Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{env_name} substitution broken since version 4.14.1 #3292

Open
rhabarberbarbara opened this issue Jun 10, 2024 · 3 comments
Open

{env_name} substitution broken since version 4.14.1 #3292

rhabarberbarbara opened this issue Jun 10, 2024 · 3 comments

Comments

@rhabarberbarbara
Copy link

rhabarberbarbara commented Jun 10, 2024

Issue

I'm creating a pipeline where a coverage report is generated over multiple test runs (spanning different Python versions). To do this, I want to include the tox environment in the coverage file name, so the artifacts don't overwrite each other in the pipeline job that combines the coverage files.

It's configured as follows (with some sections left out):

[testenv]
package = wheel
deps =
    coverage[toml] ~= 7.0
commands_pre =
    python -m coverage erase
commands =
    python -m coverage run --data-file=.coverage.{env_name} --branch --source my.project -m unittest discover {posargs:tests/unit}

This worked fine up to tox 4.14.0:

py311: commands_pre[0]> python -m coverage erase
py311: commands[0]> python -m coverage run --data-file=.coverage.py311 --branch --source my.project -m unittest discover tests/unit

However, from tox 14.4.1 onwards, the env_name variable isn't substituted anymore, and just comes through as {env_name}

py311: commands_pre[0]> python -m coverage erase
py311: commands[0]> python -m coverage run --data-file=.coverage.{env_name} --branch --source myproject -m unittest discover tests/unit

Environment

Provide at least:

  • OS: Windows 10
Output of pip list of the host Python, where tox is installed
Package       Version
------------- -------
cachetools    5.3.3
chardet       5.2.0
colorama      0.4.6
distlib       0.3.8
filelock      3.14.0
packaging     24.1
pip           24.0
platformdirs  4.2.2
pluggy        1.5.0
pyproject-api 1.6.1
setuptools    65.5.0
tomli         2.0.1
tox           4.14.1
virtualenv    20.26.2

Output of running tox

See above.

Minimal example

I tried to create a minimal example by creating a tox configuration that doesn't build and install a package, but for some reason the substitution in the command did work there. So somehow the package building and installing is important for the issue to occur.
Unfortunately, I can't share my entire tox config, as it's part of a corporate repo.

@shekhuverma
Copy link

I tried to re-create this but in my case, I'm able to use {env_name}.
I used the following code for testing and I'm getting the name "temp" printed out on the screen.

[testenv:temp]
commands =
    python -c "print(r'{env_name}')"

@rhabarberbarbara
Copy link
Author

rhabarberbarbara commented Jun 14, 2024

Hi @shekhuverma,

Indeed, that works for me as well. But as noted earlier:

So somehow the package building and installing is important for the issue to occur.

I did some further investigation, and managed to create a minimal reproducible example:
https://github.com/rhabarberbarbara/tox-issue-3292

This example shows that the issue did not exist in tox 4.14.0, while it does in 4.14.1:

MINGW64 ~/github/tox-issue-3292 (main)
$ py -3.11 -m tox run
.pkg: install_requires> python -I -m pip install setuptools>61 setuptools_scm[toml]>=7.0
.pkg: _optional_hooks> python C:\Python\311\Lib\site-packages\pyproject_api\_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_wheel> python C:\Python\311\Lib\site-packages\pyproject_api\_backend.py True setuptools.build_meta __legacy__
.pkg: install_requires_for_build_wheel> python -I -m pip install wheel
.pkg: build_wheel> python C:\Python\311\Lib\site-packages\pyproject_api\_backend.py True setuptools.build_meta __legacy__
py311: install_package> python -I -m pip install --force-reinstall --no-deps C:\Users\rhabarberbarbara\github\tox-issue-3292\.tox\.tmp\package\1\mypackage-0.1.dev2+g833b951-py3-none-any.whl
py311: commands[0]> python -m mypackage run --data-file=.coverage.{env_name} --branch
Running mypackage with: ['run', '--data-file=.coverage.{env_name}', '--branch']
  py311: OK (23.69=setup[23.53]+cmd[0.16] seconds)
  congratulations :) (24.03 seconds)

MINGW64 ~/github/tox-issue-3292 (main)
$ py -3.11 -m tox run -x 'tox.requires=tox<4.14.1'
ROOT: will run in automatically provisioned tox, host C:\Python\311\python.exe is missing [requires (has)]: tox<4.14.1 (4.15.1)
ROOT: install_deps> python -I -m pip install tox<4.14.1 tox>=4
ROOT: provision> .tox\.tox\Scripts\python.exe -m tox run -x tox.requires=tox<4.14.1
.pkg: _optional_hooks> python C:\Users\rhabarberbarbara\github\tox-issue-3292\.tox\.tox\Lib\site-packages\pyproject_api\_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_wheel> python C:\Users\rhabarberbarbara\github\tox-issue-3292\.tox\.tox\Lib\site-packages\pyproject_api\_backend.py True setuptools.build_meta __legacy__
.pkg: build_wheel> python C:\Users\rhabarberbarbara\github\tox-issue-3292\.tox\.tox\Lib\site-packages\pyproject_api\_backend.py True setuptools.build_meta __legacy__
py311: install_package> python -I -m pip install --force-reinstall --no-deps C:\Users\rhabarberbarbara\github\tox-issue-3292\.tox\.tmp\package\2\mypackage-0.1.dev2+g833b951-py3-none-any.whl
py311: commands[0]> python -m mypackage run --data-file=.coverage.py311 --branch
Running mypackage with: ['run', '--data-file=.coverage.py311', '--branch']
.pkg: _exit> python C:\Users\rhabarberbarbara\github\tox-issue-3292\.tox\.tox\Lib\site-packages\pyproject_api\_backend.py True setuptools.build_meta __legacy__
  py311: OK (3.53=setup[3.39]+cmd[0.14] seconds)
  congratulations :) (4.02 seconds)

The issue somehow seems tied to the presence of the .build_env and/or deploy environments. But it's strange, since neither of these are used in the two tox runs above.

@shekhuverma
Copy link

Bisected to #3237

Trying to fix the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants