Skip to content

Commit

Permalink
include the py.typed marker file if present without checking for content
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>
  • Loading branch information
hoefling committed Apr 22, 2020
1 parent 49b4cba commit 1503688
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 2 deletions.
5 changes: 4 additions & 1 deletion poetry/masonry/utils/package_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def stub_only(self): # type: () -> 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" for el in self.elements if el.is_file()
el.suffix == ".pyi"
or (el.parent.name == self.package and el.name == "py.typed")
for el in self.elements
if el.is_file()
)

@property
Expand Down
Empty file.
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
Empty file.
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 package example with the py.typed marker file"
authors = [
"Oleg Höfling <oleg.hoefling@gmail.com>"
]
license = "MIT"
packages = [
{include = "pkg-stubs"}
]

[tool.poetry.dependencies]
python = "^3.6"
17 changes: 16 additions & 1 deletion tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ def test_dist_info_file_permissions():
)


@pytest.mark.parametrize("package", ["pep_561_stub_only", "pep_561_stub_only_src"])
@pytest.mark.parametrize(
"package",
["pep_561_stub_only", "pep_561_stub_only_partial", "pep_561_stub_only_src"],
)
def test_wheel_package_pep_561_stub_only(package):
root = fixtures_dir / package
WheelBuilder.make(Factory().create_poetry(root), NullEnv(), NullIO())
Expand All @@ -177,3 +180,15 @@ def test_wheel_package_pep_561_stub_only(package):
assert "pkg-stubs/__init__.pyi" in z.namelist()
assert "pkg-stubs/module.pyi" in z.namelist()
assert "pkg-stubs/subpkg/__init__.pyi" 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), NullEnv(), NullIO())

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/py.typed" in z.namelist()

0 comments on commit 1503688

Please sign in to comment.