Commit 90af3a46 by finswimmer Committed by GitHub

fix: exclude subpackage from `setup.py` if `__init__.py` is excluded (#1009) (#1626)

* fix: exclude subpackage from `setup.py` if `__init__.py` is excluded

Fixes: #1009

* fix: added missing test data

* fix: lint test data

* change (sdist.git): exclude folders with no python file

* fix (sdist.git): make black happy
parent 607e70fc
......@@ -237,7 +237,15 @@ class SdistBuilder(Builder):
if from_top_level == ".":
continue
is_subpkg = any([filename.endswith(".py") for filename in filenames])
is_subpkg = any(
[filename.endswith(".py") for filename in filenames]
) and not all(
[
self.is_excluded(Path(path, filename).relative_to(self._path))
for filename in filenames
if filename.endswith(".py")
]
)
if is_subpkg:
subpkg_paths.add(from_top_level)
parts = from_top_level.split(os.sep)
......
My Package
==========
\ No newline at end of file
from .. import __version__
def test_version():
assert __version__ == "0.1.0"
[tool.poetry]
name = "example"
version = "0.1.0"
description = ""
authors = ["Sébastien Eustace <sebastien@eustace.io>"]
exclude = [
"**/test/**/*",
]
[tool.poetry.dependencies]
python = "^3.6"
[tool.poetry.dev-dependencies]
pytest = "^3.0"
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
......@@ -473,3 +473,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"]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment