Skip to content

Commit

Permalink
Add conda_create_args setting (#63)
Browse files Browse the repository at this point in the history
Co-authored-by: Antoine DECHAUME <antoine.dechaume@irt-saintexupery.com>
  • Loading branch information
AntoineD and AntoineD authored Jan 13, 2021
1 parent 1a91425 commit 666be86
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ section of configuration files:
a ``conda-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 command ``conda 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 users ``.condarc`` will not interfer.

* ``conda_install_args``, which is used to pass arguments to the command ``conda install``.
The passed arguments are inserted in the command line before the dependencies.
For instance, passing ``--override-channels`` will create more reproducible environments
Expand Down
27 changes: 27 additions & 0 deletions tests/test_conda_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,30 @@ def test_conda_install_args(newconfig, mocksession):

call = pcalls[-1]
assert call.args[6] == "--override-channels"


def test_conda_create_args(newconfig, mocksession):
config = newconfig(
[],
"""
[testenv:py123]
conda_create_args=
--override-channels
""",
)

venv = VirtualEnv(config.envconfigs["py123"])
assert venv.path == config.envconfigs["py123"].envdir

with mocksession.newaction(venv.name, "getenv") as action:
tox_testenv_create(action=action, venv=venv)
pcalls = mocksession._pcalls
assert len(pcalls) >= 1
call = pcalls[-1]
assert "conda" in call.args[0]
assert "create" == call.args[1]
assert "--yes" == call.args[2]
assert "-p" == call.args[3]
assert venv.path == call.args[4]
assert call.args[5] == "--override-channels"
assert call.args[6].startswith("python=")
10 changes: 10 additions & 0 deletions tox_conda/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def tox_addoption(parser):
help="each line specifies a conda install argument",
)

parser.add_testenv_attribute(
name="conda_create_args",
type="line-list",
help="each line specifies a conda create argument",
)


@hookimpl
def tox_configure(config):
Expand Down Expand Up @@ -124,6 +130,10 @@ def tox_testenv_create(venv, action):
args = [conda_exe, "create", "--yes", "-p", envdir]
for channel in venv.envconfig.conda_channels:
args += ["--channel", channel]

# Add end-user conda create args
args += venv.envconfig.conda_create_args

args += [python]

venv._pcall(args, venv=False, action=action, cwd=basepath)
Expand Down

0 comments on commit 666be86

Please sign in to comment.