diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2016-10-07 08:19:02 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-10-07 08:19:02 -0700 |
| commit | 4185b59aaf9772eb18d1f5681ecfaf52fd21a7f2 (patch) | |
| tree | 963b828fdbe11e50538395809f939064aa9d5d96 | |
| parent | cf469bf239cc6c0d4ebb766c5e2b6c6098e2b28b (diff) | |
| parent | 2ecc8a4428dbc75bdfd96681283c7235b120f4bd (diff) | |
| download | external_python_setuptools-4185b59aaf9772eb18d1f5681ecfaf52fd21a7f2.tar.gz external_python_setuptools-4185b59aaf9772eb18d1f5681ecfaf52fd21a7f2.tar.bz2 external_python_setuptools-4185b59aaf9772eb18d1f5681ecfaf52fd21a7f2.zip | |
Merge pull request #809 from timheap/faster-package-finder-fix
Find nested packages with excluded parent
| -rw-r--r-- | setuptools/__init__.py | 16 | ||||
| -rw-r--r-- | setuptools/tests/test_find_packages.py | 4 |
2 files changed, 12 insertions, 8 deletions
diff --git a/setuptools/__init__.py b/setuptools/__init__.py index 892626e6..baec3884 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -75,13 +75,17 @@ class PackageFinder(object): rel_path = os.path.relpath(full_path, where) package = rel_path.replace(os.path.sep, '.') - # Check if the directory is a package and passes the filters - if ('.' not in dir - and include(package) - and not exclude(package) - and cls._looks_like_package(full_path)): + # Skip directory trees that are not valid packages + if ('.' in dir or not cls._looks_like_package(full_path)): + continue + + # Should this package be included? + if include(package) and not exclude(package): yield package - dirs.append(dir) + + # Keep searching subdirectories, as there may be more packages + # down there, even if the parent was excluded. + dirs.append(dir) @staticmethod def _looks_like_package(path): diff --git a/setuptools/tests/test_find_packages.py b/setuptools/tests/test_find_packages.py index 9d31ccd7..6dc1b3ac 100644 --- a/setuptools/tests/test_find_packages.py +++ b/setuptools/tests/test_find_packages.py @@ -100,12 +100,12 @@ class TestFindPackages: def test_exclude_recursive(self): """ - Excluding a parent package should exclude all child packages as well. + Excluding a parent package should not exclude child packages as well. """ self._touch('__init__.py', self.pkg_dir) self._touch('__init__.py', self.sub_pkg_dir) packages = find_packages(self.dist_dir, exclude=('pkg',)) - assert packages == [] + assert packages == ['pkg.subpkg'] def test_include_excludes_other(self): """ |
