Skip to content

Commit dd7b1ee

Browse files
committed
Fix building packages with backend-path in pyproject.toml
Closes pypagh-6599
1 parent 3ff2513 commit dd7b1ee

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

news/6599.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix building packages which specify ``backend-path`` in pyproject.toml.

src/pip/_internal/pyproject.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def load_pyproject_toml(
3939
setup_py, # type: str
4040
req_name # type: str
4141
):
42-
# type: (...) -> Optional[Tuple[List[str], str, List[str]]]
42+
# type: (...) -> Optional[Tuple[List[str], str, List[str], List[str]]]
4343
"""Load the pyproject.toml file.
4444
4545
Parameters:
@@ -57,6 +57,8 @@ def load_pyproject_toml(
5757
name of PEP 517 backend,
5858
requirements we should check are installed after setting
5959
up the build environment
60+
directory paths to import the backend from (backend-path),
61+
relative to the project root.
6062
)
6163
"""
6264
has_pyproject = os.path.isfile(pyproject_toml)
@@ -167,6 +169,7 @@ def load_pyproject_toml(
167169
)
168170

169171
backend = build_system.get("build-backend")
172+
backend_path = build_system.get("backend-path", [])
170173
check = [] # type: List[str]
171174
if backend is None:
172175
# If the user didn't specify a backend, we assume they want to use
@@ -184,4 +187,4 @@ def load_pyproject_toml(
184187
backend = "setuptools.build_meta:__legacy__"
185188
check = ["setuptools>=40.8.0", "wheel"]
186189

187-
return (requires, backend, check)
190+
return (requires, backend, check, backend_path)

src/pip/_internal/req/req_install.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,11 @@ def load_pyproject_toml(self):
601601
return
602602

603603
self.use_pep517 = True
604-
requires, backend, check = pyproject_toml_data
604+
requires, backend, check, backend_path = pyproject_toml_data
605605
self.requirements_to_check = check
606606
self.pyproject_requires = requires
607607
self.pep517_backend = Pep517HookCaller(
608-
self.unpacked_source_directory, backend
608+
self.unpacked_source_directory, backend, backend_path=backend_path,
609609
)
610610

611611
def prepare_metadata(self):

tests/functional/test_pep517.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
from tests.lib import make_test_finder, path_to_url
77

88

9-
def make_project(tmpdir, requires=[], backend=None):
9+
def make_project(tmpdir, requires=[], backend=None, backend_path=[]):
1010
project_dir = tmpdir / 'project'
1111
project_dir.mkdir()
1212
buildsys = {'requires': requires}
1313
if backend:
1414
buildsys['build-backend'] = backend
15+
if backend_path:
16+
buildsys['backend-path'] = backend_path
1517
data = pytoml.dumps({'build-system': buildsys})
1618
project_dir.joinpath('pyproject.toml').write_text(data)
1719
return project_dir
@@ -32,6 +34,34 @@ def test_backend(tmpdir, data):
3234
assert req.pep517_backend.build_wheel("dir") == "Backend called"
3335

3436

37+
dummy_backend_code = """\
38+
def build_wheel(
39+
wheel_directory,
40+
config_settings=None,
41+
metadata_directory=None
42+
):
43+
return "Backend called"
44+
"""
45+
46+
47+
def test_backend_path(tmpdir, data):
48+
"""Check we can call a backend inside the project"""
49+
project_dir = make_project(
50+
tmpdir, backend="dummy_backend", backend_path=['.']
51+
)
52+
(project_dir / 'dummy_backend.py').write_text(dummy_backend_code)
53+
print(project_dir)
54+
import os
55+
print(os.listdir(project_dir))
56+
req = InstallRequirement(None, None, source_dir=project_dir)
57+
req.load_pyproject_toml()
58+
59+
env = BuildEnvironment()
60+
assert hasattr(req.pep517_backend, 'build_wheel')
61+
with env:
62+
assert req.pep517_backend.build_wheel("dir") == "Backend called"
63+
64+
3565
def test_pep517_install(script, tmpdir, data):
3666
"""Check we can build with a custom backend"""
3767
project_dir = make_project(

0 commit comments

Comments
 (0)