Skip to content

Commit 9bc1d90

Browse files
committed
Pass scheme to build_wheel_for_editable
1 parent f45c459 commit 9bc1d90

File tree

8 files changed

+56
-6
lines changed

8 files changed

+56
-6
lines changed

src/pip/_internal/commands/install.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
2525
from pip._internal.cli.status_codes import ERROR, SUCCESS
2626
from pip._internal.exceptions import CommandError, InstallationError
27-
from pip._internal.locations import distutils_scheme
27+
from pip._internal.locations import distutils_scheme, get_scheme
2828
from pip._internal.operations.check import check_install_conflicts
2929
from pip._internal.req import install_given_reqs
3030
from pip._internal.req.req_tracker import get_requirement_tracker
@@ -46,6 +46,7 @@
4646
from optparse import Values
4747
from typing import Any, Iterable, List, Optional
4848

49+
from pip._internal.locations import Scheme
4950
from pip._internal.models.format_control import FormatControl
5051
from pip._internal.req.req_install import InstallRequirement
5152
from pip._internal.wheel_builder import BinaryAllowedPredicate
@@ -351,12 +352,24 @@ def run(self, options, args):
351352
)
352353
]
353354

355+
def get_scheme_for_req(name):
356+
# type: (str) -> Scheme
357+
return get_scheme(
358+
name,
359+
user=options.use_user_site,
360+
home=target_temp_dir_path,
361+
root=options.root_path,
362+
isolated=options.isolated_mode,
363+
prefix=options.prefix_path,
364+
)
365+
354366
_, build_failures = build(
355367
reqs_to_build,
356368
wheel_cache=wheel_cache,
357369
build_options=[],
358370
global_options=[],
359371
allow_editable=True,
372+
get_scheme_for_editable_req=get_scheme_for_req,
360373
)
361374

362375
# If we're using PEP 517, we cannot do a direct install

src/pip/_internal/commands/wheel.py

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def run(self, options, args):
168168
build_options=options.build_options or [],
169169
global_options=options.global_options or [],
170170
allow_editable=False,
171+
get_scheme_for_editable_req=None,
171172
)
172173
for req in build_successes:
173174
assert req.link and req.link.is_wheel

src/pip/_internal/locations.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
from pip._internal.utils.virtualenv import running_under_virtualenv
2323

2424
if MYPY_CHECK_RUNNING:
25-
from typing import Dict, List, Optional, Union
25+
from typing import Callable, Dict, List, Optional, Union
2626

2727
from distutils.cmd import Command as DistutilsCommand
2828

29+
GetSchemePredicate = Callable[[str], Scheme]
30+
2931

3032
# Application Directories
3133
USER_CACHE_DIR = appdirs.user_cache_dir("pip")

src/pip/_internal/models/scheme.py

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
For a general overview of available schemes and their context, see
55
https://docs.python.org/3/install/index.html#alternate-installation.
66
"""
7+
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
8+
9+
if MYPY_CHECK_RUNNING:
10+
from typing import Dict
711

812

913
class Scheme(object):
@@ -26,3 +30,13 @@ def __init__(
2630
self.headers = headers
2731
self.scripts = scripts
2832
self.data = data
33+
34+
def as_dict(self):
35+
# type: () -> Dict[str, str]
36+
return dict(
37+
platlib=self.platlib,
38+
purelib=self.purelib,
39+
headers=self.headers,
40+
scripts=self.scripts,
41+
data=self.data,
42+
)

src/pip/_internal/operations/build/wheel.py

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
if MYPY_CHECK_RUNNING:
1010
from typing import List, Optional
11+
from pip._internal.locations import Scheme
1112
from pip._vendor.pep517.wrappers import Pep517HookCaller
1213

1314
logger = logging.getLogger(__name__)
@@ -20,6 +21,7 @@ def build_wheel_pep517(
2021
build_options, # type: List[str]
2122
tempd, # type: str
2223
editable, # type: bool
24+
scheme, # type: Scheme
2325
):
2426
# type: (...) -> Optional[str]
2527
"""Build one InstallRequirement using the PEP 517 build process.
@@ -43,6 +45,7 @@ def build_wheel_pep517(
4345
try:
4446
wheel_name = backend.build_wheel_for_editable(
4547
tempd,
48+
scheme=scheme.as_dict(),
4649
metadata_directory=metadata_directory,
4750
)
4851
except HookMissing:

src/pip/_internal/wheel_builder.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
)
2525

