Skip to content

Commit 4185b59

Browse files
authored
Merge pull request #809 from timheap/faster-package-finder-fix
Find nested packages with excluded parent
2 parents cf469bf + 2ecc8a4 commit 4185b59

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

setuptools/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,17 @@ def _find_packages_iter(cls, where, exclude, include):
7575
rel_path = os.path.relpath(full_path, where)
7676
package = rel_path.replace(os.path.sep, '.')
7777

78-
# Check if the directory is a package and passes the filters
79-
if ('.' not in dir
80-
and include(package)
81-
and not exclude(package)
82-
and cls._looks_like_package(full_path)):
78+
# Skip directory trees that are not valid packages
79+
if ('.' in dir or not cls._looks_like_package(full_path)):
80+
continue
81+
82+
# Should this package be included?
83+
if include(package) and not exclude(package):
8384
yield package
84-
dirs.append(dir)
85+
86+
# Keep searching subdirectories, as there may be more packages
87+
# down there, even if the parent was excluded.
88+
dirs.append(dir)
8589

8690
@staticmethod
8791
def _looks_like_package(path):

setuptools/tests/test_find_packages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ def test_exclude(self):
100100

101101
def test_exclude_recursive(self):
102102
"""
103-
Excluding a parent package should exclude all child packages as well.
103+
Excluding a parent package should not exclude child packages as well.
104104
"""
105105
self._touch('__init__.py', self.pkg_dir)
106106
self._touch('__init__.py', self.sub_pkg_dir)
107107
packages = find_packages(self.dist_dir, exclude=('pkg',))
108-
assert packages == []
108+
assert packages == ['pkg.subpkg']
109109

110110
def test_include_excludes_other(self):
111111
"""

0 commit comments

Comments
 (0)