Skip to content

Commit c6387b8

Browse files
authored
installer: fix PATH when building a dependency from source (#8630)
1 parent c425b85 commit c6387b8

File tree

5 files changed

+76
-4
lines changed

5 files changed

+76
-4
lines changed

Diff for: src/poetry/installation/chef.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,8 @@ def _prepare(
129129

130130
with ephemeral_environment(self._env.python) as venv:
131131
env = IsolatedEnv(venv, self._pool)
132-
builder = ProjectBuilder(
133-
directory,
134-
python_executable=env.python_executable,
135-
runner=quiet_subprocess_runner,
132+
builder = ProjectBuilder.from_isolated_env(
133+
env, directory, runner=quiet_subprocess_runner
136134
)
137135
env.install(builder.build_system_requires)
138136

Diff for: tests/fixtures/project_with_setup_calls_script/my_package/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools", "<scripts>"]
3+
build-backend = "setuptools.build_meta:__legacy__"
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from __future__ import annotations
2+
3+
import subprocess
4+
5+
from setuptools import setup
6+
7+
if subprocess.call(["exit-code"]) != 42:
8+
raise RuntimeError("Wrong exit code.")
9+
10+
kwargs = dict(
11+
name="project-with-setup-calls-script",
12+
license="MIT",
13+
version="0.1.2",
14+
description="Demo project.",
15+
author="Sébastien Eustace",
16+
author_email="[email protected]",
17+
url="https://github.com/demo/demo",
18+
packages=["my_package"],
19+
install_requires=["pendulum>=1.4.4", "cachy[msgpack]>=0.2.0"],
20+
)
21+
22+
23+
setup(**kwargs)

Diff for: tests/installation/test_chef.py

+48
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import os
4+
import shutil
45
import sys
56
import tempfile
67

@@ -10,6 +11,7 @@
1011

1112
import pytest
1213

14+
from build import ProjectBuilder
1315
from poetry.core.packages.utils.link import Link
1416

1517
from poetry.factory import Factory
@@ -165,3 +167,49 @@ def test_prepare_directory_editable(
165167

166168
# cleanup generated tmp dir artifact
167169
os.unlink(wheel)
170+
171+
172+
@pytest.mark.network
173+
def test_prepare_directory_script(
174+
config: Config,
175+
config_cache_dir: Path,
176+
artifact_cache: ArtifactCache,
177+
fixture_dir: FixtureDirGetter,
178+
tmp_path: Path,
179+
mocker: MockerFixture,
180+
) -> None:
181+
"""
182+
Building a project that requires calling a script from its build_requires.
183+
"""
184+
# make sure the scripts project is on the same drive (for Windows tests in CI)
185+
scripts_dir = tmp_path / "scripts"
186+
shutil.copytree(fixture_dir("scripts"), scripts_dir)
187+
188+
orig_build_system_requires = ProjectBuilder.build_system_requires
189+
190+
class CustomPropertyMock:
191+
def __get__(
192+
self, obj: ProjectBuilder, obj_type: type[ProjectBuilder] | None = None
193+
) -> set[str]:
194+
assert isinstance(obj, ProjectBuilder)
195+
return {
196+
req.replace("<scripts>", f"scripts @ {scripts_dir.as_uri()}")
197+
for req in orig_build_system_requires.fget(obj) # type: ignore[attr-defined]
198+
}
199+
200+
mocker.patch(
201+
"build.ProjectBuilder.build_system_requires",
202+
new_callable=CustomPropertyMock,
203+
)
204+
chef = Chef(
205+
artifact_cache, EnvManager.get_system_env(), Factory.create_pool(config)
206+
)
207+
archive = fixture_dir("project_with_setup_calls_script").resolve()
208+
209+
wheel = chef.prepare(archive)
210+
211+
assert wheel.name == "project_with_setup_calls_script-0.1.2-py3-none-any.whl"
212+
213+
assert wheel.parent.parent == Path(tempfile.gettempdir())
214+
# cleanup generated tmp dir artifact
215+
os.unlink(wheel)

0 commit comments

Comments
 (0)