Skip to content

Commit 8ef3283

Browse files
yan12125pradyunsg
authored andcommitted
Ensure all pip._vendor.* modules are mapped to debundled correspondences (#6113)
With the original `vendored()` implementation and such an initialization sequence: ``` vendored("packaging") vendored("packaging.version") ``` In `sys.modules`, `pip._vendor.packaging` is correctly connected to the debundled `packaging`, while `pip._vendor.packaging.version` is not, as the latter is `__import__`ed from the existing `pip._vendor.packaging` module. That results in the same issue as #5429 - `pip._vendor.packaging.version.Version` and `packaging.version.Version` cannot be compared. This patch attempts to fix this issue by skipping `__import__` from the vendored name. This is safe because `vendored()` is called only when `DEBUNDLED = True`, and vendored libraries are already deleted as per [debundling instructions](https://github.com/pypa/pip/blob/master/src/pip/_vendor/README.rst#debundling).
1 parent 7f6edbd commit 8ef3283

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

news/a1440b03-c0c6-4176-8e00-732517bed87b.trivial

Whitespace-only changes.

src/pip/_vendor/README.rst

+3
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,6 @@ extra work on your end in order to solve the problems described above.
146146
6. *(optional)* Update the ``pip_version_check`` logic to use the
147147
appropriate logic for determining the latest available version of pip and
148148
prompt the user with the correct upgrade message.
149+
150+
Note that partial debundling is **NOT** supported. You need to prepare wheels
151+
for all dependencies for successful debundling.

src/pip/_vendor/__init__.py

+14-17
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,21 @@ def vendored(modulename):
3030
vendored_name = "{0}.{1}".format(__name__, modulename)
3131

3232
try:
33-
__import__(vendored_name, globals(), locals(), level=0)
33+
__import__(modulename, globals(), locals(), level=0)
3434
except ImportError:
35-
try:
36-
__import__(modulename, globals(), locals(), level=0)
37-
except ImportError:
38-
# We can just silently allow import failures to pass here. If we
39-
# got to this point it means that ``import pip._vendor.whatever``
40-
# failed and so did ``import whatever``. Since we're importing this
41-
# upfront in an attempt to alias imports, not erroring here will
42-
# just mean we get a regular import error whenever pip *actually*
43-
# tries to import one of these modules to use it, which actually
44-
# gives us a better error message than we would have otherwise
45-
# gotten.
46-
pass
47-
else:
48-
sys.modules[vendored_name] = sys.modules[modulename]
49-
base, head = vendored_name.rsplit(".", 1)
50-
setattr(sys.modules[base], head, sys.modules[modulename])
35+
# We can just silently allow import failures to pass here. If we
36+
# got to this point it means that ``import pip._vendor.whatever``
37+
# failed and so did ``import whatever``. Since we're importing this
38+
# upfront in an attempt to alias imports, not erroring here will
39+
# just mean we get a regular import error whenever pip *actually*
40+
# tries to import one of these modules to use it, which actually
41+
# gives us a better error message than we would have otherwise
42+
# gotten.
43+
pass
44+
else:
45+
sys.modules[vendored_name] = sys.modules[modulename]
46+
base, head = vendored_name.rsplit(".", 1)
47+
setattr(sys.modules[base], head, sys.modules[modulename])
5148

5249

5350
# If we're operating in a debundled setup, then we want to go ahead and trigger

0 commit comments

Comments
 (0)