From c87de03d89ca07416bb2e2c252c7721313e5d9ec Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 11 Apr 2014 00:45:04 -0400 Subject: Exclude children of excluded parents when doing package discovery. Fixes #184. --- CHANGES.txt | 7 +++++++ setuptools/__init__.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 512127b3..1c54ea5e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,13 @@ CHANGES ======= +----- +3.4.4 +----- + +* Issue #184: Correct failure where find_package over-matched packages + when directory traversal isn't short-circuited. + ----- 3.4.3 ----- diff --git a/setuptools/__init__.py b/setuptools/__init__.py index 6f588962..8d46b6dd 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -50,12 +50,29 @@ class PackageFinder(object): explicitly excluded packages are removed from it. """ out = cls._find_packages_iter(convert_path(where)) + out = cls.require_parents(out) includes = cls._build_filter(*include) excludes = cls._build_filter('ez_setup', '*__pycache__', *exclude) out = filter(includes, out) out = filterfalse(excludes, out) return list(out) + @staticmethod + def require_parents(packages): + """ + Exclude any apparent package that apparently doesn't include its + parent. + + For example, exclude 'foo.bar' if 'foo' is not present. + """ + found = [] + for pkg in packages: + base, sep, child = pkg.rpartition('.') + if base and base not in found: + continue + found.append(pkg) + yield pkg + @staticmethod def _all_dirs(base_path): """ -- cgit v1.2.3