2525from tempfile import NamedTemporaryFile
2626from typing import Dict , List , Optional , Set , Tuple
2727
28- from pip ._vendor .packaging .utils import canonicalize_name
29-
30- from python .private .pypi .whl_installer import arguments , wheel
28+ from python .private .pypi .whl_installer import arguments
3129
3230
3331def _configure_reproducible_wheels () -> None :
@@ -55,44 +53,8 @@ def _configure_reproducible_wheels() -> None:
5553 os .environ ["PYTHONHASHSEED" ] = "0"
5654
5755
58- def _parse_requirement_for_extra (
59- requirement : str ,
60- ) -> Tuple [Optional [str ], Optional [Set [str ]]]:
61- """Given a requirement string, returns the requirement name and set of extras, if extras specified.
62- Else, returns (None, None)
63- """
64-
65- # https://www.python.org/dev/peps/pep-0508/#grammar
66- extras_pattern = re .compile (
67- r"^\s*([0-9A-Za-z][0-9A-Za-z_.\-]*)\s*\[\s*([0-9A-Za-z][0-9A-Za-z_.\-]*(?:\s*,\s*[0-9A-Za-z][0-9A-Za-z_.\-]*)*)\s*\]"
68- )
69-
70- matches = extras_pattern .match (requirement )
71- if matches :
72- return (
73- canonicalize_name (matches .group (1 )),
74- {extra .strip () for extra in matches .group (2 ).split ("," )},
75- )
76-
77- return None , None
7856
7957
80- def _extract_wheel (
81- wheel_file : str ,
82- extras : Dict [str , Set [str ]],
83- installation_dir : Path = Path ("." ),
84- ) -> None :
85- """Extracts wheel into given directory and creates py_library and filegroup targets.
86-
87- Args:
88- wheel_file: the filepath of the .whl
89- installation_dir: the destination directory for installation of the wheel.
90- extras: a list of extras to add as dependencies for the installed wheel
91- """
92-
93- whl = wheel .Wheel (wheel_file )
94- whl .unzip (installation_dir )
95-
9658
9759def main () -> None :
9860 args = arguments .parser (description = __doc__ ).parse_args ()
@@ -101,17 +63,6 @@ def main() -> None:
10163
10264 _configure_reproducible_wheels ()
10365
104- if args .whl_file :
105- whl = Path (args .whl_file )
106-
107- name , extras_for_pkg = _parse_requirement_for_extra (args .requirement )
108- extras = {name : extras_for_pkg } if extras_for_pkg and name else dict ()
109- _extract_wheel (
110- wheel_file = whl ,
111- extras = extras ,
112- )
113- return
114-
11566 pip_args = (
11667 [sys .executable , "-m" , "pip" ]
11768 + (["--isolated" ] if args .isolated else [])
0 commit comments