Commit 11a55e9c authored by Jason R. Coombs's avatar Jason R. Coombs

Extract _pkg_names function and add test.

parent c50d4e37
import os import os
from distutils import log from distutils import log
import itertools
from setuptools.extern.six.moves import map from setuptools.extern.six.moves import map
flatten = itertools.chain.from_iterable
class Installer: class Installer:
def install_namespaces(self): def install_namespaces(self):
...@@ -54,11 +58,20 @@ class Installer: ...@@ -54,11 +58,20 @@ class Installer:
def _get_all_ns_packages(self): def _get_all_ns_packages(self):
"""Return sorted list of all package namespaces""" """Return sorted list of all package namespaces"""
nsp = set()
pkgs = self.distribution.namespace_packages or [] pkgs = self.distribution.namespace_packages or []
for pkg in pkgs: return sorted(flatten(map(self._pkg_names, pkgs)))
pkg = pkg.split('.')
while pkg: @staticmethod
nsp.add('.'.join(pkg)) def _pkg_names(pkg):
pkg.pop() """
return sorted(nsp) 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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment