Skip to content
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
2 changes: 2 additions & 0 deletions data/test_typeshed/stubs/nspkg/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "0.1"
requires = []
Empty file.
Empty file.
6 changes: 4 additions & 2 deletions scripts/build_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ def __init__(self, typeshed_dir: str, distribution: str) -> None:
self.distribution = distribution
self._base_dir = os.path.join(typeshed_dir, THIRD_PARTY_NAMESPACE, distribution)
# Python 3 (and mixed Python 2 and 3) stubs exist if at least one
# *.pyi file exists on the top-level or one level down, *excluding*
# the @python2 directory.
# *.pyi file exists on the top-level or in subdirectories, *excluding*
# the @python2 directory. May be more than one level down in the case
# of namespace packages (which lack __init__.pyi or any pyi files)
self.py3_stubs = (
len(glob(f"{self._base_dir}/*.pyi")) >= 1
or len(glob(f"{self._base_dir}/[!@]*/*.pyi")) >= 1
or len(glob(f"{self._base_dir}/[!@]*/**/*.pyi")) >= 1
)
# Python 2 stubs exist if a @python2 directory exists.
self.py2_stubs = PY2_NAMESPACE in os.listdir(self._base_dir)
Expand Down
25 changes: 23 additions & 2 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
sort_by_dependency,
transitive_deps,
strip_types_prefix,
BuildData,
SUFFIX,
PY2_SUFFIX,
)
Expand Down Expand Up @@ -97,7 +98,7 @@ def test_sort_by_dependency() -> None:


def test_collect_setup_entries() -> None:
stubs = os.path.join("data", "test_typeshed_stubs")
stubs = os.path.join("data", "test_typeshed", "stubs")
entries = collect_setup_entries(os.path.join(stubs, "singlefilepkg"), SUFFIX)
assert entries == ({"singlefilepkg-stubs": ["__init__.pyi", "METADATA.toml"]})

Expand All @@ -121,9 +122,29 @@ def test_collect_setup_entries() -> None:
}
)

entries = collect_setup_entries(os.path.join(stubs, "nspkg"), SUFFIX)
assert entries == (
{
"nspkg-stubs": [
"innerpkg/__init__.pyi",
"METADATA.toml",
]
}
)


def test_build_data() -> None:
typeshed = os.path.join("data", "test_typeshed")
singlefilepkg_bd = BuildData(typeshed, "singlefilepkg")
assert singlefilepkg_bd.py3_stubs
assert not singlefilepkg_bd.py2_stubs
nspkg_bd = BuildData(typeshed, "nspkg")
assert nspkg_bd.py3_stubs
assert not nspkg_bd.py2_stubs


def test_collect_setup_entries_bogusfile() -> None:
stubs = os.path.join("data", "test_typeshed_stubs")
stubs = os.path.join("data", "test_typeshed", "stubs")
with pytest.raises(ValueError, match="Only stub files are allowed: bogusfile.txt"):
collect_setup_entries(os.path.join(stubs, "bogusfiles"), SUFFIX)

Expand Down