Developer guide¶
Getting started¶
We recommend installing uv
for dependency management when developing for aiida-mlip
.
This provides a number of useful features, including:
Dependency management (
uv [add,remove]
etc.) and organization (groups)Storing the versions of all installations in a uv.lock file, for reproducible builds
Improved dependency resolution
Virtual environment management
Building and publishing tools
Currently, an external build backend, such as pdm, is required
Dependencies useful for development can then be installed by running:
uv sync -p 3.12
source .venv/bin/activate
Using uv¶
uv
manages a persistent environment
with the project and its dependencies in a .venv
directory, adjacent to pyproject.toml
. This will be created automatically as needed.
uv
provides two separate APIs for managing your Python project and environment.
uv pip
is designed to resemble the pip
CLI, with similar commands (uv pip install
, uv pip list
, uv pip tree
, etc.),
and is slightly lower level. Compared with pip,
uv
tends to be stricter, but in most cases uv pip
could be used in place of pip
.
uv add
, uv run
, uv sync
, and uv lock
are known as “project APIs”, and are slightly higher level.
These commands interact with (and require) pyproject.toml
, and uv
will ensure your environment is in-sync when they are called,
including creating or updating a lockfile,
a universal resolution that is portable across platforms.
When developing for aiida-mlip
, it is usually recommended to use project commands, as described in Getting started
rather than using uv pip install
to modify the project environment manually.
Tip
uv
will detect and use Python versions available on your system,
but can also be used to install Python automtically.
The desired Python version can be specified when running project commands with the --python
/-p
option.
For further information, please refer to the documentation.
Running the tests¶
Packages in the dev
dependency group allow tests to be run locally using pytest
, by running:
pytest -v
Note
MACE must be installed for tests to run successfully.
Alternatively, tests can be run in separate virtual environments using tox
:
tox run -e ALL
This will run all unit tests for multiple versions of Python, in addition to testing that the pre-commit passes, and that documentation builds, mirroring the automated tests on GitHub.
Individual components of the tox
test suite can also be run separately, such as running only running the unit tests with Python 3.12:
tox run -e py312
See the tox documentation for further options.
Automatic coding style checks¶
Packages in the pre-commit
dependency group allow automatic code formatting and linting on every commit.
To set this up, run:
pre-commit install
After this, the ruff linter, ruff formatter, and numpydoc (docstring style validator), will run before every commit.
Rules enforced by ruff are currently set up to be comparable to:
black (code formatter)
pylint (linter)
pyupgrade (syntax upgrader)
isort (import sorter)
flake8-bugbear (bug finder)
The full set of ruff rules are specified by the [tool.ruff]
sections of pyproject.toml.
If you ever need to skip these pre-commit hooks, just use:
git commit -n
You should also keep the pre-commit hooks up to date periodically, with:
pre-commit autoupdate
Or consider using pre-commit.ci.
Building the documentation¶
Packages in the docs
dependency group install Sphinx
and other Python packages required to build aiida-mlip
’s documentation.
Individual individual documentation pages can be edited directly:
docs/source/index.rst
docs/source/developer_guide/index.rst
docs/source/user_guide/index.rst
docs/source/user_guide/get_started.rst
docs/source/user_guide/tutorial.rst
Sphinx
can then be used to generate the html documentation:
cd docs
make clean; make html
Check the result by opening build/html/index.html
in your browser.
Continuous integration¶
aiida-mlip
comes with a .github
folder that contains continuous integration tests
on every commit using GitHub Actions. It will:
Run all tests
Build the documentation
Check coding style