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

Add support for build scripts without setup.py generation in the editable builder #2718

Merged
merged 1 commit into from
Jul 24, 2020
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
16 changes: 12 additions & 4 deletions poetry/masonry/builders/editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,24 @@ def build(self):
)

if self._package.build_script:
self._debug(
" - <warning>Falling back on using a <b>setup.py</b></warning>"
)
return self._setup_build()
if self._package.build_should_generate_setup():
self._debug(
" - <warning>Falling back on using a <b>setup.py</b></warning>"
)

return self._setup_build()

self._run_build_script(self._package.build_script)

added_files = []
added_files += self._add_pth()
added_files += self._add_scripts()
self._add_dist_info(added_files)

def _run_build_script(self, build_script):
self._debug(" - Executing build script: <b>{}</b>".format(build_script))
self._env.run("python", str(self._path.joinpath(build_script)), call=True)

def _setup_build(self):
builder = SdistBuilder(self._poetry)
setup = self._path / "setup.py"
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/extended_project_without_setup/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
My Package
==========
Empty file.
32 changes: 32 additions & 0 deletions tests/fixtures/extended_project_without_setup/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[tool.poetry]
name = "extended-project"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <sebastien@eustace.io>"
]
license = "MIT"

readme = "README.rst"

homepage = "https://python-poetry.org"
repository = "https://github.com/python-poetry/poetry"
documentation = "https://python-poetry.org/docs"

keywords = ["packaging", "dependency", "poetry"]

classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules"
]

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

# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.4"

[tool.poetry.scripts]
foo = "foo:bar"
22 changes: 22 additions & 0 deletions tests/masonry/builders/test_editable_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ def extended_poetry():
return poetry


@pytest.fixture()
def extended_without_setup_poetry():
poetry = Factory().create_poetry(
Path(__file__).parent.parent.parent
/ "fixtures"
/ "extended_project_without_setup"
)

return poetry


@pytest.fixture()
def env_manager(simple_poetry):
return EnvManager(simple_poetry)
Expand Down Expand Up @@ -194,3 +205,14 @@ def test_builder_installs_proper_files_when_packages_configured(

assert paths.issubset(expected)
assert len(paths) == len(expected)


def test_builder_should_execute_build_scripts(extended_without_setup_poetry):
env = MockEnv(path=Path("/foo"))
builder = EditableBuilder(extended_without_setup_poetry, env, NullIO())

builder.build()

assert [
["python", str(extended_without_setup_poetry.file.parent / "build.py")]
] == env.executed