Code style#
The code making up kikuchipy is formatted closely following the Style Guide for Python
Code with
The Black Code style.
We use pre-commit to run black (via
ruff) automatically prior to each local commit.
Please install it in your environment:
pre-commit install
Note that 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 and docstring lines should preferably be limited to 72 characters (including leading whitespaces).
Package imports should be structured into three blocks with blank lines between them
(descending order): standard library (like os and typing), third party packages
(like numpy and 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: bool | None = 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.