|
49 | 49 | sys.exit(%(func)s())
|
50 | 50 | '''
|
51 | 51 |
|
| 52 | +# Pre-fetch the contents of all executable wrapper stubs. |
| 53 | +# This is to address https://github.com/pypa/pip/issues/12666. |
| 54 | +# When updating pip, we rename the old pip in place before installing the |
| 55 | +# new version. If we try to fetch a wrapper *after* that rename, the finder |
| 56 | +# machinery will be confused as the package is no longer available at the |
| 57 | +# location where it was imported from. So we load everything into memory in |
| 58 | +# advance. |
| 59 | + |
| 60 | +# Issue 31: don't hardcode an absolute package name, but |
| 61 | +# determine it relative to the current package |
| 62 | +distlib_package = __name__.rsplit('.', 1)[0] |
| 63 | + |
| 64 | +WRAPPERS = { |
| 65 | + r.name: r.bytes |
| 66 | + for r in finder(distlib_package).iterator("") |
| 67 | + if r.name.endswith(".exe") |
| 68 | +} |
| 69 | + |
52 | 70 |
|
53 | 71 | def enquote_executable(executable):
|
54 | 72 | if ' ' in executable:
|
@@ -409,15 +427,11 @@ def _get_launcher(self, kind):
|
409 | 427 | bits = '32'
|
410 | 428 | platform_suffix = '-arm' if get_platform() == 'win-arm64' else ''
|
411 | 429 | name = '%s%s%s.exe' % (kind, bits, platform_suffix)
|
412 |
| - # Issue 31: don't hardcode an absolute package name, but |
413 |
| - # determine it relative to the current package |
414 |
| - distlib_package = __name__.rsplit('.', 1)[0] |
415 |
| - resource = finder(distlib_package).find(name) |
416 |
| - if not resource: |
| 430 | + if name not in WRAPPERS: |
417 | 431 | msg = ('Unable to find resource %s in package %s' %
|
418 | 432 | (name, distlib_package))
|
419 | 433 | raise ValueError(msg)
|
420 |
| - return resource.bytes |
| 434 | + return WRAPPERS[name] |
421 | 435 |
|
422 | 436 | # Public API follows
|
423 | 437 |
|
|
0 commit comments