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
7 changes: 7 additions & 0 deletions pycross/private/tools/inspect_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,13 @@ def read_file(path: str) -> Optional[str]:
declared.add(name)
return sorted(declared)

def _has_python(d: str) -> bool:
prefix = d + "/"
return any(f.startswith(prefix) and _extract_module_name(f.rsplit("/", 1)[1]) for f in all_files)

# An sdist's top-level dirs are only a guess at what the built wheel installs; a dir with
# no Python anywhere below it (.github/, requirements/, licenses/) can't be an import package.
top_level_dirs = {d for d in top_level_dirs if d.isidentifier() and _has_python(d)}
pkgs = _resolve_top_level_paths(all_files, top_level_dirs, read_file)
for f in root_files:
name = _extract_module_name(f)
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/inspect_package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,31 @@ def test_sdist_no_init_py(self):
result = inspect_sdist(sdist_path)
self.assertEqual(result["site_paths"], [])

def test_sdist_ignores_non_package_top_level_dirs(self):
"""Top-level sdist directories without Python modules (.github/, requirements/) are ignored."""
sdist_path = self._create_tarball_with_dirs(
"packaging-23.2.tar.gz",
{
"packaging-23.2/.github/workflows/x.yml": "name: ci\n",
"packaging-23.2/requirements/base.txt": "pytest\n",
"packaging-23.2/packaging/__init__.py": "",
},
)
result = inspect_sdist(sdist_path)
self.assertEqual(result["site_paths"], ["packaging"])

def test_sdist_namespace_keeps_data_files_when_python_present(self):
"""Data files inside a namespace directory that also contains Python modules are kept."""
sdist_path = self._create_tarball_with_dirs(
"ns-pkg-1.0.tar.gz",
{
"ns-pkg-1.0/myns/helper.py": "# module\n",
"ns-pkg-1.0/myns/py.typed": "",
},
)
result = inspect_sdist(sdist_path)
self.assertEqual(result["site_paths"], ["myns/helper.py", "myns/py.typed"])

def test_sdist_top_level_paths_pth(self):
sdist_path = self._create_tarball_with_dirs(
"rerun_sdk-1.0.tar.gz",
Expand Down
Loading