Skip to content

Commit

Permalink
fix #97 introduce find_packages_ns() for also finding PEP420 namespac…
Browse files Browse the repository at this point in the history
…e packages
  • Loading branch information
silkentrance committed Apr 14, 2018
1 parent 7d56dc1 commit 6dd982b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
16 changes: 14 additions & 2 deletions 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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
28 changes: 19 additions & 9 deletions setuptools/tests/test_find_packages.py
Expand Up @@ -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.xfail(sys.version_info < (3,3), reason="Test runs on Python >= 3.3 only")

# modeled after CPython's test.support.can_symlink

Expand Down Expand Up @@ -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'])

0 comments on commit 6dd982b

Please sign in to comment.