This commit is contained in:
Pradyun Gedam 2023-12-10 09:03:11 +00:00 committed by GitHub
commit e3381891ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 54 additions and 15 deletions

View File

@ -6,7 +6,10 @@ from pip._internal.distributions.base import AbstractDistribution
from pip._internal.exceptions import InstallationError
from pip._internal.index.package_finder import PackageFinder
from pip._internal.metadata import BaseDistribution
from pip._internal.utils.subprocess import runner_with_spinner_message
from pip._internal.utils.subprocess import (
log_backend_warnings,
runner_with_spinner_message,
)
logger = logging.getLogger(__name__)
@ -93,7 +96,7 @@ class SourceDistribution(AbstractDistribution):
)
def _get_build_requires_wheel(self) -> Iterable[str]:
with self.req.build_env:
with self.req.build_env, log_backend_warnings():
runner = runner_with_spinner_message("Getting requirements to build wheel")
backend = self.req.pep517_backend
assert backend is not None
@ -101,7 +104,7 @@ class SourceDistribution(AbstractDistribution):
return backend.get_requires_for_build_wheel()
def _get_build_requires_editable(self) -> Iterable[str]:
with self.req.build_env:
with self.req.build_env, log_backend_warnings():
runner = runner_with_spinner_message(
"Getting requirements to build editable"
)

View File

@ -10,7 +10,10 @@ from pip._internal.exceptions import (
InstallationSubprocessError,
MetadataGenerationFailed,
)
from pip._internal.utils.subprocess import runner_with_spinner_message
from pip._internal.utils.subprocess import (
log_backend_warnings,
runner_with_spinner_message,
)
from pip._internal.utils.temp_dir import TempDirectory
@ -25,7 +28,7 @@ def generate_metadata(
metadata_dir = metadata_tmpdir.path
with build_env:
with build_env, log_backend_warnings():
# Note that BuildBackendHookCaller implements a fallback for
# prepare_metadata_for_build_wheel, so we don't have to
# consider the possibility that this hook doesn't exist.

View File

@ -10,7 +10,10 @@ from pip._internal.exceptions import (
InstallationSubprocessError,
MetadataGenerationFailed,
)
from pip._internal.utils.subprocess import runner_with_spinner_message
from pip._internal.utils.subprocess import (
log_backend_warnings,
runner_with_spinner_message,
)
from pip._internal.utils.temp_dir import TempDirectory
@ -25,7 +28,7 @@ def generate_editable_metadata(
metadata_dir = metadata_tmpdir.path
with build_env:
with build_env, log_backend_warnings():
# Note that BuildBackendHookCaller implements a fallback for
# prepare_metadata_for_build_wheel/editable, so we don't have to
# consider the possibility that this hook doesn't exist.

View File

@ -12,7 +12,7 @@ from pip._internal.exceptions import (
MetadataGenerationFailed,
)
from pip._internal.utils.setuptools_build import make_setuptools_egg_info_args
from pip._internal.utils.subprocess import call_subprocess
from pip._internal.utils.subprocess import call_subprocess, log_backend_warnings
from pip._internal.utils.temp_dir import TempDirectory
logger = logging.getLogger(__name__)
@ -58,7 +58,7 @@ def generate_metadata(
no_user_config=isolated,
)
with build_env:
with build_env, log_backend_warnings():
with open_spinner("Preparing metadata (setup.py)") as spinner:
try:
call_subprocess(

View File

@ -6,7 +6,7 @@ from typing import Optional, Sequence
from pip._internal.build_env import BuildEnvironment
from pip._internal.utils.logging import indent_log
from pip._internal.utils.setuptools_build import make_setuptools_develop_args
from pip._internal.utils.subprocess import call_subprocess
from pip._internal.utils.subprocess import call_subprocess, log_backend_warnings
logger = logging.getLogger(__name__)
@ -38,7 +38,7 @@ def install_editable(
)
with indent_log():
with build_env:
with build_env, log_backend_warnings():
call_subprocess(
args,
command_desc="python setup.py develop",

View File

@ -53,7 +53,10 @@ from pip._internal.utils.misc import (
redact_auth_from_url,
)
from pip._internal.utils.packaging import safe_extra
from pip._internal.utils.subprocess import runner_with_spinner_message
from pip._internal.utils.subprocess import (
log_backend_warnings,
runner_with_spinner_message,
)
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
from pip._internal.utils.unpacking import unpack_file
from pip._internal.utils.virtualenv import running_under_virtualenv
@ -239,7 +242,7 @@ class InstallRequirement:
if not self.use_pep517:
return False
assert self.pep517_backend
with self.build_env:
with self.build_env, log_backend_warnings():
runner = runner_with_spinner_message(
"Checking if build backend supports build_editable"
)

View File

@ -1,18 +1,24 @@
import contextlib
import logging
import os
import shlex
import subprocess
import warnings
from typing import (
TYPE_CHECKING,
Any,
Callable,
Generator,
Iterable,
List,
Mapping,
Optional,
TextIO,
Type,
Union,
)
from pip._vendor.pyproject_hooks import BuildBackendWarning
from pip._vendor.rich.markup import escape
from pip._internal.cli.spinners import SpinnerInterface, open_spinner
@ -258,3 +264,24 @@ def runner_with_spinner_message(message: str) -> Callable[..., None]:
)
return runner
@contextlib.contextmanager
def log_backend_warnings() -> Generator[None, None, None]:
def showwarning(
message: Warning | str,
category: Type[Warning],
filename: str,
lineno: int,
file: TextIO | None = None,
line: str | None = None,
) -> None:
if category == BuildBackendWarning:
subprocess_logger.warning(message)
try:
original_showwarning = warnings.showwarning
warnings.showwarning = showwarning
yield
finally:
warnings.showwarning = original_showwarning

View File

@ -22,7 +22,7 @@ from pip._internal.req.req_install import InstallRequirement
from pip._internal.utils.logging import indent_log
from pip._internal.utils.misc import ensure_dir, hash_file
from pip._internal.utils.setuptools_build import make_setuptools_clean_args
from pip._internal.utils.subprocess import call_subprocess
from pip._internal.utils.subprocess import call_subprocess, log_backend_warnings
from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.utils.urls import path_to_url
from pip._internal.vcs import vcs
@ -189,7 +189,7 @@ def _build_one(
return None
# Install build deps into temporary directory (PEP 518)
with req.build_env:
with req.build_env, log_backend_warnings():
wheel_path = _build_one_inside_env(
req, output_dir, build_options, global_options, editable
)