Skip to content

Commit

Permalink
Pass scheme to build_wheel_for_editable
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Jul 5, 2020
1 parent bb492a2 commit e37913c
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 6 deletions.
15 changes: 14 additions & 1 deletion src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
from pip._internal.cli.status_codes import ERROR, SUCCESS
from pip._internal.exceptions import CommandError, InstallationError
from pip._internal.locations import distutils_scheme
from pip._internal.locations import distutils_scheme, get_scheme
from pip._internal.operations.check import check_install_conflicts
from pip._internal.req import install_given_reqs
from pip._internal.req.req_tracker import get_requirement_tracker
Expand All @@ -46,6 +46,7 @@
from optparse import Values
from typing import Any, Iterable, List, Optional

from pip._internal.locations import Scheme
from pip._internal.models.format_control import FormatControl
from pip._internal.req.req_install import InstallRequirement
from pip._internal.wheel_builder import BinaryAllowedPredicate
Expand Down Expand Up @@ -351,12 +352,24 @@ def run(self, options, args):
)
]

def get_scheme_for_req(name):
# type: (str) -> Scheme
return get_scheme(
name,
user=options.use_user_site,
home=target_temp_dir_path,
root=options.root_path,
isolated=options.isolated_mode,
prefix=options.prefix_path,
)

_, build_failures = build(
reqs_to_build,
wheel_cache=wheel_cache,
build_options=[],
global_options=[],
allow_editable=True,
get_scheme_for_editable_req=get_scheme_for_req,
)

# If we're using PEP 517, we cannot do a direct install
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/commands/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def run(self, options, args):
build_options=options.build_options or [],
global_options=options.global_options or [],
allow_editable=False,
get_scheme_for_editable_req=None,
)
for req in build_successes:
assert req.link and req.link.is_wheel
Expand Down
4 changes: 3 additions & 1 deletion src/pip/_internal/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
from pip._internal.utils.virtualenv import running_under_virtualenv

if MYPY_CHECK_RUNNING:
from typing import Dict, List, Optional, Union
from typing import Callable, Dict, List, Optional, Union

from distutils.cmd import Command as DistutilsCommand

GetSchemePredicate = Callable[[str], Scheme]


# Application Directories
USER_CACHE_DIR = appdirs.user_cache_dir("pip")
Expand Down
14 changes: 14 additions & 0 deletions src/pip/_internal/models/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
For a general overview of available schemes and their context, see
https://docs.python.org/3/install/index.html#alternate-installation.
"""
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import Dict


class Scheme(object):
Expand All @@ -26,3 +30,13 @@ def __init__(
self.headers = headers
self.scripts = scripts
self.data = data

def as_dict(self):
# type: () -> Dict[str, str]
return dict(
platlib=self.platlib,
purelib=self.purelib,
headers=self.headers,
scripts=self.scripts,
data=self.data,
)
4 changes: 4 additions & 0 deletions src/pip/_internal/operations/build/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

if MYPY_CHECK_RUNNING:
from typing import List, Optional
from pip._internal.locations import Scheme
from pip._vendor.pep517.wrappers import Pep517HookCaller

logger = logging.getLogger(__name__)
Expand All @@ -20,6 +21,7 @@ def build_wheel_pep517(
build_options, # type: List[str]
tempd, # type: str
editable, # type: bool
scheme, # type: Optional[Scheme]
):
# type: (...) -> Optional[str]
"""Build one InstallRequirement using the PEP 517 build process.
Expand All @@ -40,9 +42,11 @@ def build_wheel_pep517(
)
with backend.subprocess_runner(runner):
if editable:
assert scheme
try:
wheel_name = backend.build_wheel_for_editable(
tempd,
scheme=scheme.as_dict(),
metadata_directory=metadata_directory,
)
except HookMissing:
Expand Down
14 changes: 13 additions & 1 deletion src/pip/_internal/wheel_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)

