kikuchipy is meant to be a community maintained project. We welcome contributions in the form of bug reports, documentation, code, feature requests, and more. These guidelines provide resources on how best to contribute.
For new users, checking out the GitHub guides are recommended.
Questions, comments, and feedback¶
Code of Conduct¶
kikuchipy has a Code of Conduct that should be honoured by everyone who participates in the kikuchipy community.
Setting up a development installation¶
Make a local copy of your forked repository and change directories:
$ git clone https://github.com/your-username/kikuchipy.git $ cd kikuchipy
upstream remote to the main kikuchipy repository:
$ git remote add upstream https://github.com/pyxem/kikuchipy.git
$ conda create --name kikuchipy $ conda activate kikuchipy
Then, install the required dependencies while making the development version
available globally (in the
$ pip install --editable .[dev]
This installs all necessary development dependencies, including those for running tests and building documentation.
The code making up kikuchipy is formatted closely following the Style Guide for
Python Code with The Black Code
use pre-commit to run
black automatically prior
to each local commit. Please install it in your environment:
$ pre-commit install
Next time you commit some code, your code will be formatted inplace according to our black configuration.
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
party packages (like
hyperspy) and finally kikuchipy imports.
Create a new feature branch:
$ git checkout master -b your-awesome-feature-name
When you’ve made some changes you can view them with:
$ git status
Add and commit your created, modified or deleted files:
$ git add my-file-or-directory $ git commit -s -m "An explanatory commit message"
Keeping your branch up-to-date¶
Switch to the
$ git checkout master
Fetch changes and update
$ git pull upstream master --tags
Update your feature branch:
$ git checkout your-awesome-feature-name $ git merge master
Building and writing documentation¶
We use Sphinx for documenting functionality. Install necessary dependencies to build the documentation:
$ pip install --editable .[doc]
Then, build the documentation from the
$ cd doc $ make html
The documentation’s HTML pages are built in the
from files in the reStructuredText (reST)
plaintext markup language. They should be accessible in the browser by typing
file:///your-absolute/path/to/kikuchipy/doc/build/html/index.html in the
Tips for writing Jupyter Notebooks that are meant to be converted to reST text files by nbsphinx:
All notebooks should have a Markdown (MD) cell with this message at the top, “This notebook is part of the kikuchipy documentation https://kikuchipy.org. Links to the documentation won’t work from the notebook.”, and have
"nbsphinx": "hidden"in the cell metadata so that the message is not visible when displayed in the documentation.
_ = ax.imshow(...)to disable Matplotlib output if a Matplotlib command is the last line in a cell.
Refer to our API reference with this general MD
[fft_filter()](reference.rst#kikuchipy.signals.EBSD.fft_filter). Remember to add the parentheses
Reference external APIs via standard MD like
The Sphinx gallery thumbnail used for a notebook is set by adding the
nbsphinx-thumbnailtag to a code cell with an image output. The notebook must be added to the gallery in the README.rst to be included in the documentation pages.
Running and writing tests¶
All functionality in kikuchipy is tested via the pytest framework. The tests reside in a
within each module. Tests are short methods that call functions in kikuchipy
and compare resulting output values with known answers. Install necessary
dependencies to run the tests:
$ pip install --editable .[tests]
Some useful fixtures, like a
dummy scan and corresponding background pattern, are available in the
kikuchipy.data module tests check that data not part of the
package distribution can be downloaded from the kikuchipy-data GitHub
repository, thus downloading some
datasets of ~15 MB to your local cache.
To run the tests:
$ pytest --cov --pyargs kikuchipy
--cov flag makes coverage.py print a nice report in the
terminal. For an even nicer presentation, you can use
$ coverage html
Then, you can open the created
htmlcov/index.html in the browser and inspect
the coverage in more detail.
Docstring examples are tested with pytest as well:
$ pytest --doctest-modules --ignore-glob=kikuchipy/*/tests
Adding data to the data module¶
Test data for user guides and tests are included in the
module via the pooch Python library.
These are listed in a file registry (kikuchipy.data._registry.py) with their
file verification string (hash, SHA256, obtain with e.g. sha256sum <file>) and
location, the latter potentially not within the package but from the
kikuchipy-data repository, since
some files are considered too large to include in the package.
If a required dataset isn’t in the package, but is in the registry, it can be
downloaded from the repository when the user passes allow_download=True to
nickel_ebsd_large(). The dataset is then downloaded
to a local cache, e.g. /home/user/.cache/kikuchipy/. Pooch handles
downloading, caching, version control, file verification (against hash) etc. If
we have updated the file hash, pooch will redownload it. If the file is
available in the cache, it can be loaded as the other files in the data module.
The desired data cache directory used by pooch can be set with a global KIKUCHIPY_DATA_DIR variable locally, e.g. by setting export KIKUCHIPY_DATA_DIR=~/kikuchipy_data in ~/.bashrc.