Open q0w opened 1 year ago
Thanks for the report @q0w!
This sounds like a bug -- could you please update your comment to use the bug report template? We use that to reduce the amount of manual maintainer effort needed to triage these kinds of things.
Updated
Much appreciated, thank you!
From a quick look, this stems from the current "fast path" behavior we have for --require-hashes
. I believe it'll get resolved via #540; cc @tetsuo-cpp for opinions.
@woodruffw Yep that's correct, this should be fixed with #540.
@tetsuo-cpp pip-audit v2.5.3 fails now with --no-deps --fix
.
note: --no-deps
is provided because of https://github.com/pypa/pip/issues/9644
@q0w could you provide the new error message?
I tried to make a repro, but no success. Also what should I do, if i wanna pip-audit to replace existing version rather than adding new line with fixed version. Its because of provided --no-deps
?
WARNING:pip_audit._cli:--no-deps is supported, but users are encouraged to fully hash their pinned dependencies
WARNING:pip_audit._cli:Consider using a tool like `pip-compile`: https://pip-tools.readthedocs.io/en/latest/#using-hashes
WARNING:pip_audit._dependency_source.requirement:added fixed subdependency explicitly to requirements file main.txt: pyjwt
WARNING:pip_audit._dependency_source.requirement:encountered an exception while applying fixes, recovering original files: package pyjwt has duplicate requirements: pyjwt==2.4.0 (from RequirementLine(line_number=1575, line='pyjwt==2.4.0', filename='main.txt'))
Traceback (most recent call last):
File "/tmp/e/venv/bin/pip-audit", line 8, in <module>
sys.exit(audit())
File "/tmp/e/venv/lib/python3.10/site-packages/pip_audit/_cli.py", line 504, in audit
source.fix(fix)
File "/tmp/e/venv/lib/python3.10/site-packages/pip_audit/_dependency_source/requirement.py", line 168, in fix
raise e
File "/tmp/e/venv/lib/python3.10/site-packages/pip_audit/_dependency_source/requirement.py", line 162, in fix
self._fix_file(filename, fix_version)
File "/tmp/e/venv/lib/python3.10/site-packages/pip_audit/_dependency_source/requirement.py", line 189, in _fix_file
raise RequirementFixError(
pip_audit._dependency_source.requirement.RequirementFixError: package pyjwt has duplicate requirements: pyjwt==2.4.0 (from RequirementLine(line_number=1575, line='pyjwt==2.4.0', filename='main.txt'))
@tetsuo-cpp pip-audit v2.5.3 fails now with
--no-deps --fix
. note:--no-deps
is provided because of pypa/pip#9644
Hmm, that's because the --fix
codepath doesn't use pip
but instead parses the requirements file with pip-requirements-parser
. I think we just need to remove this check since pip
doesn't care about having multiple requirements for the same package.
Also what should I do, if i wanna pip-audit to replace existing version rather than adding new line with fixed version.
It should replace the existing version in the requirements file already. If it's adding a new line for a package that already exists in the requirements file, that's a bug. Do you have a repro?
I'm going to re-open this so we can address the --fix
side of things too.
@tetsuo-cpp
echo "pyjwt==1.7.1" > requirements.in
pip-compile --allow-unsafe --generate-hashes --resolver=backtracking --strip-extras
cat requirements.txt
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --generate-hashes --resolver=backtracking --strip-extras
#
pyjwt==1.7.1 \
--hash=sha256:5c6eca3c2940464d106b99ba83b00c6add741c9becaec087fb7ccdefea71350e \
--hash=sha256:8d59a976fb773f3e6a39c85636357c4f0e242707394cadadd9814f5cbaa20e96
# via -r requirements.in
pip-audit --fix --no-deps -r requirements.txt
cat requirements.txt
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --generate-hashes --resolver=backtracking --strip-extras
#
pyjwt==1.7.1 \
--hash=sha256:5c6eca3c2940464d106b99ba83b00c6add741c9becaec087fb7ccdefea71350e \
--hash=sha256:8d59a976fb773f3e6a39c85636357c4f0e242707394cadadd9814f5cbaa20e96
# via -r requirements.in
# pip-audit: subdependency explicitly fixed
pyjwt==2.4.0
It also fails without --no-deps
, just --fix
Thanks @q0w. That's definitely a bug. I'll open a new issue for that.
The changeset at #577 should fix this.
@woodruffw --fix
complaining about duplicates isn't new to 2.5.0 so this is probably not as urgent.
new case with pip-audit 2.6.0
echo docxcompose > a.in
echo gunicorn > b.in
pip-compile --allow-unsafe --generate-hashes --resolver=backtracking --strip-extras a.in
pip-compile --allow-unsafe --generate-hashes --resolver=backtracking --strip-extras b.in
pip-audit --fix --disable-pip -r a.txt -r b.txt
ERROR:pip_audit._cli:package setuptools has duplicate requirements: setuptools==68.0.0 (from RequirementLine(line_number=13, line='setuptools==68.0.0 --hash=sha256:11e52c67415a381d10d6b462ced9cfb97066179f0e871399e006c4ab101fc85f --hash=sha256:baf1fdb41c6da4cd2eae722e135500da913332ab3f2f5c7d33af9b492acb5235', filename=PosixPath('b.txt')))
It also fails without --fix
.
↑ This is a regression bug in 2.6.0 @woodruffw
↑ This is a regression bug in 2.6.0
Unless I'm misunderstanding, this is not a regression in 2.6.0: it's a known defect from the 2.4 and 2.5 releases. Are you saying that there's a new, different regression in 2.6.0, or are you confirming that the previous bug still exists?
This example above is working in <2.6.0
Gotcha, I understand now: I forgot that we left this open only for the --fix
part, and that we resolved the duplicate requirement issue on audits. Sorry for the regression here; I'll look into a fix.
Bug description
With using pip-tools workflow for layered requirements pip-audit fails because of duplicate requirements.
Reproduction steps
Expected behavior
No errors
Screenshots and logs
Platform information
pip-audit
version (pip-audit -V
): pip-audit 2.5.2python -V
orpython3 -V
): Python 3.10.10pip
version (pip -V
orpip3 -V
): pip 23.0.1Additional context