Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

installer: fix PATH when building a dependency from source #8630

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/poetry/installation/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,8 @@ def _prepare(

with ephemeral_environment(self._env.python) as venv:
env = IsolatedEnv(venv, self._pool)
builder = ProjectBuilder(
directory,
python_executable=env.python_executable,
runner=quiet_subprocess_runner,
builder = ProjectBuilder.from_isolated_env(
env, directory, runner=quiet_subprocess_runner
)
env.install(builder.build_system_requires)

Expand Down
Empty file.
3 changes: 3 additions & 0 deletions tests/fixtures/project_with_setup_calls_script/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "<scripts>"]
build-backend = "setuptools.build_meta:__legacy__"
23 changes: 23 additions & 0 deletions tests/fixtures/project_with_setup_calls_script/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import annotations

import subprocess

from setuptools import setup

if subprocess.call(["exit-code"]) != 42:
raise RuntimeError("Wrong exit code.")

kwargs = dict(
name="project-with-setup-calls-script",
license="MIT",
version="0.1.2",
description="Demo project.",
author="Sébastien Eustace",
author_email="[email protected]",
url="https://github.com/demo/demo",
packages=["my_package"],
install_requires=["pendulum>=1.4.4", "cachy[msgpack]>=0.2.0"],
)


setup(**kwargs)
48 changes: 48 additions & 0 deletions tests/installation/test_chef.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
import shutil
import sys
import tempfile

Expand All @@ -10,6 +11,7 @@

import pytest

from build import ProjectBuilder
from poetry.core.packages.utils.link import Link

from poetry.factory import Factory
Expand Down Expand Up @@ -165,3 +167,49 @@ def test_prepare_directory_editable(

# cleanup generated tmp dir artifact
os.unlink(wheel)


@pytest.mark.network
def test_prepare_directory_script(
config: Config,
config_cache_dir: Path,
artifact_cache: ArtifactCache,
fixture_dir: FixtureDirGetter,
tmp_path: Path,
mocker: MockerFixture,
) -> None:
"""
Building a project that requires calling a script from its build_requires.
"""
# make sure the scripts project is on the same drive (for Windows tests in CI)
scripts_dir = tmp_path / "scripts"
shutil.copytree(fixture_dir("scripts"), scripts_dir)

orig_build_system_requires = ProjectBuilder.build_system_requires

class CustomPropertyMock:
def __get__(
self, obj: ProjectBuilder, obj_type: type[ProjectBuilder] | None = None
) -> set[str]:
assert isinstance(obj, ProjectBuilder)
return {
req.replace("<scripts>", f"scripts @ {scripts_dir.as_uri()}")
for req in orig_build_system_requires.fget(obj) # type: ignore[attr-defined]
}

mocker.patch(
"build.ProjectBuilder.build_system_requires",
new_callable=CustomPropertyMock,
)
chef = Chef(
artifact_cache, EnvManager.get_system_env(), Factory.create_pool(config)
)
archive = fixture_dir("project_with_setup_calls_script").resolve()

wheel = chef.prepare(archive)

assert wheel.name == "project_with_setup_calls_script-0.1.2-py3-none-any.whl"

assert wheel.parent.parent == Path(tempfile.gettempdir())
# cleanup generated tmp dir artifact
os.unlink(wheel)
Loading