from pip._internal.cache import WheelCache
from pip._internal.locations import GetSchemePredicate, Scheme
from pip._internal.req.req_install import InstallRequirement

BinaryAllowedPredicate = Callable[[InstallRequirement], bool]
Expand Down Expand Up @@ -172,6 +173,7 @@ def _build_one(
build_options, # type: List[str]
global_options, # type: List[str]
editable, # type: bool
scheme, # type: Optional[Scheme]
):
# type: (...) -> Optional[str]
"""Build one wheel.
Expand All @@ -190,7 +192,7 @@ def _build_one(
# Install build deps into temporary directory (PEP 518)
with req.build_env:
return _build_one_inside_env(
req, output_dir, build_options, global_options, editable
req, output_dir, build_options, global_options, editable, scheme
)


Expand All @@ -200,6 +202,7 @@ def _build_one_inside_env(
build_options, # type: List[str]
global_options, # type: List[str]
editable, # type: bool
scheme, # type: Optional[Scheme]
):
# type: (...) -> Optional[str]
with TempDirectory(kind="wheel") as temp_dir:
Expand All @@ -213,6 +216,7 @@ def _build_one_inside_env(
build_options=build_options,
tempd=temp_dir.path,
editable=editable,
scheme=scheme,
)
else:
wheel_path = build_wheel_legacy(
Expand Down Expand Up @@ -269,13 +273,16 @@ def build(
build_options, # type: List[str]
global_options, # type: List[str]
allow_editable, # type: bool
get_scheme_for_editable_req, # type: Optional[GetSchemePredicate]
):
# type: (...) -> BuildResult
"""Build wheels.
:return: The list of InstallRequirement that succeeded to build and
the list of InstallRequirement that failed to build.
"""
assert allow_editable == bool(get_scheme_for_editable_req)

if not requirements:
return [], []

Expand All @@ -288,12 +295,17 @@ def build(
with indent_log():
build_successes, build_failures = [], []
for req in requirements:
assert req.name
cache_dir = _get_cache_dir(req, wheel_cache)
scheme = None
if get_scheme_for_editable_req:
scheme = get_scheme_for_editable_req(req.name)
wheel_file = _build_one(
req, cache_dir,
build_options,
global_options,
allow_editable and req.editable,
scheme=scheme,
)
if wheel_file:
# Update the link for this.
Expand Down
6 changes: 4 additions & 2 deletions src/pip/_vendor/pep517/_in_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def build_wheel(wheel_directory, config_settings, metadata_directory=None):


def build_wheel_for_editable(
wheel_directory, config_settings, metadata_directory=None
wheel_directory, scheme, config_settings, metadata_directory=None
):
"""Invoke the optional build_wheel_for_editable hook.
"""
Expand All @@ -216,7 +216,9 @@ def build_wheel_for_editable(
except AttributeError:
raise HookMissing()
else:
return hook(wheel_directory, config_settings, metadata_directory)
return hook(
wheel_directory, scheme, config_settings, metadata_directory
)


def get_requires_for_build_sdist(config_settings):
Expand Down
6 changes: 5 additions & 1 deletion src/pip/_vendor/pep517/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,20 @@ def build_wheel(
})

def build_wheel_for_editable(
self, wheel_directory, config_settings=None,
self, wheel_directory, scheme, config_settings=None,
metadata_directory=None):
"""Build a wheel for editable install from this project.
Returns the name of the newly created file.
'scheme' is a dictionary with the following keys:
'purelib', 'platlib', 'headers', 'scripts', 'data'.
"""
if metadata_directory is not None:
metadata_directory = abspath(metadata_directory)
return self._call_hook('build_wheel_for_editable', {
'wheel_directory': abspath(wheel_directory),
'scheme': scheme,
'config_settings': config_settings,
'metadata_directory': metadata_directory,
})
Expand Down

0 comments on commit e37913c

Please sign in to comment.