tox: tox 4: pip requirements parsing doesn't support --hash arguments
For my open source project tests I use pip-compile’s --generate-hashes to pass the --hash argument to pip (example). This works in tox 3 but with tox 4 it fails where tox tries to parse the line:
$ python3.9 -m tox -e py39
py39: internal error
Traceback (most recent call last):
File "/.../.pyenv/versions/3.9.0/lib/python3.9/site-packages/packaging/requirements.py", line 98, in __init__
req = REQUIREMENT.parseString(requirement_string)
File "/.../.pyenv/versions/3.9.0/lib/python3.9/site-packages/pyparsing.py", line 1955, in parseString
raise exc
File "/.../.pyenv/versions/3.9.0/lib/python3.9/site-packages/pyparsing.py", line 3814, in parseImpl
raise ParseException(instring, loc, self.errmsg, self)
pyparsing.ParseException: Expected stringEnd, found '-' (at char 18), (line:1, col:19)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/.../.pyenv/versions/3.9.0/lib/python3.9/site-packages/tox/tox_env/python/req_file.py", line 108, in validate_and_expand
req = Requirement(line)
File "/.../.pyenv/versions/3.9.0/lib/python3.9/site-packages/packaging/requirements.py", line 100, in __init__
raise InvalidRequirement(
packaging.requirements.InvalidRequirement: Parse error at "'--hash=s'": Expected stringEnd
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/.../.pyenv/versions/3.9.0/lib/python3.9/site-packages/tox/session/cmd/run/single.py", line 41, in _evaluate
tox_env.ensure_setup(recreate=recreate)
File "/.../.pyenv/versions/3.9.0/lib/python3.9/site-packages/tox/tox_env/api.py", line 169, in ensure_setup
self.setup()
File "/.../.pyenv/versions/3.9.0/lib/python3.9/site-packages/tox/tox_env/python/runner.py", line 44, in setup
self.install_deps()
File "/.../.pyenv/versions/3.9.0/lib/python3.9/site-packages/tox/tox_env/python/runner.py", line 68, in install_deps
requirement_file_content = requirements_file.validate_and_expand()
File "/.../.pyenv/versions/3.9.0/lib/python3.9/site-packages/tox/tox_env/python/req_file.py", line 101, in validate_and_expand
result.extend(req_file.validate_and_expand())
File "/.../.pyenv/versions/3.9.0/lib/python3.9/site-packages/tox/tox_env/python/req_file.py", line 120, in validate_and_expand
raise ValueError(f"{at}: {line}") from exc
ValueError: 7: attrs==20.3.0 --hash=sha256:31b2eced602aa8423c2aea9c76a724617ed67cf9513173fd3a4f03e3a929c7e6 --hash=sha256:832aa3cde19744e49938b91fea06d69ecb9e649c93ba974535d08ad92164f700
py39: FAIL ✖ in 0.06 seconds
py39: FAIL code 2 (0.06 seconds)
evaluation failed :( (0.11 seconds)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (12 by maintainers)
In light of recent contributions and involvement invited you to be part of the maintainers group, which should give you all the rights you need 👌
Sorry - I thought you’re about to include the support for requirements.txt file support with this ticket as suggested by @pradyunsg:
Creating a new one, thanks!
Hi, I tried the tox4 in of of my projects and found another issue with the same possible root cause - just adding a minimal failing example here for reference:
https://pip--9474.org.readthedocs.build/en/9474/reference/requirements-files/#supported-options seems relevant here.