Skip to content

Passing environment variables to conditionally formatted strings seems broken #3831

@Zeitsperre

Description

@Zeitsperre

Issue

I'm not certain if this is a bug, or I'm not applying the new configuration logic properly. I would like to be able to conditionally pass environment variables to strings within the deps line.

My understanding of the documentation suggests that this is supported in more recent versions (https://tox.wiki/en/latest/reference/config.html#generative-environment-list), but it appears that when an environment variable is substituted within the string, it gets formatted into a list? i.e.

deps = [
  {replace = "if", condition = "env.ESMF_VERSION", then = ['git+https://github.com/esmf-org/esmf.git@v{env:ESMF_VERSION}#subdirectory=src/addon/esmpy']},
  {replace = "if", condition = "env.XCLIM_VERSION", then = ['xclim=={env:XCLIM_VERSION}']},
]

Effectively becomes:

deps = [
  ['git+https://github.com/esmf-org/[email protected]#subdirectory=src/addon/esmpy'],
  ['xclim==0.59.0']
]

The tox config is otherwise consistent, and no issues arise unless the environment variables are set.

Environment

Provide at least:

  • OS: Linux
Output of pip list of the host Python, where tox is installed
tox                           4.46.3

Output of running tox

Output of tox -rvv
$ export ESMF_VERSION=1.0.0
$ export XCLIM_VERSION=0.59.0
$ tox -e py3.13   
py3.13: internal error
Traceback (most recent call last):
  File "/home/tjs/mambaforge/envs/xscen/lib/python3.13/site-packages/tox/session/cmd/run/single.py", line 51, in _evaluate
    tox_env.setup()
    ~~~~~~~~~~~~~^^
  File "/home/tjs/mambaforge/envs/xscen/lib/python3.13/site-packages/tox/tox_env/api.py", line 299, in setup
    self._setup_env()
    ~~~~~~~~~~~~~~~^^
  File "/home/tjs/mambaforge/envs/xscen/lib/python3.13/site-packages/tox/tox_env/python/runner.py", line 152, in _setup_env
    self._install_deps()
    ~~~~~~~~~~~~~~~~~~^^
  File "/home/tjs/mambaforge/envs/xscen/lib/python3.13/site-packages/tox/tox_env/python/runner.py", line 156, in _install_deps
    requirements_file: PythonDeps = self.conf["deps"]
                                    ~~~~~~~~~^^^^^^^^
  File "/home/tjs/mambaforge/envs/xscen/lib/python3.13/site-packages/tox/config/sets.py", line 150, in __getitem__
    return self.load(item)
           ~~~~~~~~~^^^^^^
  File "/home/tjs/mambaforge/envs/xscen/lib/python3.13/site-packages/tox/config/sets.py", line 162, in load
    return config_definition.__call__(self._conf, self.loaders, ConfigLoadArgs(chain, self.name, self.env_name))  # noqa: PLC2801
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tjs/mambaforge/envs/xscen/lib/python3.13/site-packages/tox/config/of_type.py", line 113, in __call__
    value = loader.load(primary_key, self.of_type, self.factory, conf, args, all_keys=alias_keys)
  File "/home/tjs/mambaforge/envs/xscen/lib/python3.13/site-packages/tox/config/loader/api.py", line 153, in load
    converted = self.build(alias, of_type, factory, conf, raw, args)
  File "/home/tjs/mambaforge/envs/xscen/lib/python3.13/site-packages/tox/config/loader/toml/__init__.py", line 75, in build
    result = self.to(exploded, of_type, factory)
  File "/home/tjs/mambaforge/envs/xscen/lib/python3.13/site-packages/tox/config/loader/convert.py", line 56, in to
    return factory(raw)
  File "/home/tjs/mambaforge/envs/xscen/lib/python3.13/site-packages/tox/tox_env/python/pip/req_file.py", line 145, in factory
    raise TypeError(raw)
TypeError: [['git+https://github.com/esmf-org/[email protected]#subdirectory=src/addon/esmpy'], ['xclim==0.59.0']]
  py3.13: FAIL code 2 (0.04 seconds)
  evaluation failed :( (0.07 seconds)

Minimal example

deps = [
  {replace = "if", condition = "env.ESMF_VERSION", then = ['git+https://github.com/esmf-org/esmf.git@v{env:ESMF_VERSION}#subdirectory=src/addon/esmpy']},
  {replace = "if", condition = "env.XCLIM_VERSION", then = ['xclim=={env:XCLIM_VERSION}']},
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions