mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Fix building packages with backend-path in pyproject.toml
Closes gh-6599
This commit is contained in:
parent
3ff2513537
commit
dd7b1ee5c3
4 changed files with 39 additions and 5 deletions
1
news/6599.bugfix
Normal file
1
news/6599.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Fix building packages which specify ``backend-path`` in pyproject.toml.
|
|
@ -39,7 +39,7 @@ def load_pyproject_toml(
|
|||
setup_py, # type: str
|
||||
req_name # type: str
|
||||
):
|
||||
# type: (...) -> Optional[Tuple[List[str], str, List[str]]]
|
||||
# type: (...) -> Optional[Tuple[List[str], str, List[str], List[str]]]
|
||||
"""Load the pyproject.toml file.
|
||||
|
||||
Parameters:
|
||||
|
@ -57,6 +57,8 @@ def load_pyproject_toml(
|
|||
name of PEP 517 backend,
|
||||
requirements we should check are installed after setting
|
||||
up the build environment
|
||||
directory paths to import the backend from (backend-path),
|
||||
relative to the project root.
|
||||
)
|
||||
"""
|
||||
has_pyproject = os.path.isfile(pyproject_toml)
|
||||
|
@ -167,6 +169,7 @@ def load_pyproject_toml(
|
|||
)
|
||||
|
||||
backend = build_system.get("build-backend")
|
||||
backend_path = build_system.get("backend-path", [])
|
||||
check = [] # type: List[str]
|
||||
if backend is None:
|
||||
# If the user didn't specify a backend, we assume they want to use
|
||||
|
@ -184,4 +187,4 @@ def load_pyproject_toml(
|
|||
backend = "setuptools.build_meta:__legacy__"
|
||||
check = ["setuptools>=40.8.0", "wheel"]
|
||||
|
||||
return (requires, backend, check)
|
||||
return (requires, backend, check, backend_path)
|
||||
|
|
|
@ -601,11 +601,11 @@ class InstallRequirement(object):
|
|||
return
|
||||
|
||||
self.use_pep517 = True
|
||||
requires, backend, check = pyproject_toml_data
|
||||
requires, backend, check, backend_path = pyproject_toml_data
|
||||
self.requirements_to_check = check
|
||||
self.pyproject_requires = requires
|
||||
self.pep517_backend = Pep517HookCaller(
|
||||
self.unpacked_source_directory, backend
|
||||
self.unpacked_source_directory, backend, backend_path=backend_path,
|
||||
)
|
||||
|
||||
def prepare_metadata(self):
|
||||
|
|
|
@ -6,12 +6,14 @@ from pip._internal.req import InstallRequirement
|
|||
from tests.lib import make_test_finder, path_to_url
|
||||
|
||||
|
||||
def make_project(tmpdir, requires=[], backend=None):
|
||||
def make_project(tmpdir, requires=[], backend=None, backend_path=[]):
|
||||
project_dir = tmpdir / 'project'
|
||||
project_dir.mkdir()
|
||||
buildsys = {'requires': requires}
|
||||
if backend:
|
||||
buildsys['build-backend'] = backend
|
||||
if backend_path:
|
||||
buildsys['backend-path'] = backend_path
|
||||
data = pytoml.dumps({'build-system': buildsys})
|
||||
project_dir.joinpath('pyproject.toml').write_text(data)
|
||||
return project_dir
|
||||
|
@ -32,6 +34,34 @@ def test_backend(tmpdir, data):
|
|||
assert req.pep517_backend.build_wheel("dir") == "Backend called"
|
||||
|
||||
|
||||
dummy_backend_code = """\
|
||||
def build_wheel(
|
||||
wheel_directory,
|
||||
config_settings=None,
|
||||
metadata_directory=None
|
||||
):
|
||||
return "Backend called"
|
||||
"""
|
||||
|
||||
|
||||
def test_backend_path(tmpdir, data):
|
||||
"""Check we can call a backend inside the project"""
|
||||
project_dir = make_project(
|
||||
tmpdir, backend="dummy_backend", backend_path=['.']
|
||||
)
|
||||
(project_dir / 'dummy_backend.py').write_text(dummy_backend_code)
|
||||
print(project_dir)
|
||||
import os
|
||||
print(os.listdir(project_dir))
|
||||
req = InstallRequirement(None, None, source_dir=project_dir)
|
||||
req.load_pyproject_toml()
|
||||
|
||||
env = BuildEnvironment()
|
||||
assert hasattr(req.pep517_backend, 'build_wheel')
|
||||
with env:
|
||||
assert req.pep517_backend.build_wheel("dir") == "Backend called"
|
||||
|
||||
|
||||
def test_pep517_install(script, tmpdir, data):
|
||||
"""Check we can build with a custom backend"""
|
||||
project_dir = make_project(
|
||||
|
|
Loading…
Reference in a new issue