1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Use pep517's new subprocess_runner API (#7111)

This commit is contained in:
Pradyun Gedam 2019-09-30 16:09:08 +05:30 committed by GitHub
commit 7d523f3219
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 47 deletions

View file

@ -6,6 +6,7 @@ import logging
from pip._internal.build_env import BuildEnvironment
from pip._internal.distributions.base import AbstractDistribution
from pip._internal.exceptions import InstallationError
from pip._internal.utils.subprocess import runner_with_spinner_message
logger = logging.getLogger(__name__)
@ -81,9 +82,13 @@ class SourceDistribution(AbstractDistribution):
# This must be done in a second pass, as the pyproject.toml
# dependencies must be installed before we can call the backend.
with self.req.build_env:
# We need to have the env active when calling the hook.
self.req.spin_message = "Getting requirements to build wheel"
reqs = self.req.pep517_backend.get_requires_for_build_wheel()
runner = runner_with_spinner_message(
"Getting requirements to build wheel"
)
backend = self.req.pep517_backend
with backend.subprocess_runner(runner):
reqs = backend.get_requires_for_build_wheel()
conflicting, missing = self.req.build_env.check_requirements(reqs)
if conflicting:
_raise_conflicts("the backend dependencies", conflicting)

View file

@ -49,16 +49,18 @@ from pip._internal.utils.misc import (
)
from pip._internal.utils.packaging import get_metadata
from pip._internal.utils.setuptools_build import make_setuptools_shim_args
from pip._internal.utils.subprocess import call_subprocess
from pip._internal.utils.subprocess import (
call_subprocess,
runner_with_spinner_message,
)
from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
from pip._internal.utils.ui import open_spinner
from pip._internal.utils.virtualenv import running_under_virtualenv
from pip._internal.vcs import vcs
if MYPY_CHECK_RUNNING:
from typing import (
Any, Dict, Iterable, List, Mapping, Optional, Sequence, Union,
Any, Dict, Iterable, List, Optional, Sequence, Union,
)
from pip._internal.build_env import BuildEnvironment
from pip._internal.cache import WheelCache
@ -547,26 +549,6 @@ class InstallRequirement(object):
self.unpacked_source_directory, backend
)
# Use a custom function to call subprocesses
self.spin_message = ""
def runner(
cmd, # type: List[str]
cwd=None, # type: Optional[str]
extra_environ=None # type: Optional[Mapping[str, Any]]
):
# type: (...) -> None
with open_spinner(self.spin_message) as spinner:
call_subprocess(
cmd,
cwd=cwd,
extra_environ=extra_environ,
spinner=spinner
)
self.spin_message = ""
self.pep517_backend._subprocess_runner = runner
def prepare_metadata(self):
# type: () -> None
"""Ensure that project metadata is available.
@ -622,11 +604,12 @@ class InstallRequirement(object):
# Note that Pep517HookCaller implements a fallback for
# prepare_metadata_for_build_wheel, so we don't have to
# consider the possibility that this hook doesn't exist.
runner = runner_with_spinner_message("Preparing wheel metadata")
backend = self.pep517_backend
self.spin_message = "Preparing wheel metadata"
distinfo_dir = backend.prepare_metadata_for_build_wheel(
metadata_dir
)
with backend.subprocess_runner(runner):
distinfo_dir = backend.prepare_metadata_for_build_wheel(
metadata_dir
)
return os.path.join(metadata_dir, distinfo_dir)
@ -951,15 +934,15 @@ class InstallRequirement(object):
install_args = self.get_install_args(
global_options, record_filename, root, prefix, pycompile,
)
msg = 'Running setup.py install for %s' % (self.name,)
with open_spinner(msg) as spinner:
with indent_log():
with self.build_env:
call_subprocess(
install_args + install_options,
cwd=self.unpacked_source_directory,
spinner=spinner,
)
runner = runner_with_spinner_message(
"Running setup.py install for {}".format(self.name)
)
with indent_log(), self.build_env:
runner(
cmd=install_args + install_options,
cwd=self.unpacked_source_directory,
)
if not os.path.exists(record_filename):
logger.debug('Record file %s not found', record_filename)

View file

@ -9,14 +9,13 @@ import logging
import logging.handlers
import os
import sys
from logging import Filter
from logging import Filter, getLogger
from pip._vendor.six import PY2
from pip._internal.utils.compat import WINDOWS
from pip._internal.utils.deprecation import DEPRECATION_MSG_PREFIX
from pip._internal.utils.misc import ensure_dir
from pip._internal.utils.subprocess import subprocess_logger
try:
import threading
@ -54,6 +53,7 @@ else:
_log_state = threading.local()
_log_state.indentation = 0
subprocess_logger = getLogger('pip.subprocessor')
class BrokenStdoutLoggingError(Exception):

View file

@ -11,17 +11,20 @@ from pip._vendor.six.moves import shlex_quote
from pip._internal.exceptions import InstallationError
from pip._internal.utils.compat import console_to_str, str_to_display
from pip._internal.utils.logging import subprocess_logger
from pip._internal.utils.misc import HiddenText, path_to_display
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
from pip._internal.utils.ui import open_spinner
if MYPY_CHECK_RUNNING:
from typing import Any, Iterable, List, Mapping, Optional, Text, Union
from typing import (
Any, Callable, Iterable, List, Mapping, Optional, Text, Union,
)
from pip._internal.utils.ui import SpinnerInterface
CommandArgs = List[Union[str, HiddenText]]
subprocess_logger = logging.getLogger('pip.subprocessor')
LOG_DIVIDER = '----------------------------------------'
@ -245,3 +248,28 @@ def call_subprocess(
raise ValueError('Invalid value: on_returncode=%s' %
repr(on_returncode))
return ''.join(all_output)
def runner_with_spinner_message(message):
# type: (str) -> Callable
"""Provide a subprocess_runner that shows a spinner message.
Intended for use with for pep517's Pep517HookCaller. Thus, the runner has
an API that matches what's expected by Pep517HookCaller.subprocess_runner.
"""
def runner(
cmd, # type: List[str]
cwd=None, # type: Optional[str]
extra_environ=None # type: Optional[Mapping[str, Any]]
):
# type: (...) -> None
with open_spinner(message) as spinner:
call_subprocess(
cmd,
cwd=cwd,
extra_environ=extra_environ,
spinner=spinner,
)
return runner

View file

@ -44,6 +44,7 @@ from pip._internal.utils.subprocess import (
LOG_DIVIDER,
call_subprocess,
format_command_args,
runner_with_spinner_message,
)
from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
@ -979,12 +980,17 @@ class WheelBuilder(object):
'--build-options is present' % (req.name,))
return None
try:
req.spin_message = 'Building wheel for %s (PEP 517)' % (req.name,)
logger.debug('Destination directory: %s', tempd)
wheel_name = req.pep517_backend.build_wheel(
tempd,
metadata_directory=req.metadata_directory
runner = runner_with_spinner_message(
'Building wheel for {} (PEP 517)'.format(req.name)
)
backend = req.pep517_backend
with backend.subprocess_runner(runner):
wheel_name = backend.build_wheel(
tempd,
metadata_directory=req.metadata_directory,
)
if python_tag:
# General PEP 517 backends don't necessarily support
# a "--python-tag" option, so we rename the wheel