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 stub-only partial namespace packages not recognized as packages #221

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
3 changes: 1 addition & 2 deletions src/poetry/core/masonry/utils/package_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def is_stub_only(self) -> bool:
# returns `True` if this a PEP 561 stub-only package,
# see [PEP 561](https://www.python.org/dev/peps/pep-0561/#stub-only-packages)
return (self.package or "").endswith("-stubs") and all(
el.suffix == ".pyi"
or (el.parent.name == self.package and el.name == "py.typed")
el.suffix == ".pyi" or el.name == "py.typed"
for el in self.elements
if el.is_file()
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Example module"""
from typing import Tuple

version_info = Tuple[int, int, int]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
partial
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.poetry]
name = "pep-561-stubs"
version = "0.1"
description = "PEP 561 stub namespace package example with the py.typed marker file"
authors = [
"Henrik Bruåsdal <henrik.bruasdal@gmail.com>"
]
license = "MIT"
packages = [
{include = "pkg-stubs"}
]

[tool.poetry.dependencies]
python = "^3.6"
14 changes: 14 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ def test_wheel_package_pep_561_stub_only(package: str) -> None:
assert "pkg-stubs/subpkg/__init__.pyi" in z.namelist()


def test_wheel_package_pep_561_stub_only_partial_namespace() -> None:
root = fixtures_dir / "pep_561_stub_only_partial_namespace"
WheelBuilder.make(Factory().create_poetry(root))

whl = root / "dist" / "pep_561_stubs-0.1-py3-none-any.whl"

assert whl.exists()

with zipfile.ZipFile(str(whl)) as z:
assert "pkg-stubs/module.pyi" in z.namelist()
assert "pkg-stubs/subpkg/__init__.pyi" in z.namelist()
assert "pkg-stubs/subpkg/py.typed" in z.namelist()


def test_wheel_package_pep_561_stub_only_includes_typed_marker() -> None:
root = fixtures_dir / "pep_561_stub_only_partial"
WheelBuilder.make(Factory().create_poetry(root))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Example module"""
from typing import Tuple

version_info = Tuple[int, int, int]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
partial
13 changes: 13 additions & 0 deletions tests/masonry/utils/test_package_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ def test_pep_561_stub_only_package_good_name_suffix() -> None:
]


def test_pep_561_stub_only_partial_namespace_package_good_name_suffix() -> None:
pkg_include = PackageInclude(
base=fixtures_dir / "pep_561_stub_only_partial_namespace", include="good-stubs"
)
assert pkg_include.elements == [
fixtures_dir / "pep_561_stub_only_partial_namespace/good-stubs/module.pyi",
fixtures_dir / "pep_561_stub_only_partial_namespace/good-stubs/subpkg/",
fixtures_dir
/ "pep_561_stub_only_partial_namespace/good-stubs/subpkg/__init__.pyi",
fixtures_dir / "pep_561_stub_only_partial_namespace/good-stubs/subpkg/py.typed",
]


def test_pep_561_stub_only_package_bad_name_suffix() -> None:
with pytest.raises(ValueError) as e:
PackageInclude(base=fixtures_dir / "pep_561_stub_only", include="bad")
Expand Down