Skip to content

Commit 457446d

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

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
v39.2.0
22
-------
33

4+
* #97: PEP 420: introduce find_packages_ns()
45
* #1359: Support using "file:" to load a PEP 440-compliant package version from
56
a text file.
67
* #1360: Fixed issue with a mismatch between the name of the package and the

docs/setuptools.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ Feature Highlights:
5959
* Create extensible applications and frameworks that automatically discover
6060
extensions, using simple "entry points" declared in a project's setup script.
6161

62+
* Full support for PEP 420 via ``find_packages_ns()``, which is also backwards
63+
compatible to the existing ``find_packages()``.
64+
6265
.. contents:: **Table of Contents**
6366

6467
.. _ez_setup.py: `bootstrap module`_
@@ -107,6 +110,19 @@ As you can see, it doesn't take much to use setuptools in a project.
107110
Run that script in your project folder, alongside the Python packages
108111
you have developed.
109112

113+
Note that instead of, and whenever you are using PEP 420 compliant implicit
114+
namespace packages, you can use ``find_packages_ns()``. But keep in
115+
mind that if you do, you might have to either define a few exclusions or
116+
reorganize your codebase a little bit so that the new function does not find
117+
for example your test fixtures and treat them as implicit namespace packages.
118+
119+
from setuptools import setup, find_packages_ns as find_packages
120+
setup(
121+
name="HelloWorld",
122+
version="0.1",
123+
packages=find_packages(),
124+
)
125+
110126
Invoke that script to produce eggs, upload to
111127
PyPI, and automatically include all packages in the directory where the
112128
setup.py lives. See the `Command Reference`_ section below to see what

setuptools/__init__.py

Lines changed: 5 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,13 @@
1718

1819
__metaclass__ = type
1920

21+
2022
__all__ = [
2123
'setup', 'Distribution', 'Feature', 'Command', 'Extension', 'Require',
22-
'find_packages',
24+
'find_packages', 'find_packages_ns'
2325
]
2426

27+
2528
__version__ = setuptools.version.__version__
2629

2730
bootstrap_install_from = None
@@ -110,6 +113,7 @@ def _looks_like_package(path):
110113

111114

112115
find_packages = PackageFinder.find
116+
find_packages_ns = PEP420PackageFinder.find
113117

114118

115119
def _install_setup_requires(attrs):

setuptools/tests/test_find_packages.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77

88
import pytest
99

10-
import setuptools
1110
from setuptools import find_packages
12-
13-
find_420_packages = setuptools.PEP420PackageFinder.find
11+
from setuptools import find_packages_ns
1412

1513
# modeled after CPython's test.support.can_symlink
1614

17-
1815
def can_symlink():
1916
TESTFN = tempfile.mktemp()
2017
symlink_path = TESTFN + "can_symlink"
@@ -154,29 +151,29 @@ def _assert_packages(self, actual, expected):
154151
assert set(actual) == set(expected)
155152

156153
def test_pep420_ns_package(self):
157-
packages = find_420_packages(
154+
packages = find_packages_ns(
158155
self.dist_dir, include=['pkg*'], exclude=['pkg.subpkg.assets'])
159156
self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg'])
160157

161158
def test_pep420_ns_package_no_includes(self):
162-
packages = find_420_packages(
159+
packages = find_packages_ns(
163160
self.dist_dir, exclude=['pkg.subpkg.assets'])
164161
self._assert_packages(packages, ['docs', 'pkg', 'pkg.nspkg', 'pkg.subpkg'])
165162

166163
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']
164+
packages = find_packages_ns(self.dist_dir)
165+
expected = ['docs', 'pkg', 'pkg.nspkg', 'pkg.subpkg', 'pkg.subpkg.assets']
170166
self._assert_packages(packages, expected)
171167

172168
def test_regular_package_with_nested_pep420_ns_packages(self):
173169
self._touch('__init__.py', self.pkg_dir)
174-
packages = find_420_packages(
170+
packages = find_packages_ns(
175171
self.dist_dir, exclude=['docs', 'pkg.subpkg.assets'])
176172
self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg'])
177173

178174
def test_pep420_ns_package_no_non_package_dirs(self):
179175
shutil.rmtree(self.docs_dir)
180176
shutil.rmtree(os.path.join(self.dist_dir, 'pkg/subpkg/assets'))
181-
packages = find_420_packages(self.dist_dir)
177+
packages = find_packages_ns(self.dist_dir)
182178
self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg'])
179+

0 commit comments

Comments
 (0)