Skip to content

Commit a1d63f1

Browse files
abnneersighted
authored andcommitted
ensure setup.py editable builds do not use pep517
Prior to this change when Poetry builds a project with a setup.py file, as in the case when `generate-setup-file` was set to true, `pip` fallback was invoked with a PEP 517 isolated build causing it to fail. This was a regression in functionality from Poetry 1.1 build script usage. However, note that build script usage is an experimental feature.
1 parent 4387523 commit a1d63f1

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

src/poetry/utils/pip.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def pip_install(
3131
# lot of packages.
3232
args = ["install", "--disable-pip-version-check", "--prefix", str(environment.path)]
3333

34-
if not is_wheel:
34+
if not is_wheel and not editable:
3535
args.insert(1, "--use-pep517")
3636

3737
if upgrade:
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path
4+
from typing import Any
5+
6+
7+
def build(setup_kwargs: dict[str, Any]):
8+
assert setup_kwargs["name"] == "extended-project"
9+
assert setup_kwargs["version"] == "1.2.3"
10+
11+
dynamic_module = Path(__file__).parent / "extended_project" / "built.py"
12+
dynamic_module.write_text("# Generated by build.py")

tests/fixtures/extended_project/pyproject.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ classifiers = [
2020
"Topic :: Software Development :: Libraries :: Python Modules"
2121
]
2222

23-
build = "build.py"
23+
[tool.poetry.build]
24+
script = "build.py"
25+
generate-setup-file = true
2426

2527
# Requirements
2628
[tool.poetry.dependencies]
27-
python = "~2.7 || ^3.4"
29+
python = "^3.7"

tests/masonry/builders/test_editable_builder.py

+38
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212

1313
from poetry.factory import Factory
1414
from poetry.masonry.builders.editable import EditableBuilder
15+
from poetry.repositories.installed_repository import InstalledRepository
16+
from poetry.utils.env import EnvCommandError
1517
from poetry.utils.env import EnvManager
1618
from poetry.utils.env import MockEnv
1719
from poetry.utils.env import VirtualEnv
20+
from poetry.utils.env import ephemeral_environment
1821

1922

2023
if TYPE_CHECKING:
@@ -203,6 +206,41 @@ def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts(
203206
assert [] == env.executed
204207

205208

209+
def test_builder_setup_generation_runs_with_pip_editable(tmp_dir: str):
210+
# create an isolated copy of the project
211+
fixture = Path(__file__).parent.parent.parent / "fixtures" / "extended_project"
212+
extended_project = Path(tmp_dir) / "extended_project"
213+
214+
shutil.copytree(fixture, extended_project)
215+
assert extended_project.exists()
216+
217+
poetry = Factory().create_poetry(extended_project)
218+
219+
# we need a venv with setuptools since we are verifying setup.py builds
220+
with ephemeral_environment(flags={"no-setuptools": False}) as venv:
221+
builder = EditableBuilder(poetry, venv, NullIO())
222+
builder.build()
223+
224+
# is the package installed?
225+
repository = InstalledRepository.load(venv)
226+
assert repository.package("extended-project", "1.2.3")
227+
228+
# check for the module built by build.py
229+
try:
230+
output = venv.run_python_script(
231+
"from extended_project import built; print(built.__file__)"
232+
).strip()
233+
except EnvCommandError:
234+
pytest.fail("Unable to import built module")
235+
else:
236+
built_py = Path(output).resolve()
237+
238+
expected = extended_project / "extended_project" / "built.py"
239+
240+
# ensure the package was installed as editable
241+
assert built_py == expected.resolve()
242+
243+
206244
def test_builder_installs_proper_files_when_packages_configured(
207245
project_with_include: Poetry, tmp_venv: VirtualEnv
208246
):

0 commit comments

Comments
 (0)