diff --git a/setuptools/__init__.py b/setuptools/__init__.py index 7da47fbed5e..3085605fd94 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -1,6 +1,7 @@ """Extensions to the 'distutils' for large or complex distributions""" import os +import sys import functools import distutils.core import distutils.filelist @@ -15,11 +16,18 @@ from setuptools.depends import Require from . import monkey + +is_py33_upwards = sys.version_info >= (3,3) + __all__ = [ 'setup', 'Distribution', 'Feature', 'Command', 'Extension', 'Require', - 'find_packages', + 'find_packages' ] +if is_py33_upwards: + __all__.append('find_packages_ns') + + __version__ = setuptools.version.__version__ bootstrap_install_from = None @@ -107,7 +115,11 @@ def _looks_like_package(path): return True -find_packages = PackageFinder.find +find_packages = find_packages_std = PackageFinder.find + + +if is_py33_upwards: + find_packages_ns = PEP420PackageFinder.find def _install_setup_requires(attrs): diff --git a/setuptools/tests/test_find_packages.py b/setuptools/tests/test_find_packages.py index a6023de9d5a..088d444f53a 100644 --- a/setuptools/tests/test_find_packages.py +++ b/setuptools/tests/test_find_packages.py @@ -7,10 +7,15 @@ import pytest -import setuptools from setuptools import find_packages -find_420_packages = setuptools.PEP420PackageFinder.find +try: + from setuptools import find_packages_ns +except: + # just catch + pass + +py33_upwards = pytest.mark.skipif(sys.version_info < (3,3), reason="Test runs on Python >= 3.3 only") # modeled after CPython's test.support.can_symlink @@ -153,30 +158,35 @@ def test_symlinked_packages_are_included(self): def _assert_packages(self, actual, expected): assert set(actual) == set(expected) + @py33_upwards def test_pep420_ns_package(self): - packages = find_420_packages( + packages = find_packages_ns( self.dist_dir, include=['pkg*'], exclude=['pkg.subpkg.assets']) self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg']) + @py33_upwards def test_pep420_ns_package_no_includes(self): - packages = find_420_packages( + packages = find_packages_ns( self.dist_dir, exclude=['pkg.subpkg.assets']) self._assert_packages(packages, ['docs', 'pkg', 'pkg.nspkg', 'pkg.subpkg']) + @py33_upwards def test_pep420_ns_package_no_includes_or_excludes(self): - packages = find_420_packages(self.dist_dir) - expected = [ - 'docs', 'pkg', 'pkg.nspkg', 'pkg.subpkg', 'pkg.subpkg.assets'] + packages = find_packages_ns(self.dist_dir) + expected = ['docs', 'pkg', 'pkg.nspkg', 'pkg.subpkg', 'pkg.subpkg.assets'] self._assert_packages(packages, expected) + @py33_upwards def test_regular_package_with_nested_pep420_ns_packages(self): self._touch('__init__.py', self.pkg_dir) - packages = find_420_packages( + packages = find_packages_ns( self.dist_dir, exclude=['docs', 'pkg.subpkg.assets']) self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg']) + @py33_upwards def test_pep420_ns_package_no_non_package_dirs(self): shutil.rmtree(self.docs_dir) shutil.rmtree(os.path.join(self.dist_dir, 'pkg/subpkg/assets')) - packages = find_420_packages(self.dist_dir) + packages = find_packages_ns(self.dist_dir) self._assert_packages(packages, ['pkg', 'pkg.nspkg', 'pkg.subpkg']) +