Skip to content

Commit

Permalink
Support build script in sub directory (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-leapyear authored May 2, 2022
1 parent f26e236 commit 16cb159
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def build_setup(self) -> bytes:

# If we have a build script, use it
if self._package.build_script:
import_name = self._package.build_script.split(".")[0]
import_name = ".".join(
Path(self._package.build_script).with_suffix("").parts
)
after += [f"from {import_name} import *", "build(setup_kwargs)"]

modules = []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.poetry]
name = "build_script_in_subdir"
version = "0.1"
description = "Some description."
authors = [
"Brandon Chinn <brandonchinn178@gmail.com>"
]
license = "MIT"
homepage = "https://python-poetry.org/"
packages = [
{ include = "*", from = "src" },
]

build = "scripts/build.py"
Empty file.
Empty file.
9 changes: 9 additions & 0 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ def test_with_c_extensions_src_layout() -> None:
assert "extended-0.1/src/extended/extended.c" in tar.getnames()


def test_with_build_script_in_subdir() -> None:
poetry = Factory().create_poetry(project("build_script_in_subdir"))

builder = SdistBuilder(poetry)
setup = builder.build_setup()
# should not error
ast.parse(setup)


def test_with_src_module_file() -> None:
poetry = Factory().create_poetry(project("source_file"))

Expand Down

0 comments on commit 16cb159

Please sign in to comment.