Skip to content

Commit 02374ee

Browse files
committed
fix #97 introduce find_packages_ns() for also finding PEP420 namespace packages
1 parent 244ff32 commit 02374ee

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

setuptools/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Extensions to the 'distutils' for large or complex distributions"""
22

33
import os
4+
import sys
45
import functools
56
import distutils.core
67
import distutils.filelist
@@ -17,11 +18,17 @@
1718

1819
__metaclass__ = type
1920

21+
is_py33_upwards = sys.version_info >= (3,3)
22+
2023
__all__ = [
2124
'setup', 'Distribution', 'Feature', 'Command', 'Extension', 'Require',
22-
'find_packages',
25+
'find_packages'
2326
]
2427

28+
if is_py33_upwards:
29+
__all__.append('find_packages_ns')
30+
31+
2532
__version__ = setuptools.version.__version__
2633

2734
bootstrap_install_from = None
@@ -112,6 +119,10 @@ def _looks_like_package(path):
112119
find_packages = PackageFinder.find
113120

114121

122+
if is_py33_upwards:
123+
find_packages_ns = PEP420PackageFinder.find
124+
125+
115126
def _install_setup_requires(attrs):
116127
# Note: do not use `setuptools.Distribution` directly, as
117128
# our PEP 517 backend patch `distutils.core.Distribution`.

setuptools/tests/test_find_packages.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77

88
import pytest
99

10-
import setuptools
1110
from setuptools import find_packages
1211

13-
find_420_packages = setuptools.PEP420PackageFinder.find
12+
try:
13+
from setuptools import find_packages_ns
14+
except:
15+
# just catch
16+
pass
17+
18+
py33_upwards = pytest.mark.skipif(sys.version_info < (3,3), reason="Test runs on Python >= 3.3 only")
1419

1520
# modeled after CPython's test.support.can_symlink
1621

@@ -153,30 +158,35 @@ def test_symlinked_packages_are_included(self):
153158
def _assert_packages(self, actual, expected):
154159
assert set(actual) == set(expected)
155160

161+
@py33_upwards
156162
def test_pep420_ns_package(self):
157-
packages = find_420_packages(
163+
packages = find_packages_ns(
158164
self.dist_dir, include=['pkg*'], exclude=['pkg.subpkg.assets'])
159165
self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg'])
160166

167+
@py33_upwards
161168
def test_pep420_ns_package_no_includes(self):
162-
packages = find_420_packages(
169+
packages = find_packages_ns(
163170
self.dist_dir, exclude=['pkg.subpkg.assets'])
164171
self._assert_packages(packages, ['docs', 'pkg', 'pkg.nspkg', 'pkg.subpkg'])
165172

173+
@py33_upwards
166174
def test_pep420_ns_package_no_includes_or_excludes(self):
167-
packages = find_420_packages(self.dist_dir)
168-
expected = [
169-
'docs', 'pkg', 'pkg.nspkg', 'pkg.subpkg', 'pkg.subpkg.assets']
175+
packages = find_packages_ns(self.dist_dir)
176+
expected = ['docs', 'pkg', 'pkg.nspkg', 'pkg.subpkg', 'pkg.subpkg.assets']
170177
self._assert_packages(packages, expected)
171178

179+
@py33_upwards
172180
def test_regular_package_with_nested_pep420_ns_packages(self):
173181
self._touch('__init__.py', self.pkg_dir)
174-
packages = find_420_packages(
182+
packages = find_packages_ns(
175183
self.dist_dir, exclude=['docs', 'pkg.subpkg.assets'])
176184
self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg'])
177185

186+
@py33_upwards
178187
def test_pep420_ns_package_no_non_package_dirs(self):
179188
shutil.rmtree(self.docs_dir)
180189
shutil.rmtree(os.path.join(self.dist_dir, 'pkg/subpkg/assets'))
181-
packages = find_420_packages(self.dist_dir)
190+
packages = find_packages_ns(self.dist_dir)
182191
self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg'])
192+

0 commit comments

Comments
 (0)