The code making up kikuchipy is formatted closely following the Style Guide for Python
The Black Code style.
We use pre-commit to run
black automatically prior to
each local commit.
Please install it in your environment:
Next time you commit some code, your code will be formatted inplace according to
black can format Jupyter notebooks as well. Code lines in tutorial notebooks should
be limited to 77 characters to display nicely in the documentation:
black -l 77 <your_nice_notebook>.ipynb
black won’t format docstrings.
We follow the numpydoc standard (with some exceptions), and the
docstrings are checked against this standard when building the documentation.
Comment lines should preferably be limited to 72 characters.
Package imports should be structured into three blocks with blank lines between them
(descending order): standard library (like
typing), third party packages
hyperspy) and finally kikuchipy imports.
We use type hints in the function definition without type duplication in the function docstring, for example:
def my_function(a: int, b: Optional[bool] = None) -> Tuple[float, np.ndarray]: """This is a new function. Parameters ---------- a Explanation of ``a``. b Explanation of flag ``b``. Default is ``None``. Returns ------- values Explanation of returned values. """
We import modules lazily using the specification in PEP 562.