From 5e12f26fee168f2fe5168397757b54c433e6ff5d Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Fri, 18 Mar 2022 15:08:26 +0000 Subject: Allow type stubs for FlatLayoutPackageFinder --- setuptools/discovery.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'setuptools/discovery.py') 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): -- cgit v1.2.1