Skip to content

Commit 966d792

Browse files
committed
Pass scheme to build_wheel_for_editable
1 parent 66902f6 commit 966d792

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
@@ -353,12 +354,24 @@ def run(self, options, args):
353354
)
354355
]
355356

357+
def get_scheme_for_req(name):
358+
# type: (str) -> Scheme
359+
return get_scheme(
360+
name,
361+
user=options.use_user_site,
362+
home=target_temp_dir_path,
363+
root=options.root_path,
364+
isolated=options.isolated_mode,
365+
prefix=options.prefix_path,
366+
)
367+
356368
_, build_failures = build(
357369
reqs_to_build,
358370
wheel_cache=wheel_cache,
359371
build_options=[],
360372
global_options=[],
361373
allow_editable=True,
374+
get_scheme_for_editable_req=get_scheme_for_req,
362375
)
363376

364377
# 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
@@ -171,6 +171,7 @@ def run(self, options, args):
171171
build_options=options.build_options or [],
172172
global_options=options.global_options or [],
173173
allow_editable=False,
174+
get_scheme_for_editable_req=None,
174175
)
175176
for req in build_successes:
176177
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):
@@ -23,3 +27,13 @@ def __init__(
2327
self.headers = headers
2428
self.scripts = scripts
2529
self.data = data
30+
31+
def as_dict(self):
32+
# type: () -> Dict[str, str]
33+
return dict(
34+
platlib=self.platlib,
35+
purelib=self.purelib,
36+
headers=self.headers,
37+
scripts=self.scripts,
38+
data=self.data,
39+
)

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
@@ -27,6 +27,7 @@
2727
)
2828

2929
from pip._internal.cache import WheelCache
30+
from pip._internal.locations import GetSchemePredicate, Scheme
3031
from pip._internal.req.req_install import InstallRequirement
3132

3233
BinaryAllowedPredicate = Callable[[InstallRequirement], bool]
@@ -173,6 +174,7 @@ def _build_one(
173174
build_options, # type: List[str]
174175
global_options, # type: List[str]
175176
editable, # type: bool
177+
scheme, # type: Scheme
176178
):
177179
# type: (...) -> Optional[str]
178180
"""Build one wheel.
@@ -191,7 +193,7 @@ def _build_one(
191193
# Install build deps into temporary directory (PEP 518)
192194
with req.build_env:
193195
return _build_one_inside_env(
194-
req, output_dir, build_options, global_options, editable
196+
req, output_dir, build_options, global_options, editable, scheme
195197
)
196198

197199

@@ -201,6 +203,7 @@ def _build_one_inside_env(
201203
build_options, # type: List[str]
202204
global_options, # type: List[str]
203205
editable, # type: bool
206+
scheme, # type: Scheme
204207
):
205208
# type: (...) -> Optional[str]
206209
with TempDirectory(kind="wheel") as temp_dir:
@@ -212,6 +215,7 @@ def _build_one_inside_env(
212215
build_options=build_options,
213216
tempd=temp_dir.path,
214217
editable=editable,
218+
scheme=scheme,
215219
)
216220
else:
217221
wheel_path = build_wheel_legacy(
@@ -268,13 +272,16 @@ def build(
268272
build_options, # type: List[str]
269273
global_options, # type: List[str]
270274
allow_editable, # type: bool
275+
get_scheme_for_editable_req, # type: Optional[GetSchemePredicate]
271276
):
272277
# type: (...) -> BuildResult
273278
"""Build wheels.
274279
275280
:return: The list of InstallRequirement that succeeded to build and
276281
the list of InstallRequirement that failed to build.
277282
"""
283+
assert allow_editable == bool(get_scheme_for_editable_req)
284+
278285
if not requirements:
279286
return [], []
280287

@@ -288,11 +295,15 @@ def build(
288295
build_successes, build_failures = [], []
289296
for req in requirements:
290297
cache_dir = _get_cache_dir(req, wheel_cache)
298+
scheme = None
299+
if get_scheme_for_editable_req:
300+
scheme = get_scheme_for_editable_req(req.name)
291301
wheel_file = _build_one(
292302
req, cache_dir,
293303
build_options,
294304
global_options,
295305
allow_editable and req.editable,
306+
scheme=scheme,
296307
)
297308
if wheel_file:
298309
# Update the link for this.

src/pip/_vendor/pep517/_in_process.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,22 @@ 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.
212+
213+
'scheme' is a dictionary with the following keys:
214+
'purelib', 'platlib', 'headers', 'scripts', 'data'.
212215
"""
213216
backend = _build_backend()
214217
try:
215218
hook = backend.build_wheel_for_editable
216219
except AttributeError:
217220
raise HookMissing()
218221
else:
219-
return hook(wheel_directory, config_settings, metadata_directory)
222+
return hook(
223+
wheel_directory, scheme, config_settings, metadata_directory
224+
)
220225

221226

222227
def get_requires_for_build_sdist(config_settings):

src/pip/_vendor/pep517/wrappers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ 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
@@ -210,6 +210,7 @@ def build_wheel_for_editable(
210210
metadata_directory = abspath(metadata_directory)
211211
return self._call_hook('build_wheel_for_editable', {
212212
'wheel_directory': abspath(wheel_directory),
213+
'scheme': scheme,
213214
'config_settings': config_settings,
214215
'metadata_directory': metadata_directory,
215216
})

0 commit comments

Comments
 (0)