Dependency Management#
This is a guide on how to manage the package dependencies of CLIMADA.
We use uv for dependency management.
Prerequisites#
Install uv.
Install CLIMADA from source, following instructions for uv.
Install all developer dependencies, in particular pre-commit.
Concept#
uv resolves the dependency tree and stores the exact resolved package versions in a cross-platform lockfile. This is particularly useful for applications, because dependencies can be locked and thus compatibility is ensured. CLIMADA is not an application but a library and thus may be used in different downstream environments. Therefore, the lockfile only reflects the default environment for CLIMADA.
We commit uv.lock to the git source tree.
The lockfile represents the exact environment created when installing CLIMADA from source (with uv).
Adding or updating dependencies of CLIMADA will change the lockfile, as will upgrading packages within the environment.
These changes should only be committed if this seems appropriate, either because dependency defintions changed or a default package should or must be upgraded.
Note
Upgrading packages changes the lockfile.
If you do not want to commit these changes, this will result in a “dirty” Git working tree (“Changes not staged for commit”).
Therefore, changes to the environment have to be reverted before switching branches, e.g. with git restore uv.lock.
See the guidelines on upgrading packages.
We also maintain a Conda environment file for simple creating of a suitable environment with Conda.
However, Conda package requirements might differ from those in the pyproject.toml:
Package names are different, or different packages might be required altogether.
This is handled by peanutfun/pyproject-to-conda-env.
The script translates the pyproject.toml to an environment.yml file, respecting data on package addition, renaming, or deletion defined in transform.yml.
The script is executed automatically by pre-commit if pyproject.toml changes.
Lockfile Use#
- pre-commit
The lockfile is synced.
Pre-commit checks if the lockfile is in sync with the
pyproject.toml.Pre-commit checks if the Conda environment file is in sync with
pyproject.toml.Pre-commit does not check if the lockfile lists the latest versions available (Upgrading is done manually).
- CI Testing
The lockfile is ignored.
Testing environments are built with pip, installing the latest compatible package versions. This reflects the behavior when installing CLIMADA downstream.
- Documentation
The lockfile is respected.
Documentation apps easily break under package upgrades. Therefore, readthedocs.org uses the lockfile for a fixed documentation environment.
How-To Guides#
Manage Dependencies#
Instead of updating the pyproject.toml “by hand”, you may use uv commands.
Changes to the pyproject.toml might induce changes to the lockfile.
pre-commit will pick this up automatically.
Please commit these changes to the lockfile.
Upgrade Dependencies#
Even without changes to the pyproject.toml, you might occasionally want to upgrade the lockfile.
One reason could be the upgrade of a package used for building the documentation (within the current package version specifier limits).
Make sure that tests pass and that the documentation builds on the upgraded environment.
Commit the changes to the lockfile.
Attention
Make sure that the online docs build successfully. A successful build report is not enough: imports might be failing, but the Sphinx builder usually ignores such issues and simply does not render the associated parts. Make sure that the docs of the CLIMADA submodules are rendered correctly.