tox-conda
is a plugin that provides integration with the conda package and environment manager for the tox automation tool. It's like having your cake and
eating it, too!
By default, tox
creates isolated environments using virtualenv and installs dependencies from pip
.
In contrast, when using the tox-conda
plugin tox
will use conda
to create
environments, and will install specified dependencies from conda
. This is
useful for developers who rely on conda
for environment management and
package distribution but want to take advantage of the features provided by
tox
for test automation.
tox-conda
has not been tested with conda
version below 4.5.
tox-conda
can be used in one of two ways: by installing it globally and by
enabling it on a per-project basis. When the plugin is installed globally, the
default behavior of tox
will be to use conda
to create environments. To
use it on a per-project basis instead, use tox
's auto-provisioning feature
to selectively enable the plugin.
To enable the use of tox-conda
by default, follow the Installation
instructions. To use the plugin selectively, do not manually install it, but
instead enable it by adding tox-conda
as a provisioning requirement to a
project's tox
config:
[tox] requires = tox-conda
More information on auto-provisioning can be found in the tox documentation.
The tox-conda
package is available on pypi
. To install, simply use the
following command:
$ pip install tox-conda
To install from source, first clone the project from github:
$ git clone https://github.com/tox-dev/tox-conda
Then install it in your environment:
$ cd tox-conda $ pip install .
To install in development mode:
$ pip install -e .
The tox-conda
plugin expects that tox
and conda
are already installed and
available in your working environment.
Details on tox
usage can be found in the tox documentation.
With the plugin enabled and no other changes, the tox-conda
plugin will use
conda
to create environments and use pip
to install dependencies that are
given in the tox.ini
configuration file.
tox-conda
adds six additional (and optional) settings to the [testenv]
section of configuration files:
conda_deps
, which is used to configure which dependencies are installed fromconda
instead of frompip
. All dependencies inconda_deps
are installed before all dependencies indeps
. If not given, no dependencies will be installed usingconda
.conda_channels
, which specifies which channel(s) should be used for resolvingconda
dependencies. If not given, only thedefault
channel will be used.conda_spec
, which specifies aconda-spec.txt
file that lists conda dependencies to install and will be combined withconda_deps
(if given). These dependencies can be in a general from (e.g.,numpy>=1.17.5
) or an explicit form (eg., https://conda.anaconda.org/conda-forge/linux-64/numpy-1.17.5-py38h95a1406_0.tar.bz2), however, if the@EXPLICIT
header is inconda-spec.txt
, all general dependencies will be ignored, including those given inconda_deps
.conda_env
, which specifies aconda-env.yml
file to create a base conda environment for the test. Theconda-env.yml
file is self-contained and if the desired conda channels to use are not given, the default channels will be used. If theconda-env.yml
specifies a python version it must be compatible with thebasepython
set for the tox env. Aconda-env.yml
specifyingpython>=3.8
could for example be used withbasepython
set topy38
,py39
orpy310
. The aboveconda_deps
,conda_channels
, andconda_spec
arguments, if used in conjunction with aconda-env.yml
file, will be used to update the environment after the initial environment creation.conda_create_args
, which is used to pass arguments to the commandconda create
. The passed arguments are inserted in the command line before the python package. For instance, passing--override-channels
will create more reproducible environments because the channels defined in the user's.condarc
will not interfer.conda_install_args
, which is used to pass arguments to the commandconda install
. The passed arguments are inserted in the command line before the dependencies. For instance, passing--override-channels
will create more reproducible environments because the channels defined in the user's.condarc
will not interfer.
tox-conda
will usually install a python version compatible with your specified basepython
to the conda environment. To disable this behavior set basepython
to none
.
If mamba is installed in the same environment as tox,
you may use it instead of the conda
executable by setting the environment variable
CONDA_EXE=mamba
in the shell where tox
is called.
An example configuration file is given below:
[tox] envlist = {py35,py36,py37}-{stable,dev} [testenv] deps= pytest-sugar py35,py36: importlib_resources dev: git+git://github.com/numpy/numpy conda_deps= pytest<=3.8 stable: numpy=1.15 conda_channels= conda-forge conda_install_args= --override-channels commands= pytest {posargs}
More information on tox
configuration files can be found in the
documentation.
Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
Distributed under the terms of the MIT license, "tox-conda" is free and open source software
If you encounter any problems, please file an issue along with a detailed description.