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

Tox 4.0.x does not support --no-deps dependency spec #2674

Closed
Zac-HD opened this issue Dec 10, 2022 · 7 comments · Fixed by #2678
Closed

Tox 4.0.x does not support --no-deps dependency spec #2674

Zac-HD opened this issue Dec 10, 2022 · 7 comments · Fixed by #2678
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

@Zac-HD
Copy link

Zac-HD commented Dec 10, 2022

With tox 4.0.3 and tox 4.0.5, on WSL locally and on Ubuntu in GitHub Actions, I've noticed that passing --no-deps is now an error:

[tox]
[testenv]
deps =
    # Really useful to check that a requirements file is complete in each environment
    # (e.g. to check pip-compile hasn't left any deps unpinned on some versions or OSes)
    --no-deps  # works if you comment out this line
    urllib3    # just a common dep, for simplicity
commands =
    python -c 'print("Hello World!")'
$ tox  # 4.0.5, on Python 3.8, WSL
py: internal error
Traceback (most recent call last):
  File "tox/tox_env/python/pip/pip_install.py", line 93, in _install_requirement_file
    new_options, new_reqs = arguments.unroll()
  File "tox/tox_env/python/pip/req_file.py", line 84, in unroll   
    opts_dict = vars(self.options)
  File "tox/tox_env/python/pip/req/file.py", line 153, in options 
    self._ensure_requirements_parsed()
  File "tox/tox_env/python/pip/req/file.py", line 169, in _ensure_requirements_parsed
    self._requirements = self._parse_requirements(opt=self._opt, recurse=True)
  File "tox/tox_env/python/pip/req_file.py", line 71, in _parse_requirements
    requirements = super()._parse_requirements(opt, recurse)
  File "tox/tox_env/python/pip/req/file.py", line 173, in _parse_requirements
    for parsed_line in self._parse_and_recurse(str(self._path), self.is_constraint, recurse):
  File "tox/tox_env/python/pip/req/file.py", line 195, in _parse_and_recurse
    for line in self._parse_file(filename, constraint):
  File "tox/tox_env/python/pip/req/file.py", line 217, in _parse_file
    args_str, opts = self._parse_line(line)
  File "tox/tox_env/python/pip/req/file.py", line 264, in _parse_line
    opts = self._parser.parse_args(args)
  File "/usr/lib/python3.8/argparse.py", line 1783, in parse_args
    self.error(msg % ' '.join(argv))
  File "/usr/lib/python3.8/argparse.py", line 2533, in error
    self.exit(2, _('%(prog)s: error: %(message)s\n') % args)
  File "tox/tox_env/python/pip/req/args.py", line 18, in exit     
    raise ValueError(msg)
ValueError: unrecognized arguments: --no-deps

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tox/session/cmd/run/single.py", line 45, in _evaluate     
    tox_env.setup()
  File "tox/tox_env/api.py", line 226, in setup
    self._setup_env()
  File "tox/tox_env/python/runner.py", line 99, in _setup_env     
    self._install_deps()
  File "tox/tox_env/python/runner.py", line 103, in _install_deps 
    self.installer.install(requirements_file, PythonRun.__name__, "deps")
  File "tox/tox_env/python/pip/pip_install.py", line 84, in install
    self._install_requirement_file(arguments, section, of_type)
  File "tox/tox_env/python/pip/pip_install.py", line 95, in _install_requirement_file
    raise HandledError(f"{exception} for tox env py within deps")
tox.report.HandledError: unrecognized arguments: --no-deps for tox env py within deps
  py: FAIL code 2 (4.17 seconds)
  evaluation failed :( (19.80 seconds)
@gaborbernat
Copy link
Member

gaborbernat commented Dec 10, 2022

What's the use case for this flag? Do you have a reproducible on a demo project? Pull requests welcome.

@Zac-HD
Copy link
Author

Zac-HD commented Dec 10, 2022

I use this on every project where I use pip-tools to compile my requirements files, to ensure that I've correctly specified any version- or platform-specific requirements. It's also very useful in restricted corporate environments, to ensure that dependency resolution doesn't pull in a package which isn't explicitly allowlisted.

I constructed the above example based on this failing build in shed, but most of my other projects use the same pattern and I'm pretty sure I got the idea from someone else, though I don't remember where.

@gaborbernat gaborbernat added 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. labels Dec 11, 2022
@gaborbernat gaborbernat added this to the 4.0.x milestone Dec 11, 2022
@gaborbernat
Copy link
Member

Seems this is not supported as part of the requirements.txt, so really the only use of it part of the CLI 🤔

❯ venv/bin/pip install -r requirements.txt
Usage: pip [options]

ERROR: Invalid requirement: --no-deps
pip: error: no such option: --no-deps

~/git/github/tox/magic on  main [!]
❯ virtualenv venv^C
~/git/github/tox/magic on  main [!]
❯ cat requirements.txt
--no-deps
urllib3⏎  

The question then is if this should be supported via a separate configuration argument or if it should be only part of deps as was in v3. Note this was not supported in v3, just happened to work 🤔

@gaborbernat
Copy link
Member

@Zac-HD this now is out via 4.0.7

@nsoranzo
Copy link

@gaborbernat This seems to have introduced a regression, see https://github.com/galaxyproject/galaxy/actions/runs/3670306804/jobs/6204749384

lint: internal error
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tox/session/cmd/run/single.py", line 45, in _evaluate
    tox_env.setup()
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tox/tox_env/api.py", line 236, in setup
    self._setup_env()
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tox/tox_env/python/runner.py", line 99, in _setup_env
    self._install_deps()
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tox/tox_env/python/runner.py", line 103, in _install_deps
    self.installer.install(requirements_file, PythonRun.__name__, "deps")
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tox/tox_env/python/pip/pip_install.py", line 83, in install
    self._install_requirement_file(arguments, section, of_type)
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tox/tox_env/python/pip/pip_install.py", line 92, in _install_requirement_file
    new_options, new_reqs = arguments.unroll()
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tox/tox_env/python/pip/req_file.py", line 104, in unroll
    opts_dict = vars(self.options)
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tox/tox_env/python/pip/req/file.py", line 157, in options
    self._ensure_requirements_parsed()
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tox/tox_env/python/pip/req/file.py", line 177, in _ensure_requirements_parsed
    self._requirements = self._parse_requirements(opt=self._opt, recurse=True)
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tox/tox_env/python/pip/req_file.py", line 92, in _parse_requirements
    requirements = super()._parse_requirements(opt, recurse)
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tox/tox_env/python/pip/req/file.py", line 189, in _parse_requirements
    self._merge_option_line(opt, parsed_line.opts, parsed_line.filename)
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tox/tox_env/python/pip/req_file.py", line 26, in _merge_option_line
    if opt.no_deps:
AttributeError: 'Namespace' object has no attribute 'no_deps'
  lint: FAIL code 2 (0.28 seconds)
  evaluation failed :( (0.41 seconds)

@gaborbernat
Copy link
Member

@nsoranzo
Copy link

@gaborbernat Great, thanks, that was super-fast. Tested and looks fixed!

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.

3 participants