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

--workdir override not working in tox >=4 #2654

Closed
jabbera opened this issue Dec 9, 2022 · 10 comments · Fixed by #2776
Closed

--workdir override not working in tox >=4 #2654

jabbera opened this issue Dec 9, 2022 · 10 comments · Fixed by #2776
Labels
bug:normal affects many people or has quite an impact help:wanted Issues that have been acknowledged, a solution determined and a PR might likely be accepted.

Comments

@jabbera
Copy link

jabbera commented Dec 9, 2022

Issue

In tox <4 using --workdir would override whatever was in tox.ini, this no longer works in >= 4 which makes some CI/CD use cases difficult

Environment

Provide at least:

  • OS: linux

Minimal example

If possible, provide a minimal reproducer for the issue:

tox.ini:
[tox]
toxworkdir=/tmp/blah

[testenv]
allowlist_externals=echo
commands=echo {toxworkdir}

setup.py
from distutils.core import setup

setup(name='Distutilsaaa',
      version='1.0',
      description='Python Distribution Utilities',
      author='Greg Ward',
      author_email='gward@python.net',
      url='https://www.python.org/sigs/distutils-sig/',
      packages=['distutilsa'],
     )

distutilsa/__init.py

Tox 4:

 jabbera    toxbug   3.8.10  ﮫ20.419s⠀   tox -e py --workdir /tmp/blah1  70  19:30:47 
.pkg: install_requires> python -I -m pip install 'setuptools>=40.8.0' wheel
.pkg: _optional_hooks> python /home/jabbera/.local/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_sdist> python /home/jabbera/.local/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: prepare_metadata_for_build_wheel> python /home/jabbera/.local/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: build_sdist> python /home/jabbera/.local/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
py: install_package> python -I -m pip install --force-reinstall --no-deps /tmp/blah/.tmp/package/1/Distutilsaaa-1.0.tar.gz
py: commands[0]> echo /tmp/blah
/tmp/blah
.pkg: _exit> python /home/jabbera/.local/lib/python3.10/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
  py: OK (6.34=setup[6.34]+cmd[0.00] seconds)
  congratulations :) (6.43 seconds)

Tox 3:

 jabbera    toxbug   3.8.10  ﮫ4.404s⠀   tox -e py --workdir /tmp/blah1         bash   70  19:29:36 
GLOB sdist-make: /home/jabbera/toxbug/setup.py
py inst-nodeps: /tmp/blah1/.tmp/package/1/Distutilsaaa-1.0.zip
py installed: Distutilsaaa @ file:///tmp/blah1/.tmp/package/1/Distutilsaaa-1.0.zip
py run-test-pre: PYTHONHASHSEED='1612454640'
py run-test: commands[0] | echo /tmp/blah1
/tmp/blah1
_______________________________________________________ summary ________________________________________________________
  py: commands succeeded
  congratulations :)
@gaborbernat gaborbernat added the bug:normal affects many people or has quite an impact label Dec 9, 2022
@gaborbernat gaborbernat added this to the 4.0.x milestone Dec 9, 2022
@gaborbernat
Copy link
Member

gaborbernat commented Dec 9, 2022

Minimal reproducible:

[tox]
toxworkdir=/tmp/blah
❯ tox c -k toxworkdir --core -e py --workdir a
[testenv:py]

[tox]
work_dir = /tmp/blah

PR welcome with test and changelog.

@gaborbernat gaborbernat added the help:wanted Issues that have been acknowledged, a solution determined and a PR might likely be accepted. label Dec 9, 2022
@jabbera
Copy link
Author

jabbera commented Dec 9, 2022

I tried to fix this but there doesn't seem to be an obvious way to differentiate if a parameter is passed or the default is called. That said: -x tox.toxworkdir=blah sorts the problem.

@jaraco
Copy link

jaraco commented Dec 15, 2022

I'm continuing the analysis from #2713.

@jaraco jaraco mentioned this issue Dec 15, 2022
5 tasks
@jaraco
Copy link

jaraco commented Dec 15, 2022

In #2725, I have a few commits that start to address this issue, but there are still a few test failures. Annoyingly, I can't even seem to get consistent test failures. A moment ago, test_sequential_inserted_env_vars was failing due to a failed assertion on test_sequential:435, but now it's failing on :437. When it was failing on 435, it was failing because the virtualenv couldn't find pip... so maybe there was some issues with cached envs in the tree. It does appear that if --root is passed, the expectation is that the work_dir should still be relative to the project directory and not the root (gist).

It seems to me it's ill-defined what the value of work_dir is expected to be when root_dir is specified, work_dir is unspecified, and source.path.parent is not root_dir, and the tests make a lot of assumptions about work_dir being {source.path.parent}/.tox.

The docs talk about a tox root and a package root. --root points to where the project root is. Is the work_dir meant to be relative to the tox root or the project root or package root? Is project root the package root or tox root?

@gaborbernat
Copy link
Member

gaborbernat commented Dec 15, 2022

Is the work_dir meant to be relative to the tox root or the project root or package root?

Relative to tox_root when not specified, otherwise the path where it's specified.

Is project root the package root or tox root?

Project root should default to tox_root, but can be changed.

Package root defaults to tox_root, but can be changed.

The core idea here would be to be able to run tox with tox.ini and move tox work_dir outside of the project working directory:

$ ls custom-tox-config
tox.ini
$ cd project-without-tox
tox r -c ../custom-tox-config/tox.ini -e py310
...
$ ls ../custom-tox-config/.tox
py310

@jaraco
Copy link

jaraco commented Dec 15, 2022

What is the difference between package root and project root? How is package root defined? Do I understand correctly that tox_root is always where the ini file is found? How can package root be changed?

@gaborbernat
Copy link
Member

How can package root be changed?

Always relative to the project root, it can be changed via the tox.ini config.

Do I understand correctly that tox_root is always where the ini file is found?

Yes.

What is the difference between package root and project root? How is package root defined?

By default is package root is the project root, but can be changed via tox.ini.

@jaraco
Copy link

jaraco commented Dec 20, 2022

What I mean to ask: what is the purpose of package root and project root compared to each other? What value would someone get by defining them separately?

@gaborbernat
Copy link
Member

Packaging root is used by the package builder as the root directory. Project root is what tox uses as root directory.

@q0w
Copy link
Contributor

q0w commented Dec 25, 2022

The problem is here

for key, loader in product(self.keys, loaders):
chain_key = f"{loader.section.key}.{key}"
if chain_key in args.chain:
raise ValueError(f"circular chain detected {', '.join(args.chain[args.chain.index(chain_key):])}")
args.chain.append(chain_key)
try:
value = loader.load(key, self.of_type, self.factory, conf, args)
except KeyError:
continue
else:
break
finally:
del args.chain[-1]
else:
value = self.default(conf, args.env_name) if callable(self.default) else self.default

the last else block is never called, and tox gets the toxworkdir from IniLoader and work_dir_builder as default is never called, so cli args dont take precedence over loaders

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:normal affects many people or has quite an impact help:wanted Issues that have been acknowledged, a solution determined and a PR might likely be accepted.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants