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

inspection: fix PATH when building a dependency to fetch metadata #8827

Merged
merged 2 commits into from
Dec 29, 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/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@
dest = '{dest}'

with build.env.DefaultIsolatedEnv() as env:
builder = build.ProjectBuilder(
source_dir=source,
python_executable=env.python_executable,
runner=pyproject_hooks.quiet_subprocess_runner,
builder = build.ProjectBuilder.from_isolated_env(
env, source, runner=pyproject_hooks.quiet_subprocess_runner
)
env.install(builder.build_system_requires)
env.install(builder.get_requires_for_build('wheel'))
Expand Down
36 changes: 36 additions & 0 deletions tests/inspection/test_info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import shutil

from subprocess import CalledProcessError
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -87,6 +89,33 @@ def demo_setup_complex_pep517_legacy(demo_setup_complex: Path) -> Path:
return demo_setup_complex


@pytest.fixture
def demo_setup_complex_calls_script(
fixture_dir: FixtureDirGetter, source_dir: Path, tmp_path: Path
) -> Path:
# 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)

pyproject = source_dir / "pyproject.toml"
pyproject.write_text(f"""\
[build-system]
requires = ["setuptools", "scripts @ {scripts_dir.as_uri()}"]
build-backend = "setuptools.build_meta:__legacy__"
""")

setup_py = source_dir / "setup.py"
setup_py.write_text("""\
import subprocess
from setuptools import setup
if subprocess.call(["exit-code"]) != 42:
raise RuntimeError("Wrong exit code.")
setup(name="demo", version="0.1.0", install_requires=[i for i in ["package"]])
""")

return source_dir


def demo_check_info(info: PackageInfo, requires_dist: set[str] | None = None) -> None:
assert info.name == "demo"
assert info.version == "0.1.0"
Expand Down Expand Up @@ -245,6 +274,13 @@ def test_info_setup_complex_disable_build(
assert info.requires_dist is None


@pytest.mark.network
def test_info_setup_complex_calls_script(demo_setup_complex_calls_script: Path) -> None:
"""Building the project requires calling a script from its build_requires."""
info = PackageInfo.from_directory(demo_setup_complex_calls_script)
demo_check_info(info, requires_dist={"package"})


@pytest.mark.network
@pytest.mark.parametrize("missing", ["version", "name", "install_requires"])
def test_info_setup_missing_mandatory_should_trigger_pep517(
Expand Down