Skip to content

Commit

Permalink
Fix stub-only partial namespace packages
Browse files Browse the repository at this point in the history
  • Loading branch information
henribru committed May 6, 2022
1 parent 435adc7 commit 6bbcde5
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 2 deletions.
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 <[email protected]>"
]
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
14 changes: 14 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,20 @@ 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"
)
print(pkg_include.elements)
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

0 comments on commit 6bbcde5

Please sign in to comment.