|
| 1 | +diff --git a/src/pip/_vendor/distlib/scripts.py b/src/pip/_vendor/distlib/scripts.py |
| 2 | +index cfa45d2af..e16292b83 100644 |
| 3 | +--- a/src/pip/_vendor/distlib/scripts.py |
| 4 | ++++ b/src/pip/_vendor/distlib/scripts.py |
| 5 | +@@ -49,6 +49,24 @@ if __name__ == '__main__': |
| 6 | + sys.exit(%(func)s()) |
| 7 | + ''' |
| 8 | + |
| 9 | ++# Pre-fetch the contents of all executable wrapper stubs. |
| 10 | ++# This is to address https://github.com/pypa/pip/issues/12666. |
| 11 | ++# When updating pip, we rename the old pip in place before installing the |
| 12 | ++# new version. If we try to fetch a wrapper *after* that rename, the finder |
| 13 | ++# machinery will be confused as the package is no longer available at the |
| 14 | ++# location where it was imported from. So we load everything into memory in |
| 15 | ++# advance. |
| 16 | ++ |
| 17 | ++# Issue 31: don't hardcode an absolute package name, but |
| 18 | ++# determine it relative to the current package |
| 19 | ++distlib_package = __name__.rsplit('.', 1)[0] |
| 20 | ++ |
| 21 | ++WRAPPERS = { |
| 22 | ++ r.name: r.bytes |
| 23 | ++ for r in finder(distlib_package).iterator("") |
| 24 | ++ if r.name.endswith(".exe") |
| 25 | ++} |
| 26 | ++ |
| 27 | + |
| 28 | + def enquote_executable(executable): |
| 29 | + if ' ' in executable: |
| 30 | +@@ -409,15 +427,11 @@ class ScriptMaker(object): |
| 31 | + bits = '32' |
| 32 | + platform_suffix = '-arm' if get_platform() == 'win-arm64' else '' |
| 33 | + name = '%s%s%s.exe' % (kind, bits, platform_suffix) |
| 34 | +- # Issue 31: don't hardcode an absolute package name, but |
| 35 | +- # determine it relative to the current package |
| 36 | +- distlib_package = __name__.rsplit('.', 1)[0] |
| 37 | +- resource = finder(distlib_package).find(name) |
| 38 | +- if not resource: |
| 39 | ++ if name not in WRAPPERS: |
| 40 | + msg = ('Unable to find resource %s in package %s' % |
| 41 | + (name, distlib_package)) |
| 42 | + raise ValueError(msg) |
| 43 | +- return resource.bytes |
| 44 | ++ return WRAPPERS[name] |
| 45 | + |
| 46 | + # Public API follows |
| 47 | + |
0 commit comments