Skip to content

Commit

Permalink
Make the editable builder execute build scripts if no setup.py genera…
Browse files Browse the repository at this point in the history
…tion (#2718)
  • Loading branch information
sdispater authored Jul 24, 2020
1 parent c2bab89 commit a2216ba
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
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.
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 <[email protected]>"
]
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

0 comments on commit a2216ba

Please sign in to comment.