summaryrefslogtreecommitdiffstats
path: root/Lib/pkgutil.py
diff options
context:
space:
mode:
authorEric V. Smith <eric@trueblade.com>2012-05-25 00:21:04 (GMT)
committerEric V. Smith <eric@trueblade.com>2012-05-25 00:21:04 (GMT)
commit984b11f88fcace98e30decc19bbf9e281355e607 (patch)
tree613a0fb564da71c5fc84e9343813f87619591732 /Lib/pkgutil.py
parentfa52cbd5e6210f257de40aab12d55d84d64bdb91 (diff)
downloadcpython-984b11f88fcace98e30decc19bbf9e281355e607.zip
cpython-984b11f88fcace98e30decc19bbf9e281355e607.tar.gz
cpython-984b11f88fcace98e30decc19bbf9e281355e607.tar.bz2
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 8e062a4..c5b0c4d 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)