Commit 2ecc8a44 authored by Tim Heap's avatar Tim Heap

Find nested packages with excluded parent

`find_packages(exclude=['pkg'])` should still find and include the
`pkg.subpkg` package.

Fixes #808
parent cf469bf2
...@@ -75,12 +75,16 @@ class PackageFinder(object): ...@@ -75,12 +75,16 @@ class PackageFinder(object):
rel_path = os.path.relpath(full_path, where) rel_path = os.path.relpath(full_path, where)
package = rel_path.replace(os.path.sep, '.') package = rel_path.replace(os.path.sep, '.')
# Check if the directory is a package and passes the filters # Skip directory trees that are not valid packages
if ('.' not in dir if ('.' in dir or not cls._looks_like_package(full_path)):
and include(package) continue
and not exclude(package)
and cls._looks_like_package(full_path)): # Should this package be included?
if include(package) and not exclude(package):
yield package yield package
# Keep searching subdirectories, as there may be more packages
# down there, even if the parent was excluded.
dirs.append(dir) dirs.append(dir)
@staticmethod @staticmethod
......
...@@ -100,12 +100,12 @@ class TestFindPackages: ...@@ -100,12 +100,12 @@ class TestFindPackages:
def test_exclude_recursive(self): 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.pkg_dir)
self._touch('__init__.py', self.sub_pkg_dir) self._touch('__init__.py', self.sub_pkg_dir)
packages = find_packages(self.dist_dir, exclude=('pkg',)) packages = find_packages(self.dist_dir, exclude=('pkg',))
assert packages == [] assert packages == ['pkg.subpkg']
def test_include_excludes_other(self): def test_include_excludes_other(self):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment