wheel.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. """Support for installing and building the "wheel" binary package format.
  2. """
  3. # The following comment should be removed at some point in the future.
  4. # mypy: strict-optional=False
  5. from __future__ import absolute_import
  6. import collections
  7. import compileall
  8. import contextlib
  9. import csv
  10. import logging
  11. import os.path
  12. import re
  13. import shutil
  14. import stat
  15. import sys
  16. import warnings
  17. from base64 import urlsafe_b64encode
  18. from itertools import starmap
  19. from zipfile import ZipFile
  20. from pip._vendor import pkg_resources
  21. from pip._vendor.distlib.scripts import ScriptMaker
  22. from pip._vendor.distlib.util import get_export_entry
  23. from pip._vendor.six import StringIO
  24. from pip._internal.exceptions import InstallationError
  25. from pip._internal.locations import get_major_minor_version
  26. from pip._internal.models.direct_url import DIRECT_URL_METADATA_NAME, DirectUrl
  27. from pip._internal.utils.filesystem import adjacent_tmp_file, replace
  28. from pip._internal.utils.misc import captured_stdout, ensure_dir, hash_file
  29. from pip._internal.utils.temp_dir import TempDirectory
  30. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  31. from pip._internal.utils.unpacking import current_umask, unpack_file
  32. from pip._internal.utils.wheel import parse_wheel
  33. if MYPY_CHECK_RUNNING:
  34. from email.message import Message
  35. from typing import (
  36. Dict, List, Optional, Sequence, Tuple, Any,
  37. Iterable, Iterator, Callable, Set,
  38. )
  39. from pip._internal.models.scheme import Scheme
  40. from pip._internal.utils.filesystem import NamedTemporaryFileResult
  41. InstalledCSVRow = Tuple[str, ...]
  42. logger = logging.getLogger(__name__)
  43. def normpath(src, p):
  44. # type: (str, str) -> str
  45. return os.path.relpath(src, p).replace(os.path.sep, '/')
  46. def rehash(path, blocksize=1 << 20):
  47. # type: (str, int) -> Tuple[str, str]
  48. """Return (encoded_digest, length) for path using hashlib.sha256()"""
  49. h, length = hash_file(path, blocksize)
  50. digest = 'sha256=' + urlsafe_b64encode(
  51. h.digest()
  52. ).decode('latin1').rstrip('=')
  53. # unicode/str python2 issues
  54. return (digest, str(length)) # type: ignore
  55. def csv_io_kwargs(mode):
  56. # type: (str) -> Dict[str, Any]
  57. """Return keyword arguments to properly open a CSV file
  58. in the given mode.
  59. """
  60. if sys.version_info.major < 3:
  61. return {'mode': '{}b'.format(mode)}
  62. else:
  63. return {'mode': mode, 'newline': ''}
  64. def fix_script(path):
  65. # type: (str) -> Optional[bool]
  66. """Replace #!python with #!/path/to/python
  67. Return True if file was changed.
  68. """
  69. # XXX RECORD hashes will need to be updated
  70. if os.path.isfile(path):
  71. with open(path, 'rb') as script:
  72. firstline = script.readline()
  73. if not firstline.startswith(b'#!python'):
  74. return False
  75. exename = sys.executable.encode(sys.getfilesystemencoding())
  76. firstline = b'#!' + exename + os.linesep.encode("ascii")
  77. rest = script.read()
  78. with open(path, 'wb') as script:
  79. script.write(firstline)
  80. script.write(rest)
  81. return True
  82. return None
  83. def wheel_root_is_purelib(metadata):
  84. # type: (Message) -> bool
  85. return metadata.get("Root-Is-Purelib", "").lower() == "true"
  86. def get_entrypoints(filename):
  87. # type: (str) -> Tuple[Dict[str, str], Dict[str, str]]
  88. if not os.path.exists(filename):
  89. return {}, {}
  90. # This is done because you can pass a string to entry_points wrappers which
  91. # means that they may or may not be valid INI files. The attempt here is to
  92. # strip leading and trailing whitespace in order to make them valid INI
  93. # files.
  94. with open(filename) as fp:
  95. data = StringIO()
  96. for line in fp:
  97. data.write(line.strip())
  98. data.write("\n")
  99. data.seek(0)
  100. # get the entry points and then the script names
  101. entry_points = pkg_resources.EntryPoint.parse_map(data)
  102. console = entry_points.get('console_scripts', {})
  103. gui = entry_points.get('gui_scripts', {})
  104. def _split_ep(s):
  105. # type: (pkg_resources.EntryPoint) -> Tuple[str, str]
  106. """get the string representation of EntryPoint,
  107. remove space and split on '='
  108. """
  109. split_parts = str(s).replace(" ", "").split("=")
  110. return split_parts[0], split_parts[1]
  111. # convert the EntryPoint objects into strings with module:function
  112. console = dict(_split_ep(v) for v in console.values())
  113. gui = dict(_split_ep(v) for v in gui.values())
  114. return console, gui
  115. def message_about_scripts_not_on_PATH(scripts):
  116. # type: (Sequence[str]) -> Optional[str]
  117. """Determine if any scripts are not on PATH and format a warning.
  118. Returns a warning message if one or more scripts are not on PATH,
  119. otherwise None.
  120. """
  121. if not scripts:
  122. return None
  123. # Group scripts by the path they were installed in
  124. grouped_by_dir = collections.defaultdict(set) # type: Dict[str, Set[str]]
  125. for destfile in scripts:
  126. parent_dir = os.path.dirname(destfile)
  127. script_name = os.path.basename(destfile)
  128. grouped_by_dir[parent_dir].add(script_name)
  129. # We don't want to warn for directories that are on PATH.
  130. not_warn_dirs = [
  131. os.path.normcase(i).rstrip(os.sep) for i in
  132. os.environ.get("PATH", "").split(os.pathsep)
  133. ]
  134. # If an executable sits with sys.executable, we don't warn for it.
  135. # This covers the case of venv invocations without activating the venv.
  136. not_warn_dirs.append(os.path.normcase(os.path.dirname(sys.executable)))
  137. warn_for = {
  138. parent_dir: scripts for parent_dir, scripts in grouped_by_dir.items()
  139. if os.path.normcase(parent_dir) not in not_warn_dirs
  140. } # type: Dict[str, Set[str]]
  141. if not warn_for:
  142. return None
  143. # Format a message
  144. msg_lines = []
  145. for parent_dir, dir_scripts in warn_for.items():
  146. sorted_scripts = sorted(dir_scripts) # type: List[str]
  147. if len(sorted_scripts) == 1:
  148. start_text = "script {} is".format(sorted_scripts[0])
  149. else:
  150. start_text = "scripts {} are".format(
  151. ", ".join(sorted_scripts[:-1]) + " and " + sorted_scripts[-1]
  152. )
  153. msg_lines.append(
  154. "The {} installed in '{}' which is not on PATH."
  155. .format(start_text, parent_dir)
  156. )
  157. last_line_fmt = (
  158. "Consider adding {} to PATH or, if you prefer "
  159. "to suppress this warning, use --no-warn-script-location."
  160. )
  161. if len(msg_lines) == 1:
  162. msg_lines.append(last_line_fmt.format("this directory"))
  163. else:
  164. msg_lines.append(last_line_fmt.format("these directories"))
  165. # Add a note if any directory starts with ~
  166. warn_for_tilde = any(
  167. i[0] == "~" for i in os.environ.get("PATH", "").split(os.pathsep) if i
  168. )
  169. if warn_for_tilde:
  170. tilde_warning_msg = (
  171. "NOTE: The current PATH contains path(s) starting with `~`, "
  172. "which may not be expanded by all applications."
  173. )
  174. msg_lines.append(tilde_warning_msg)
  175. # Returns the formatted multiline message
  176. return "\n".join(msg_lines)
  177. def sorted_outrows(outrows):
  178. # type: (Iterable[InstalledCSVRow]) -> List[InstalledCSVRow]
  179. """Return the given rows of a RECORD file in sorted order.
  180. Each row is a 3-tuple (path, hash, size) and corresponds to a record of
  181. a RECORD file (see PEP 376 and PEP 427 for details). For the rows
  182. passed to this function, the size can be an integer as an int or string,
  183. or the empty string.
  184. """
  185. # Normally, there should only be one row per path, in which case the
  186. # second and third elements don't come into play when sorting.
  187. # However, in cases in the wild where a path might happen to occur twice,
  188. # we don't want the sort operation to trigger an error (but still want
  189. # determinism). Since the third element can be an int or string, we
  190. # coerce each element to a string to avoid a TypeError in this case.
  191. # For additional background, see--
  192. # https://github.com/pypa/pip/issues/5868
  193. return sorted(outrows, key=lambda row: tuple(str(x) for x in row))
  194. def get_csv_rows_for_installed(
  195. old_csv_rows, # type: Iterable[List[str]]
  196. installed, # type: Dict[str, str]
  197. changed, # type: Set[str]
  198. generated, # type: List[str]
  199. lib_dir, # type: str
  200. ):
  201. # type: (...) -> List[InstalledCSVRow]
  202. """
  203. :param installed: A map from archive RECORD path to installation RECORD
  204. path.
  205. """
  206. installed_rows = [] # type: List[InstalledCSVRow]
  207. for row in old_csv_rows:
  208. if len(row) > 3:
  209. logger.warning(
  210. 'RECORD line has more than three elements: {}'.format(row)
  211. )
  212. # Make a copy because we are mutating the row.
  213. row = list(row)
  214. old_path = row[0]
  215. new_path = installed.pop(old_path, old_path)
  216. row[0] = new_path
  217. if new_path in changed:
  218. digest, length = rehash(new_path)
  219. row[1] = digest
  220. row[2] = length
  221. installed_rows.append(tuple(row))
  222. for f in generated:
  223. digest, length = rehash(f)
  224. installed_rows.append((normpath(f, lib_dir), digest, str(length)))
  225. for f in installed:
  226. installed_rows.append((installed[f], '', ''))
  227. return installed_rows
  228. class MissingCallableSuffix(Exception):
  229. pass
  230. def _raise_for_invalid_entrypoint(specification):
  231. # type: (str) -> None
  232. entry = get_export_entry(specification)
  233. if entry is not None and entry.suffix is None:
  234. raise MissingCallableSuffix(str(entry))
  235. class PipScriptMaker(ScriptMaker):
  236. def make(self, specification, options=None):
  237. # type: (str, Dict[str, Any]) -> List[str]
  238. _raise_for_invalid_entrypoint(specification)
  239. return super(PipScriptMaker, self).make(specification, options)
  240. def install_unpacked_wheel(
  241. name, # type: str
  242. wheeldir, # type: str
  243. wheel_zip, # type: ZipFile
  244. scheme, # type: Scheme
  245. req_description, # type: str
  246. pycompile=True, # type: bool
  247. warn_script_location=True, # type: bool
  248. direct_url=None, # type: Optional[DirectUrl]
  249. ):
  250. # type: (...) -> None
  251. """Install a wheel.
  252. :param name: Name of the project to install
  253. :param wheeldir: Base directory of the unpacked wheel
  254. :param wheel_zip: open ZipFile for wheel being installed
  255. :param scheme: Distutils scheme dictating the install directories
  256. :param req_description: String used in place of the requirement, for
  257. logging
  258. :param pycompile: Whether to byte-compile installed Python files
  259. :param warn_script_location: Whether to check that scripts are installed
  260. into a directory on PATH
  261. :raises UnsupportedWheel:
  262. * when the directory holds an unpacked wheel with incompatible
  263. Wheel-Version
  264. * when the .dist-info dir does not match the wheel
  265. """
  266. # TODO: Investigate and break this up.
  267. # TODO: Look into moving this into a dedicated class for representing an
  268. # installation.
  269. source = wheeldir.rstrip(os.path.sep) + os.path.sep
  270. info_dir, metadata = parse_wheel(wheel_zip, name)
  271. if wheel_root_is_purelib(metadata):
  272. lib_dir = scheme.purelib
  273. else:
  274. lib_dir = scheme.platlib
  275. subdirs = os.listdir(source)
  276. data_dirs = [s for s in subdirs if s.endswith('.data')]
  277. # Record details of the files moved
  278. # installed = files copied from the wheel to the destination
  279. # changed = files changed while installing (scripts #! line typically)
  280. # generated = files newly generated during the install (script wrappers)
  281. installed = {} # type: Dict[str, str]
  282. changed = set()
  283. generated = [] # type: List[str]
  284. # Compile all of the pyc files that we're going to be installing
  285. if pycompile:
  286. with captured_stdout() as stdout:
  287. with warnings.catch_warnings():
  288. warnings.filterwarnings('ignore')
  289. compileall.compile_dir(source, force=True, quiet=True)
  290. logger.debug(stdout.getvalue())
  291. def record_installed(srcfile, destfile, modified=False):
  292. # type: (str, str, bool) -> None
  293. """Map archive RECORD paths to installation RECORD paths."""
  294. oldpath = normpath(srcfile, wheeldir)
  295. newpath = normpath(destfile, lib_dir)
  296. installed[oldpath] = newpath
  297. if modified:
  298. changed.add(destfile)
  299. def clobber(
  300. source, # type: str
  301. dest, # type: str
  302. is_base, # type: bool
  303. fixer=None, # type: Optional[Callable[[str], Any]]
  304. filter=None # type: Optional[Callable[[str], bool]]
  305. ):
  306. # type: (...) -> None
  307. ensure_dir(dest) # common for the 'include' path
  308. for dir, subdirs, files in os.walk(source):
  309. basedir = dir[len(source):].lstrip(os.path.sep)
  310. destdir = os.path.join(dest, basedir)
  311. if is_base and basedir == '':
  312. subdirs[:] = [s for s in subdirs if not s.endswith('.data')]
  313. for f in files:
  314. # Skip unwanted files
  315. if filter and filter(f):
  316. continue
  317. srcfile = os.path.join(dir, f)
  318. destfile = os.path.join(dest, basedir, f)
  319. # directory creation is lazy and after the file filtering above
  320. # to ensure we don't install empty dirs; empty dirs can't be
  321. # uninstalled.
  322. ensure_dir(destdir)
  323. # copyfile (called below) truncates the destination if it
  324. # exists and then writes the new contents. This is fine in most
  325. # cases, but can cause a segfault if pip has loaded a shared
  326. # object (e.g. from pyopenssl through its vendored urllib3)
  327. # Since the shared object is mmap'd an attempt to call a
  328. # symbol in it will then cause a segfault. Unlinking the file
  329. # allows writing of new contents while allowing the process to
  330. # continue to use the old copy.
  331. if os.path.exists(destfile):
  332. os.unlink(destfile)
  333. # We use copyfile (not move, copy, or copy2) to be extra sure
  334. # that we are not moving directories over (copyfile fails for
  335. # directories) as well as to ensure that we are not copying
  336. # over any metadata because we want more control over what
  337. # metadata we actually copy over.
  338. shutil.copyfile(srcfile, destfile)
  339. # Copy over the metadata for the file, currently this only
  340. # includes the atime and mtime.
  341. st = os.stat(srcfile)
  342. if hasattr(os, "utime"):
  343. os.utime(destfile, (st.st_atime, st.st_mtime))
  344. # If our file is executable, then make our destination file
  345. # executable.
  346. if os.access(srcfile, os.X_OK):
  347. st = os.stat(srcfile)
  348. permissions = (
  349. st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
  350. )
  351. os.chmod(destfile, permissions)
  352. changed = False
  353. if fixer:
  354. changed = fixer(destfile)
  355. record_installed(srcfile, destfile, changed)
  356. clobber(source, lib_dir, True)
  357. dest_info_dir = os.path.join(lib_dir, info_dir)
  358. # Get the defined entry points
  359. ep_file = os.path.join(dest_info_dir, 'entry_points.txt')
  360. console, gui = get_entrypoints(ep_file)
  361. def is_entrypoint_wrapper(name):
  362. # type: (str) -> bool
  363. # EP, EP.exe and EP-script.py are scripts generated for
  364. # entry point EP by setuptools
  365. if name.lower().endswith('.exe'):
  366. matchname = name[:-4]
  367. elif name.lower().endswith('-script.py'):
  368. matchname = name[:-10]
  369. elif name.lower().endswith(".pya"):
  370. matchname = name[:-4]
  371. else:
  372. matchname = name
  373. # Ignore setuptools-generated scripts
  374. return (matchname in console or matchname in gui)
  375. for datadir in data_dirs:
  376. fixer = None
  377. filter = None
  378. for subdir in os.listdir(os.path.join(wheeldir, datadir)):
  379. fixer = None
  380. if subdir == 'scripts':
  381. fixer = fix_script
  382. filter = is_entrypoint_wrapper
  383. source = os.path.join(wheeldir, datadir, subdir)
  384. dest = getattr(scheme, subdir)
  385. clobber(source, dest, False, fixer=fixer, filter=filter)
  386. maker = PipScriptMaker(None, scheme.scripts)
  387. # Ensure old scripts are overwritten.
  388. # See https://github.com/pypa/pip/issues/1800
  389. maker.clobber = True
  390. # Ensure we don't generate any variants for scripts because this is almost
  391. # never what somebody wants.
  392. # See https://bitbucket.org/pypa/distlib/issue/35/
  393. maker.variants = {''}
  394. # This is required because otherwise distlib creates scripts that are not
  395. # executable.
  396. # See https://bitbucket.org/pypa/distlib/issue/32/
  397. maker.set_mode = True
  398. scripts_to_generate = []
  399. # Special case pip and setuptools to generate versioned wrappers
  400. #
  401. # The issue is that some projects (specifically, pip and setuptools) use
  402. # code in setup.py to create "versioned" entry points - pip2.7 on Python
  403. # 2.7, pip3.3 on Python 3.3, etc. But these entry points are baked into
  404. # the wheel metadata at build time, and so if the wheel is installed with
  405. # a *different* version of Python the entry points will be wrong. The
  406. # correct fix for this is to enhance the metadata to be able to describe
  407. # such versioned entry points, but that won't happen till Metadata 2.0 is
  408. # available.
  409. # In the meantime, projects using versioned entry points will either have
  410. # incorrect versioned entry points, or they will not be able to distribute
  411. # "universal" wheels (i.e., they will need a wheel per Python version).
  412. #
  413. # Because setuptools and pip are bundled with _ensurepip and virtualenv,
  414. # we need to use universal wheels. So, as a stopgap until Metadata 2.0, we
  415. # override the versioned entry points in the wheel and generate the
  416. # correct ones. This code is purely a short-term measure until Metadata 2.0
  417. # is available.
  418. #
  419. # To add the level of hack in this section of code, in order to support
  420. # ensurepip this code will look for an ``ENSUREPIP_OPTIONS`` environment
  421. # variable which will control which version scripts get installed.
  422. #
  423. # ENSUREPIP_OPTIONS=altinstall
  424. # - Only pipX.Y and easy_install-X.Y will be generated and installed
  425. # ENSUREPIP_OPTIONS=install
  426. # - pipX.Y, pipX, easy_install-X.Y will be generated and installed. Note
  427. # that this option is technically if ENSUREPIP_OPTIONS is set and is
  428. # not altinstall
  429. # DEFAULT
  430. # - The default behavior is to install pip, pipX, pipX.Y, easy_install
  431. # and easy_install-X.Y.
  432. pip_script = console.pop('pip', None)
  433. if pip_script:
  434. if "ENSUREPIP_OPTIONS" not in os.environ:
  435. scripts_to_generate.append('pip = ' + pip_script)
  436. if os.environ.get("ENSUREPIP_OPTIONS", "") != "altinstall":
  437. scripts_to_generate.append(
  438. 'pip{} = {}'.format(sys.version_info[0], pip_script)
  439. )
  440. scripts_to_generate.append(
  441. 'pip{} = {}'.format(get_major_minor_version(), pip_script)
  442. )
  443. # Delete any other versioned pip entry points
  444. pip_ep = [k for k in console if re.match(r'pip(\d(\.\d)?)?$', k)]
  445. for k in pip_ep:
  446. del console[k]
  447. easy_install_script = console.pop('easy_install', None)
  448. if easy_install_script:
  449. if "ENSUREPIP_OPTIONS" not in os.environ:
  450. scripts_to_generate.append(
  451. 'easy_install = ' + easy_install_script
  452. )
  453. scripts_to_generate.append(
  454. 'easy_install-{} = {}'.format(
  455. get_major_minor_version(), easy_install_script
  456. )
  457. )
  458. # Delete any other versioned easy_install entry points
  459. easy_install_ep = [
  460. k for k in console if re.match(r'easy_install(-\d\.\d)?$', k)
  461. ]
  462. for k in easy_install_ep:
  463. del console[k]
  464. # Generate the console and GUI entry points specified in the wheel
  465. scripts_to_generate.extend(starmap('{} = {}'.format, console.items()))
  466. gui_scripts_to_generate = list(starmap('{} = {}'.format, gui.items()))
  467. generated_console_scripts = [] # type: List[str]
  468. try:
  469. generated_console_scripts = maker.make_multiple(scripts_to_generate)
  470. generated.extend(generated_console_scripts)
  471. generated.extend(
  472. maker.make_multiple(gui_scripts_to_generate, {'gui': True})
  473. )
  474. except MissingCallableSuffix as e:
  475. entry = e.args[0]
  476. raise InstallationError(
  477. "Invalid script entry point: {} for req: {} - A callable "
  478. "suffix is required. Cf https://packaging.python.org/"
  479. "specifications/entry-points/#use-for-scripts for more "
  480. "information.".format(entry, req_description)
  481. )
  482. if warn_script_location:
  483. msg = message_about_scripts_not_on_PATH(generated_console_scripts)
  484. if msg is not None:
  485. logger.warning(msg)
  486. generated_file_mode = 0o666 & ~current_umask()
  487. @contextlib.contextmanager
  488. def _generate_file(path, **kwargs):
  489. # type: (str, **Any) -> Iterator[NamedTemporaryFileResult]
  490. with adjacent_tmp_file(path, **kwargs) as f:
  491. yield f
  492. os.chmod(f.name, generated_file_mode)
  493. replace(f.name, path)
  494. # Record pip as the installer
  495. installer_path = os.path.join(dest_info_dir, 'INSTALLER')
  496. with _generate_file(installer_path) as installer_file:
  497. installer_file.write(b'pip\n')
  498. generated.append(installer_path)
  499. # Record the PEP 610 direct URL reference
  500. if direct_url is not None:
  501. direct_url_path = os.path.join(dest_info_dir, DIRECT_URL_METADATA_NAME)
  502. with _generate_file(direct_url_path) as direct_url_file:
  503. direct_url_file.write(direct_url.to_json().encode("utf-8"))
  504. generated.append(direct_url_path)
  505. # Record details of all files installed
  506. record_path = os.path.join(dest_info_dir, 'RECORD')
  507. with open(record_path, **csv_io_kwargs('r')) as record_file:
  508. rows = get_csv_rows_for_installed(
  509. csv.reader(record_file),
  510. installed=installed,
  511. changed=changed,
  512. generated=generated,
  513. lib_dir=lib_dir)
  514. with _generate_file(record_path, **csv_io_kwargs('w')) as record_file:
  515. writer = csv.writer(record_file)
  516. writer.writerows(sorted_outrows(rows)) # sort to simplify testing
  517. def install_wheel(
  518. name, # type: str
  519. wheel_path, # type: str
  520. scheme, # type: Scheme
  521. req_description, # type: str
  522. pycompile=True, # type: bool
  523. warn_script_location=True, # type: bool
  524. _temp_dir_for_testing=None, # type: Optional[str]
  525. direct_url=None, # type: Optional[DirectUrl]
  526. ):
  527. # type: (...) -> None
  528. with TempDirectory(
  529. path=_temp_dir_for_testing, kind="unpacked-wheel"
  530. ) as unpacked_dir, ZipFile(wheel_path, allowZip64=True) as z:
  531. unpack_file(wheel_path, unpacked_dir.path)
  532. install_unpacked_wheel(
  533. name=name,
  534. wheeldir=unpacked_dir.path,
  535. wheel_zip=z,
  536. scheme=scheme,
  537. req_description=req_description,
  538. pycompile=pycompile,
  539. warn_script_location=warn_script_location,
  540. direct_url=direct_url,
  541. )