-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the distlib changes into a patch
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
diff --git a/src/pip/_vendor/distlib/scripts.py b/src/pip/_vendor/distlib/scripts.py | ||
index cfa45d2af..e16292b83 100644 | ||
--- a/src/pip/_vendor/distlib/scripts.py | ||
+++ b/src/pip/_vendor/distlib/scripts.py | ||
@@ -49,6 +49,24 @@ if __name__ == '__main__': | ||
sys.exit(%(func)s()) | ||
''' | ||
|
||
+# Pre-fetch the contents of all executable wrapper stubs. | ||
+# This is to address https://github.com/pypa/pip/issues/12666. | ||
+# When updating pip, we rename the old pip in place before installing the | ||
+# new version. If we try to fetch a wrapper *after* that rename, the finder | ||
+# machinery will be confused as the package is no longer available at the | ||
+# location where it was imported from. So we load everything into memory in | ||
+# advance. | ||
+ | ||
+# Issue 31: don't hardcode an absolute package name, but | ||
+# determine it relative to the current package | ||
+distlib_package = __name__.rsplit('.', 1)[0] | ||
+ | ||
+WRAPPERS = { | ||
+ r.name: r.bytes | ||
+ for r in finder(distlib_package).iterator("") | ||
+ if r.name.endswith(".exe") | ||
+} | ||
+ | ||
|
||
def enquote_executable(executable): | ||
if ' ' in executable: | ||
@@ -409,15 +427,11 @@ class ScriptMaker(object): | ||
bits = '32' | ||
platform_suffix = '-arm' if get_platform() == 'win-arm64' else '' | ||
name = '%s%s%s.exe' % (kind, bits, platform_suffix) | ||
- # Issue 31: don't hardcode an absolute package name, but | ||
- # determine it relative to the current package | ||
- distlib_package = __name__.rsplit('.', 1)[0] | ||
- resource = finder(distlib_package).find(name) | ||
- if not resource: | ||
+ if name not in WRAPPERS: | ||
msg = ('Unable to find resource %s in package %s' % | ||
(name, distlib_package)) | ||
raise ValueError(msg) | ||
- return resource.bytes | ||
+ return WRAPPERS[name] | ||
|
||
# Public API follows | ||
|