From d51ba2d7a8850a7fb56a6572b372626dd1cd3631 Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Mon, 20 Jul 2015 16:35:49 +0100 Subject: Big performance fix for find_packages by ignoring hidden dirs earlier --- setuptools/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'setuptools') diff --git a/setuptools/__init__.py b/setuptools/__init__.py index 8188f125..f6536359 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -81,10 +81,20 @@ class PackageFinder(object): for dir in dirs: yield os.path.relpath(os.path.join(root, dir), base_path) + @staticmethod + def _suitable_dirs(base_path): + """ + Return all suitable package dirs in base_path, relative to base_path + """ + for root, dirs, files in os.walk(base_path, followlinks=True): + # Mutate dirs to trim the search: + dirs[:] = filterfalse(lambda n: '.' in n, dirs) + for dir in dirs: + yield os.path.relpath(os.path.join(root, dir), base_path) + @classmethod def _find_packages_iter(cls, base_path): - dirs = cls._all_dirs(base_path) - suitable = filterfalse(lambda n: '.' in n, dirs) + suitable = cls._suitable_dirs(base_path) return ( path.replace(os.path.sep, '.') for path in suitable -- cgit v1.2.3