summaryrefslogtreecommitdiff
path: root/Lib/pkgutil.py
diff options
context:
space:
mode:
authorEric V. Smith <eric@trueblade.com>2012-05-24 20:21:04 -0400
committerEric V. Smith <eric@trueblade.com>2012-05-24 20:21:04 -0400
commitc6d213b38f0c5dbe4e347481f4a6896417ee9b97 (patch)
tree96b8931e68d4cf0fd61b464d8098b3001bd48d5a /Lib/pkgutil.py
parent56f56b04e98301a3bd96eeeb22d251bfd925f60d (diff)
downloadcpython-c6d213b38f0c5dbe4e347481f4a6896417ee9b97.tar.gz
issue 14660: Implement PEP 420, namespace packages.
Diffstat (limited to 'Lib/pkgutil.py')
-rw-r--r--Lib/pkgutil.py26
1 files changed, 18 insertions, 8 deletions
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index 8e062a4cd9..c5b0c4df9a 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -515,19 +515,29 @@ def extend_path(path, name):
pname = os.path.join(*name.split('.')) # Reconstitute as relative path
sname_pkg = name + ".pkg"
- init_py = "__init__.py"
path = path[:] # Start with a copy of the existing path
for dir in sys.path:
- if not isinstance(dir, str) or not os.path.isdir(dir):
+ if not isinstance(dir, str):
continue
- subdir = os.path.join(dir, pname)
- # XXX This may still add duplicate entries to path on
- # case-insensitive filesystems
- initfile = os.path.join(subdir, init_py)
- if subdir not in path and os.path.isfile(initfile):
- path.append(subdir)
+
+ finder = get_importer(dir)
+ if finder is not None:
+ # Is this finder PEP 420 compliant?
+ if hasattr(finder, 'find_loader'):
+ loader, portions = finder.find_loader(name)
+ else:
+ # No, no need to call it
+ loader = None
+ portions = []
+
+ for portion in portions:
+ # XXX This may still add duplicate entries to path on
+ # case-insensitive filesystems
+ if portion not in path:
+ path.append(portion)
+
# XXX Is this the right thing for subpackages like zope.app?
# It looks for a file named "zope.app.pkg"
pkgfile = os.path.join(dir, sname_pkg)