Contributing guide#
This document aims at summarizing the most important information for getting you started on contributing to this project. We assume that you are already familiar with git and with making pull requests on GitHub.
For more extensive tutorials, that also cover the absolute basics, please refer to other resources such as the pyopensci tutorials, the scientific Python tutorials, or the scanpy developer guide.
Tip
The hatch project manager
We highly recommend to familiarize yourself with hatch.
Hatch is a Python project manager that
manages virtual environments, separately for development, testing and building the documentation. Separating the environments is useful to avoid dependency conflicts.
allows to run tests locally in different environments (e.g. different python versions)
allows to run tasks defined in
pyproject.toml, e.g. to build documentation.
While the project is setup with hatch in mind,
it is still possible to use different tools to manage dependencies, such as uv or pip.
Installing dev dependencies#
In addition to the packages needed to use this package, you need additional python packages to run tests and build the documentation.
On the command line, you typically interact with hatch through its command line interface (CLI). Running one of the following commands will automatically resolve the environments for testing and building the documentation in the background:
hatch test # defined in the table [tool.hatch.envs.hatch-test] in pyproject.toml
hatch run docs:build # defined in the table [tool.hatch.envs.docs]
When using an IDE such as VS Code,
you’ll have to point the editor at the paths to the virtual environments manually.
The environment you typically want to use as your main development environment is the hatch-test
environment with the latest Python version.
To get a list of all environments for your projects, run
hatch env show -i
This will list “Standalone” environments and a table of “Matrix” environments like the following:
+------------+---------+--------------------------+----------+---------------------------------+-------------+
| Name | Type | Envs | Features | Dependencies | Scripts |
+------------+---------+--------------------------+----------+---------------------------------+-------------+
| hatch-test | virtual | hatch-test.py3.11-stable | dev | coverage-enable-subprocess==1.0 | cov-combine |
| | | hatch-test.py3.14-stable | test | coverage[toml]~=7.4 | cov-report |
| | | hatch-test.py3.14-pre | | pytest-mock~=3.12 | run |
| | | | | pytest-randomly~=3.15 | run-cov |
| | | | | pytest-rerunfailures~=14.0 | |
| | | | | pytest-xdist[psutil]~=3.5 | |
| | | | | pytest~=8.1 | |
+------------+---------+--------------------------+----------+---------------------------------+-------------+
From the Envs column, select the environment name you want to use for development.
In this example, it would be hatch-test.py3.14-stable.
Next, create the environment with
hatch env create hatch-test.py3.14-stable
Then, obtain the path to the environment using
hatch env find hatch-test.py3.14-stable
In case you are using VScode, now open the command palette (Ctrl+Shift+P) and search for Python: Select Interpreter.
Choose Enter Interpreter Path and paste the path to the virtual environment from above.
In this future, this may become easier through a hatch vscode extension.
A popular choice for managing virtual environments is uv. The main disadvantage compared to hatch is that it supports only a single environment per project at a time, which requires you to mix the dependencies for running tests and building docs. This can have undesired side-effects, such as requiring to install a lower version of a library your project depends on, only because an outdated sphinx plugin pins an older version.
To initialize a virtual environment in the .venv directory of your project, simply run
uv sync --all-extras
The .venv directory is typically automatically discovered by IDEs such as VS Code.
Pip is nowadays mostly superseded by environment manager such as hatch.
However, for the sake of completeness, and since it’s ubiquitously available,
we describe how you can manage environments manually using pip:
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev,test,doc]"
The .venv directory is typically automatically discovered by IDEs such as VS Code.
Code-style#
This package uses pre-commit to enforce consistent code-styles. On every commit, pre-commit checks will either automatically fix issues with the code, or raise an error message.
To enable pre-commit locally, simply run
pre-commit install
in the root of the repository. Pre-commit will automatically download all dependencies when it is run for the first time.
Alternatively, you can rely on the pre-commit.ci service enabled on GitHub.
If you didn’t run pre-commit before pushing changes to GitHub it will automatically commit fixes to your pull request, or show an error message.
If pre-commit.ci added a commit on a branch you still have been working on locally, simply use
git pull --rebase
to integrate the changes into yours. While the pre-commit.ci is useful, we strongly encourage installing and running pre-commit locally first to understand its usage.
Finally, most editors have an autoformat on save feature. Consider enabling this option for ruff and biome.
Writing tests#
This package uses pytest for automated testing. Please write Tests for every function added to the package.
Most IDEs integrate with pytest and provide a GUI to run tests. Just point yours to one of the environments returned by
hatch env create hatch-test # create test environments for all supported versions
hatch env find hatch-test # list all possible test environment paths
Alternatively, you can run all tests from the command line by executing
hatch test # test with the highest supported Python version
# or
hatch test --all # test with all supported Python versions
uv run pytest
source .venv/bin/activate
pytest
in the root of the repository.
Continuous integration#
Continuous integration via GitHub actions will automatically run the tests on all pull requests and test against the minimum and maximum supported Python version.
Additionally, there’s a CI job that tests against pre-releases of all dependencies (if there are any). The purpose of this check is to detect incompatibilities of new package versions early on and gives you time to fix the issue or reach out to the developers of the dependency before the package is released to a wider audience.
The CI job is defined in .github/workflows/test.yaml,
however the single point of truth for CI jobs is the Hatch test matrix defined in pyproject.toml.
This means that local testing via hatch and remote testing on CI tests against the same python versions and uses the same environments.
Publishing a release#
The version number is not edited#
ATLAS derives its version from git tags, through hatch-vcs — version.source = "vcs" in
pyproject.toml. There is no version string to update anywhere. The tag is the version:
v1.1.0 produces 1.1.0, and a commit that is not tagged produces a development version
such as 1.0.1.dev48+ga1ac816.
Please adhere to Semantic Versioning, in brief
Given a version number MAJOR.MINOR.PATCH, increment the:
MAJOR version when you make incompatible API changes,
MINOR version when you add functionality in a backwards compatible manner, and
PATCH version when you make backwards compatible bug fixes.
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
The sequence#
Development happens on the GitLab instance; GitHub is a push mirror, and the release workflow lives there. The order matters, and it is not the order GitHub’s own interface suggests:
Tag on GitLab, which is the source of truth:
git tag v1.1.0 git push origin v1.1.0
Wait for the mirror to carry the tag to GitHub. Confirm it is there before going on — the tags are what the release build reads.
Create a GitHub release for that existing tag. On the “Releases” page, choose the tag that is already present rather than typing a new one. Letting GitHub create the tag would put it on the mirror only, leaving PyPI holding a version whose tag does not exist in the source of truth.
Publishing the release fires
release.yaml, which builds, checks, and publishes to PyPI through trusted publishing.
For more information on step 3, see managing GitHub releases.
What the release workflow refuses#
release.yaml will not publish a distribution it has not proven usable. Between building
and publishing it:
validates the metadata of both the wheel and the source distribution;
installs the built wheel into a clean environment and imports
atlasand each ofatlas.pp,atlas.tlandatlas.pl;refuses any version that is not a release version.
That last check is the one most likely to stop a release, and it almost always means the same thing: the tag was not visible to the build. Creating the GitHub release before the mirror carried the tag produces a development version, and publishing it would burn that version number on PyPI permanently. If the workflow refuses, check step 2 rather than the gate.
These gates exist because release 1.0.0 was published before they did, with metadata that
omitted matplotlib and scipy and carried no upper bound on pandas, and nothing noticed
until a user could not install it.
Note also that trusted publishing is bound on PyPI’s side to this repository, the workflow
filename release.yaml, and the pypi environment name. Renaming either the file or the
environment breaks publishing silently.
Writing documentation#
Please write documentation for new or changed features and use-cases. This project uses sphinx with the following features:
The myst extension allows to write documentation in markdown/Markedly Structured Text
Numpy-style docstrings (through the napoloen extension).
Jupyter notebooks as tutorials through myst-nb (See Tutorials with myst-nb)
sphinx-autodoc-typehints, to automatically reference annotated input and output types
Citations (like [VBH+23]) can be included with sphinxcontrib-bibtex
See scanpy’s Documentation for more information on how to write your own.
Tutorials with myst-nb and jupyter notebooks#
The documentation is set-up to render jupyter notebooks stored in the docs/notebooks directory using myst-nb.
Currently, only notebooks in .ipynb format are supported that will be included with both their input and output cells.
It is your responsibility to update and re-run the notebook whenever necessary.
If you are interested in automatically running notebooks as part of the continuous integration,
please check out this feature request in the cookiecutter-scverse repository.
Hints#
If you refer to objects from other packages, please add an entry to
intersphinx_mappingindocs/conf.py. Only if you do so can sphinx automatically create a link to the external documentation.If building the documentation fails because of a missing link that is outside your control, you can add an entry to the
nitpick_ignorelist indocs/conf.py
Building the docs locally#
hatch run docs:build
hatch run docs:open
cd docs
uv run sphinx-build -M html . _build -W
(xdg-)open _build/html/index.html
source .venv/bin/activate
cd docs
sphinx-build -M html . _build -W
(xdg-)open _build/html/index.html