Home

Awesome

pdm-conda

A PDM plugin to resolve/install/uninstall project dependencies with Conda.

Configuration

Config itemDescriptionDefault valuePossible valuesEnvironment variable
conda.activeForce plugin usage or notTruePDM_CONDA_ACTIVE
conda.runnerConda runner executablecondaconda, mamba, micromambaPDM_CONDA_RUNNER
conda.solverSolver to use for Conda resolutioncondaconda, libmambaPDM_CONDA_SOLVER
conda.channelsConda channels to use, order will be enforced[]
conda.as-default-managerUse Conda to install all possible requirementsFalsePDM_CONDA_AS_DEFAULT_MANAGER
conda.batched-commandsExecute batched install and remove Conda commands, when True the command is executed only at the endFalsePDM_CONDA_BATCHED_COMMANDS
conda.excludesArray of dependencies to exclude from Conda resolution[]
conda.auto-excludesIf cannot find package with Conda, add it to excludes listFalsePDM_CONDA_AUTO_EXCLUDES
conda.installation-methodInstallation method to use when installing dependencies with Condahard-linkhard-link, copyPDM_CONDA_INSTALLATION_METHOD
conda.dependenciesArray of dependencies to install with Conda, analogue to project.dependencies[]
conda.optional-dependenciesGroups of optional dependencies to install with Conda, analogue to project.optional-dependencies{}
conda.dev-dependenciesGroups of development dependencies to install with Conda, analogue to tool.pdm.dev-dependencies{}
conda.pypi-mapping.download-dirPyPI-Conda mapping download directory$HOME/.pdm-conda/PDM_CONDA_PYPI_MAPPING_DIR
conda.pypi-mapping.urlPyPI-Conda mapping urlhttps://github.com/regro/cf-graph-countyfair/raw/master/mappings/pypi/grayskull_pypi_mapping.yamlPDM_CONDA_PYPI_MAPPING_URL

All configuration items use prefix pdm.tool, this is a viable configuration:

[tool.pdm.conda]
runner = "micromamba"
channels = ["conda-forge/noarch", "conda-forge", "anaconda"]
dependencies = ["pdm"]
as-default-manager = true
auto-excludes = true
solver = "libmamba"
excludes = ["pytest-cov"] # don't install with conda even if it's a dependency from other packages
installation-method = "copy"
batched-commands = true
active = false

[tool.pdm.conda.pypi-mapping]
download-dir = "/tmp"
url = "https://url/to/mapping.yaml"

[tool.pdm.conda.optional-dependencies]
extra = ["anaconda:ffmpeg"] # non python dependency, obtained from anaconda channel

[tool.pdm.conda.dev-dependencies]
dev = ["pytest"]

Usage

This plugin adds capabilities to the default PDM commands.

Working commands

The following commands were tested and work:

How it works

Using conda/libmamba solver

PDM invokes Conda solver to resolve conda packages each time a PDM candidate makes a change in the last Conda resolution.

If only Conda packages are used (i.e. setting conda.as-default-manager to true and no conda.excludes) then Conda solver is invoked only once.

Settings overridden

In order to use Conda to install packages some settings were overriden:

Some environment variables were overridden too:

All this changes will be maintained only during the execution of the command, after that the settings will be restored to the previous values.

Lock strategy

Development

For development docker-compose files exist in deploy directory, helper script deploy/docker-compose.sh can be used for executing docker.

For running dev environment:

bash deploy/docker-compose.sh -d up

And for productive environment:

bash deploy/docker-compose.sh up