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

fix subpackage check for setup.py generation #17

Merged
merged 1 commit into from
Apr 9, 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
10 changes: 9 additions & 1 deletion poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,15 @@ def find_nearest_pkg(rel_path):
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(
[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be extracted out to a different variable to make it easier to read? It took me a while to understand that this was checking that all of the Python files are not part of the excluded files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree; but I wanted to keep this at par with the fix we have already merged in poetry pr. That might be a seperate change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, makes sense. Then this PR looks good to go.

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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
My Package
==========
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .. import __version__


def test_version():
assert __version__ == "0.1.0"
18 changes: 18 additions & 0 deletions tests/masonry/builders/fixtures/excluded_subpackage/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = "example"
version = "0.1.0"
description = ""
authors = ["Sébastien Eustace <[email protected]>"]
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"
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)
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"]