summaryrefslogtreecommitdiff
path: root/Lib/pkgutil.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-07-09 21:23:58 +0200
committerAntoine Pitrou <solipsis@pitrou.net>2012-07-09 21:23:58 +0200
commitb2dd880e0a9e9936de92a508bcff28e253a04c8e (patch)
tree53581a495dac07d0a085738ca6a7ec86511d3fb0 /Lib/pkgutil.py
parent7df5e5858b846b9de6dd1148d13e105712c8b1e1 (diff)
downloadcpython-git-b2dd880e0a9e9936de92a508bcff28e253a04c8e.tar.gz
Issue #15294: Fix a regression in pkgutil.extend_path()'s handling of nested namespace packages.
Diffstat (limited to 'Lib/pkgutil.py')
-rw-r--r--Lib/pkgutil.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index c5b0c4df9a..59c99bfba4 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -513,12 +513,22 @@ def extend_path(path, name):
# frozen package. Return the path unchanged in that case.
return path
- pname = os.path.join(*name.split('.')) # Reconstitute as relative path
sname_pkg = name + ".pkg"
path = path[:] # Start with a copy of the existing path
- for dir in sys.path:
+ parent_package, _, final_name = name.rpartition('.')
+ if parent_package:
+ try:
+ search_path = sys.modules[parent_package].__path__
+ except (KeyError, AttributeError):
+ # We can't do anything: find_loader() returns None when
+ # passed a dotted name.
+ return path
+ else:
+ search_path = sys.path
+
+ for dir in search_path:
if not isinstance(dir, str):
continue
@@ -526,7 +536,7 @@ def extend_path(path, name):
if finder is not None:
# Is this finder PEP 420 compliant?
if hasattr(finder, 'find_loader'):
- loader, portions = finder.find_loader(name)
+ loader, portions = finder.find_loader(final_name)
else:
# No, no need to call it
loader = None