Skip to content

Commit

Permalink
ensure setup.py editable builds do not use pep517
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
abn committed May 11, 2022
1 parent 2e6ae2a commit d512a2a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/poetry/utils/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def pip_install(
# lot of packages.
args = ["install", "--disable-pip-version-check", "--prefix", str(environment.path)]

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

if upgrade:
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/extended_project/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import annotations

from pathlib import Path
from typing import Any


def build(setup_kwargs: dict[str, Any]):
assert setup_kwargs["name"] == "extended-project"
assert setup_kwargs["version"] == "1.2.3"

dynamic_module = Path(__file__).parent / "extended_project" / "built.py"
dynamic_module.write_text("# Generated by build.py")
6 changes: 4 additions & 2 deletions tests/fixtures/extended_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules"
]

build = "build.py"
[tool.poetry.build]
script = "build.py"
generate-setup-file = true

# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.4"
python = "^3.7"
38 changes: 38 additions & 0 deletions tests/masonry/builders/test_editable_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@

from poetry.factory import Factory
from poetry.masonry.builders.editable import EditableBuilder
from poetry.repositories.installed_repository import InstalledRepository
from poetry.utils.env import EnvCommandError
from poetry.utils.env import EnvManager
from poetry.utils.env import MockEnv
from poetry.utils.env import VirtualEnv
from poetry.utils.env import ephemeral_environment


if TYPE_CHECKING:
Expand Down Expand Up @@ -203,6 +206,41 @@ def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts(
assert [] == env.executed


def test_builder_setup_generation_runs_with_pip_editable(tmp_dir: str):
# create an isolated copy of the project
fixture = Path(__file__).parent.parent.parent / "fixtures" / "extended_project"
extended_project = Path(tmp_dir) / "extended_project"

shutil.copytree(fixture, extended_project)
assert extended_project.exists()

poetry = Factory().create_poetry(extended_project)

# we need a venv with setuptools since we are verifying setup.py builds
with ephemeral_environment(flags={"no-setuptools": False}) as venv:
builder = EditableBuilder(poetry, venv, NullIO())
builder.build()

# is the package installed?
repository = InstalledRepository.load(venv)
assert repository.package("extended-project", "1.2.3")

# check for the module built by build.py
try:
output = venv.run_python_script(
"from extended_project import built; print(built.__file__)"
).strip()
except EnvCommandError:
pytest.fail("Unable to import built module")
else:
built_py = Path(output).resolve()

expected = extended_project / "extended_project" / "built.py"

# ensure the package was installed as editable
assert built_py == expected.resolve()


def test_builder_installs_proper_files_when_packages_configured(
project_with_include: Poetry, tmp_venv: VirtualEnv
):
Expand Down

0 comments on commit d512a2a

Please sign in to comment.