Skip to content

Commit

Permalink
fix: exclude subpackage from setup.py if __init__.py is excluded
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Nov 24, 2019
1 parent c77b442 commit d66f799
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion poetry/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ def find_nearest_pkg(rel_path):
if from_top_level == ".":
continue

is_subpkg = "__init__.py" in filenames
is_subpkg = "__init__.py" in filenames and not self.is_excluded(
Path(path, "__init__.py").relative_to(self._path)
)
if is_subpkg:
subpkg_paths.add(from_top_level)
parts = from_top_level.split(os.sep)
Expand Down
15 changes: 15 additions & 0 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,18 @@ def test_proper_python_requires_if_three_digits_precision_version_specified():
parsed = p.parsestr(to_str(pkg_info))

assert parsed["Requires-Python"] == "==2.7.15"


def test_excluded_subpackage():
poetry = Factory().create_poetry(project("excluded_subpackage"))

builder = SdistBuilder(poetry, NullEnv(), NullIO())
setup = builder.build_setup()

setup_ast = ast.parse(setup)

setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
ns = {}
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)

assert ns["packages"] == ["example"]

0 comments on commit d66f799

Please sign in to comment.