diff options
author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-03-18 15:08:26 +0000 |
---|---|---|
committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-03-18 20:53:00 +0000 |
commit | 5e12f26fee168f2fe5168397757b54c433e6ff5d (patch) | |
tree | 137df8ed4bb1342be9f129d2ae0de434e4de6ca3 /setuptools/discovery.py | |
parent | fd66feb094cc9885265fecae4c7b37911e880702 (diff) | |
download | python-setuptools-git-5e12f26fee168f2fe5168397757b54c433e6ff5d.tar.gz |
Allow type stubs for FlatLayoutPackageFinder
Diffstat (limited to 'setuptools/discovery.py')
-rw-r--r-- | setuptools/discovery.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/setuptools/discovery.py b/setuptools/discovery.py index f15ebd6f..8c7f506c 100644 --- a/setuptools/discovery.py +++ b/setuptools/discovery.py @@ -131,7 +131,7 @@ class PackageFinder(_Finder): package = rel_path.replace(os.path.sep, '.') # Skip directory trees that are not valid packages - if '.' in dir or not cls._looks_like_package(full_path): + if '.' in dir or not cls._looks_like_package(full_path, package): continue # Should this package be included? @@ -143,14 +143,14 @@ class PackageFinder(_Finder): dirs.append(dir) @staticmethod - def _looks_like_package(path): + def _looks_like_package(path, _package_name): """Does a directory look like a package?""" return os.path.isfile(os.path.join(path, '__init__.py')) class PEP420PackageFinder(PackageFinder): @staticmethod - def _looks_like_package(path): + def _looks_like_package(path, _package_name): return True @@ -212,7 +212,14 @@ class FlatLayoutPackageFinder(PEP420PackageFinder): DEFAULT_EXCLUDE = tuple(chain_iter((p, f"{p}.*") for p in _EXCLUDE)) """Reserved package names""" - _looks_like_package = staticmethod(_valid_name) + @staticmethod + def _looks_like_package(path, package_name): + names = package_name.split('.') + return names and ( + # Consider PEP 561 + (names[0].isidentifier() or names[0].endswith("-stubs")) + and all(name.isidentifier() for name in names[1:]) + ) class FlatLayoutModuleFinder(ModuleFinder): |