-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8212 from sbidoul/pep517-editable-sbi
PEP 660 (build_editable) support
- Loading branch information
Showing
16 changed files
with
526 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Support editable installs for projects that have a ``pyproject.toml`` and use a | ||
build backend that supports :pep:`660`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Metadata generation logic for source distributions. | ||
""" | ||
|
||
import os | ||
|
||
from pip._vendor.pep517.wrappers import Pep517HookCaller | ||
|
||
from pip._internal.build_env import BuildEnvironment | ||
from pip._internal.utils.subprocess import runner_with_spinner_message | ||
from pip._internal.utils.temp_dir import TempDirectory | ||
|
||
|
||
def generate_editable_metadata( | ||
build_env: BuildEnvironment, backend: Pep517HookCaller | ||
) -> str: | ||
"""Generate metadata using mechanisms described in PEP 660. | ||
Returns the generated metadata directory. | ||
""" | ||
metadata_tmpdir = TempDirectory(kind="modern-metadata", globally_managed=True) | ||
|
||
metadata_dir = metadata_tmpdir.path | ||
|
||
with build_env: | ||
# Note that Pep517HookCaller 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. | ||
runner = runner_with_spinner_message( | ||
"Preparing editable metadata (pyproject.toml)" | ||
) | ||
with backend.subprocess_runner(runner): | ||
distinfo_dir = backend.prepare_metadata_for_build_editable(metadata_dir) | ||
|
||
return os.path.join(metadata_dir, distinfo_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import logging | ||
import os | ||
from typing import Optional | ||
|
||
from pip._vendor.pep517.wrappers import HookMissing, Pep517HookCaller | ||
|
||
from pip._internal.utils.subprocess import runner_with_spinner_message | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def build_wheel_editable( | ||
name: str, | ||
backend: Pep517HookCaller, | ||
metadata_directory: str, | ||
tempd: str, | ||
) -> Optional[str]: | ||
"""Build one InstallRequirement using the PEP 660 build process. | ||
Returns path to wheel if successfully built. Otherwise, returns None. | ||
""" | ||
assert metadata_directory is not None | ||
try: | ||
logger.debug("Destination directory: %s", tempd) | ||
|
||
runner = runner_with_spinner_message( | ||
f"Building editable for {name} (pyproject.toml)" | ||
) | ||
with backend.subprocess_runner(runner): | ||
try: | ||
wheel_name = backend.build_editable( | ||
tempd, | ||
metadata_directory=metadata_directory, | ||
) | ||
except HookMissing as e: | ||
logger.error( | ||
"Cannot build editable %s because the build " | ||
"backend does not have the %s hook", | ||
name, | ||
e, | ||
) | ||
return None | ||
except Exception: | ||
logger.error("Failed building editable for %s", name) | ||
return None | ||
return os.path.join(tempd, wheel_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.