summaryrefslogtreecommitdiff
path: root/setuptools/namespaces.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2016-10-23 09:36:11 -0400
committerJason R. Coombs <jaraco@jaraco.com>2016-10-23 09:36:11 -0400
commit11a55e9c6849f9215ddc714d2ae41d47c34d4f46 (patch)
tree4848d2ae505cbabce924aa673b9906826a1de9b1 /setuptools/namespaces.py
parentc50d4e37edb96b7e4d63101139591a007e5e7241 (diff)
downloadpython-setuptools-git-11a55e9c6849f9215ddc714d2ae41d47c34d4f46.tar.gz
Extract _pkg_names function and add test.
Diffstat (limited to 'setuptools/namespaces.py')
-rwxr-xr-xsetuptools/namespaces.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/setuptools/namespaces.py b/setuptools/namespaces.py
index 4248d1fc..6a766eda 100755
--- a/setuptools/namespaces.py
+++ b/setuptools/namespaces.py
@@ -1,9 +1,13 @@
import os
from distutils import log
+import itertools
from setuptools.extern.six.moves import map
+flatten = itertools.chain.from_iterable
+
+
class Installer:
def install_namespaces(self):
@@ -54,11 +58,20 @@ class Installer:
def _get_all_ns_packages(self):
"""Return sorted list of all package namespaces"""
- nsp = set()
pkgs = self.distribution.namespace_packages or []
- for pkg in pkgs:
- pkg = pkg.split('.')
- while pkg:
- nsp.add('.'.join(pkg))
- pkg.pop()
- return sorted(nsp)
+ return sorted(flatten(map(self._pkg_names, pkgs)))
+
+ @staticmethod
+ def _pkg_names(pkg):
+ """
+ Given a namespace package, yield the components of that
+ package.
+
+ >>> names = Installer._pkg_names('a.b.c')
+ >>> set(names) == set(['a', 'a.b', 'a.b.c'])
+ True
+ """
+ parts = pkg.split('.')
+ while parts:
+ yield '.'.join(parts)
+ parts.pop()