2626
from pip._internal.cache import WheelCache
27+
from pip._internal.locations import GetSchemePredicate, Scheme
2728
from pip._internal.req.req_install import InstallRequirement
2829

2930
BinaryAllowedPredicate = Callable[[InstallRequirement], bool]
@@ -172,6 +173,7 @@ def _build_one(
172173
build_options, # type: List[str]
173174
global_options, # type: List[str]
174175
editable, # type: bool
176+
scheme, # type: Scheme
175177
):
176178
# type: (...) -> Optional[str]
177179
"""Build one wheel.
@@ -190,7 +192,7 @@ def _build_one(
190192
# Install build deps into temporary directory (PEP 518)
191193
with req.build_env:
192194
return _build_one_inside_env(
193-
req, output_dir, build_options, global_options, editable
195+
req, output_dir, build_options, global_options, editable, scheme
194196
)
195197

196198

@@ -200,6 +202,7 @@ def _build_one_inside_env(
200202
build_options, # type: List[str]
201203
global_options, # type: List[str]
202204
editable, # type: bool
205+
scheme, # type: Scheme
203206
):
204207
# type: (...) -> Optional[str]
205208
with TempDirectory(kind="wheel") as temp_dir:
@@ -213,6 +216,7 @@ def _build_one_inside_env(
213216
build_options=build_options,
214217
tempd=temp_dir.path,
215218
editable=editable,
219+
scheme=scheme,
216220
)
217221
else:
218222
wheel_path = build_wheel_legacy(
@@ -269,13 +273,16 @@ def build(
269273
build_options, # type: List[str]
270274
global_options, # type: List[str]
271275
allow_editable, # type: bool
276+
get_scheme_for_editable_req, # type: Optional[GetSchemePredicate]
272277
):
273278
# type: (...) -> BuildResult
274279
"""Build wheels.
275280
276281
:return: The list of InstallRequirement that succeeded to build and
277282
the list of InstallRequirement that failed to build.
278283
"""
284+
assert allow_editable == bool(get_scheme_for_editable_req)
285+
279286
if not requirements:
280287
return [], []
281288

@@ -289,11 +296,15 @@ def build(
289296
build_successes, build_failures = [], []
290297
for req in requirements:
291298
cache_dir = _get_cache_dir(req, wheel_cache)
299+
scheme = None
300+
if get_scheme_for_editable_req:
301+
scheme = get_scheme_for_editable_req(req.name)
292302
wheel_file = _build_one(
293303
req, cache_dir,
294304
build_options,
295305
global_options,
296306
allow_editable and req.editable,
307+
scheme=scheme,
297308
)
298309
if wheel_file:
299310
# Update the link for this.

src/pip/_vendor/pep517/_in_process.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def build_wheel(wheel_directory, config_settings, metadata_directory=None):
206206

207207

208208
def build_wheel_for_editable(
209-
wheel_directory, config_settings, metadata_directory=None
209+
wheel_directory, scheme, config_settings, metadata_directory=None
210210
):
211211
"""Invoke the optional build_wheel_for_editable hook.
212212
"""
@@ -216,7 +216,9 @@ def build_wheel_for_editable(
216216
except AttributeError:
217217
raise HookMissing()
218218
else:
219-
return hook(wheel_directory, config_settings, metadata_directory)
219+
return hook(
220+
wheel_directory, scheme, config_settings, metadata_directory
221+
)
220222

221223

222224
def get_requires_for_build_sdist(config_settings):

src/pip/_vendor/pep517/wrappers.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,20 @@ def build_wheel(
200200
})
201201

202202
def build_wheel_for_editable(
203-
self, wheel_directory, config_settings=None,
203+
self, wheel_directory, scheme, config_settings=None,
204204
metadata_directory=None):
205205
"""Build a wheel for editable install from this project.
206206
207207
Returns the name of the newly created file.
208+
209+
'scheme' is a dictionary with the following keys:
210+
'purelib', 'platlib', 'headers', 'scripts', 'data'.
208211
"""
209212
if metadata_directory is not None:
210213
metadata_directory = abspath(metadata_directory)
211214
return self._call_hook('build_wheel_for_editable', {
212215
'wheel_directory': abspath(wheel_directory),
216+
'scheme': scheme,
213217
'config_settings': config_settings,
214218
'metadata_directory': metadata_directory,
215219
})

0 commit comments

Comments
 (0)