-
-
Notifications
You must be signed in to change notification settings - Fork 611
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
pip==23.3 breaking "extras" behavior #2004
Comments
Just a quick note:
The simple answer to this issue may just be that the |
Oof, in my local test, it comes out as
Using the legacy resolver, it's just
I tried adding a simple if ireq.extras:
ireq.extras = set(map(canonicalize_name, ireq.extras)) to the start of |
OK this may be sloppy, and I can never remember which ireq/req attributes are guaranteed, or how req affects ireq exactly, but the following addition at the top of if ireq.req and ireq.req.extras:
ireq.req.extras = set(map(canonicalize_name, ireq.req.extras))
if ireq.extras:
ireq.extras = set(map(canonicalize_name, ireq.extras)) I also don't know if the format method is the proper place to do this canonicalization. |
@AndydeCleyre I think that the normalization should happen whenever an instance of |
So another place we can get at this is in diff --git a/piptools/_compat/pip_compat.py b/piptools/_compat/pip_compat.py
index 6409fbc..6972f03 100644
--- a/piptools/_compat/pip_compat.py
+++ b/piptools/_compat/pip_compat.py
@@ -14,6 +14,7 @@ from pip._internal.network.session import PipSession
from pip._internal.req import InstallRequirement
from pip._internal.req import parse_requirements as _parse_requirements
from pip._internal.req.constructors import install_req_from_parsed_requirement
+from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.packaging.version import parse as parse_version
from pip._vendor.pkg_resources import Requirement
@@ -74,7 +75,10 @@ def parse_requirements(
for parsed_req in _parse_requirements(
filename, session, finder=finder, options=options, constraint=constraint
):
- yield install_req_from_parsed_requirement(parsed_req, isolated=isolated)
+ ireq = install_req_from_parsed_requirement(parsed_req, isolated=isolated)
+ if ireq.req.extras:
+ ireq.req.extras = set(map(canonicalize_name, ireq.req.extras))
+ yield ireq
def create_wheel_cache(cache_dir: str, format_control: str | None = None) -> WheelCache: But things I don't know include:
|
Some extras are getting duplicated. It doesn't appear to impact the resolver or pip's use of the requirements file but it is an unexpected change when updating to pip 23.3.x. This is pip 23.3.1 and pip-tools 7.3.0:
|
Maybe? Given it's not possible at some earlier stage...
Why not? Wouldn't “something else” also go through normalization?
Probably. I'd expect us to be consistent across the codebase.
I'd say yes. Canonicalization is well-defined now and as the time passes, more people will use newer pip versions that do this. At some point, we'll EOL support for pip versions that don't do such conversion and then, we'd just differ for no good reason. Maybe, we'd need to leave the original dep names in the comments, though. |
Maybe we should shadow all the |
Based on the case in jazzband#2004
Does pip not normalize in all places? I think it may make sense there too. |
Yeah we're getting non-normalized extras via |
Based on the case in jazzband#2004
I just wanted to share that in my experience, the duplicate extras DO impact the resolution, although it's possible that I'm misattributing the behavior. Some clarifications would help me understand if I should report an issue with In my case, having It's odd that the expected One additional tidbit: To work around this, we are explicitly listing
EDIT: Disregard the last. I was using the |
One other thing that seems related to this: It's odd, and I think unexpected, that a package listed in the I'm also happy to make that its own issue, if you feel it is distinct enough. Thanks! EDIT: Added the extra criteria that a version constraint must be used in order to provoke the unexpected behavior. |
Based on the case in jazzband#2004
@tboddyspargo I don't think I can reproduce the self-via issue. $ pip-compile --version
pip-compile, version 7.3.0
$ <<<'sqlalchemy[postgresql-psycopg2binary]' pip-compile --no-header - -o - 2>/dev/null
greenlet==3.0.1
# via sqlalchemy
sqlalchemy[postgresql-psycopg2binary]==2.0.23
# via -r -
typing-extensions==4.8.0
# via sqlalchemy And with my PR #2013: $ pip-compile --version
pip-compile, version 7.3.1.dev65
$ <<<'sqlalchemy[postgresql-psycopg2binary]' pip-compile --no-header - -o - 2>/dev/null
greenlet==3.0.1
# via sqlalchemy
sqlalchemy[postgresql-psycopg2binary]==2.0.23
# via -r -
typing-extensions==4.8.0
# via sqlalchemy |
Thanks for pointing that out, @AndydeCleyre! Your counter examples helped me realize that there's another contributing factor. It seems that the redundant $ pip-compile --version
pip-compile, version 7.3.0
$ <<<'sqlalchemy[postgresql-psycopg2binary]==2.0.23' pip-compile --no-header - -o - 2>/dev/null
greenlet==3.0.1
# via sqlalchemy
sqlalchemy[postgresql-psycopg2binary]==2.0.23
# via
# -r -
# sqlalchemy
typing-extensions==4.8.0
# via sqlalchemy Toggling the presence of |
Thanks! I can now reproduce using the main branch. I can't confidently say that's fixed by the mentioned PR, because I didn't set out to fix that problem, but I am not seeing it there. |
Based on the case in jazzband#2004
Based on the case in jazzband#2004
Based on the case in jazzband#2004
Based on the case in jazzband#2004
Based on the case in jazzband#2004
Apologies if this is implied by the ticket elsewhere, but pip==24.0 and pip-tools==7.4.0 emits a warning I don't think I saw before:
The name of the extra in the package and in my requirements.in is |
I can't reproduce that here on Linux with Python 3.11, with the versions you specified. Can you test if it still happens with #2013 ? |
Testing it out with that branch I don't get the warning. My output is:
Note that the underscore in pure_eval is replaced by a dash. I'd also expect the packages |
This is currently intentional.
Uh oh. Thanks! |
Based on the case in jazzband#2004
Based on the case in jazzband#2004
Based on the case in jazzband#2004
Based on the case in jazzband#2004
Based on the case in jazzband#2004
Using
pip==23.3.x
can result in invalidrequirements.txt
for projects that declare extras.A change in
pip==23.3.0
introduced the "canonicalization" of extras names:The canonicalization leads to this outcome:
requirements.in
:sqlalchemy[postgresql_psycopg2binary]
requirements.txt
:sqlalchemy[postgresql-psycopg2binary]
For many cases, this probably isn't an issue.
psycopg2-binary
still makes it intorequirements.txt
as an individual entry.For more "niche" cases, the extras still carry some significance.
eg. When using rules_python under the Bazel build system, the extras must properly resolve to build out a dependency graph.
Environment Versions
3.10.9
23.3.0
7.3.0
Steps to replicate
requirements.in
file.pip-tools
and the previous majorpip
version, runpip-compile
.python -m venv .venv . ./.venv/bin/activate pip install pip-tools==7.3.0 pip==22.3.1 pip-compile --no-strip-extras
requirement.txt
file listssqlalchemy[postgresql_psycopg2binary]
(with an underscore).pip>=23.3
, runpip-compile
.requirement.txt
file listssqlalchemy[postgresql-psycopg2binary]
(with a hyphen).Expected result
The valid input extras should still be valid in the output.
Actual result
The output extras will not resolve.
The text was updated successfully, but these errors were encountered: