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 Oct 14, 2021
1 parent 1ad005f commit 49f853e
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 2 deletions.
3 changes: 1 addition & 2 deletions poetry/core/masonry/utils/package_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,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.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 @@ -205,6 +205,20 @@ def test_wheel_package_pep_561_stub_only(package):
assert "pkg-stubs/subpkg/__init__.pyi" in z.namelist()


def test_wheel_package_pep_561_stub_only_partial_namespace():
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():
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 @@ -63,6 +63,20 @@ def test_pep_561_stub_only_package_good_name_suffix():
]


def test_pep_561_stub_only_partial_namespace_package_good_name_suffix():
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():
with pytest.raises(ValueError) as e:
PackageInclude(base=fixtures_dir / "pep_561_stub_only", include="bad")
Expand Down

0 comments on commit 49f853e

Please sign in to comment.