summaryrefslogtreecommitdiff
path: root/pkg_resources/__init__.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2016-01-16 17:04:13 -0500
committerJason R. Coombs <jaraco@jaraco.com>2016-01-16 17:04:13 -0500
commit8a304f31a541944339fed6fe931dd5024d3f0897 (patch)
treec8bb161ac6503c06b948f787c244c25e11c9e242 /pkg_resources/__init__.py
parent70697b3a8c795a25de56a30d41cca76ad18d78fb (diff)
parentebc54982b1085b05054a75dbcdd16008ac20a60e (diff)
downloadpython-setuptools-git-8a304f31a541944339fed6fe931dd5024d3f0897.tar.gz
Merged in embray/setuptools (pull request #167)
Possible fix for #207
Diffstat (limited to 'pkg_resources/__init__.py')
-rw-r--r--pkg_resources/__init__.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index 8382571e..50b86cdb 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -755,7 +755,7 @@ class WorkingSet(object):
will be called.
"""
if insert:
- dist.insert_on(self.entries, entry)
+ dist.insert_on(self.entries, entry, replace=replace)
if entry is None:
entry = dist.location
@@ -2182,9 +2182,17 @@ def _handle_ns(packageName, path_item):
path = module.__path__
path.append(subpath)
loader.load_module(packageName)
- for path_item in path:
- if path_item not in module.__path__:
- module.__path__.append(path_item)
+
+ # Rebuild mod.__path__ ensuring that all entries are ordered
+ # corresponding to their sys.path order
+ sys_path= [(p and _normalize_cached(p) or p) for p in sys.path]
+ def sort_key(p):
+ parts = p.split(os.sep)
+ parts = parts[:-(packageName.count('.') + 1)]
+ return sys_path.index(_normalize_cached(os.sep.join(parts)))
+
+ path.sort(key=sort_key)
+ module.__path__[:] = [_normalize_cached(p) for p in path]
return subpath
def declare_namespace(packageName):
@@ -2639,7 +2647,7 @@ class Distribution(object):
"""Ensure distribution is importable on `path` (default=sys.path)"""
if path is None:
path = sys.path
- self.insert_on(path)
+ self.insert_on(path, replace=True)
if path is sys.path:
fixup_namespace_packages(self.location)
for pkg in self._get_metadata('namespace_packages.txt'):
@@ -2716,7 +2724,7 @@ class Distribution(object):
"""Return the EntryPoint object for `group`+`name`, or ``None``"""
return self.get_entry_map(group).get(name)
- def insert_on(self, path, loc = None):
+ def insert_on(self, path, loc=None, replace=False):
"""Insert self.location in path before its nearest parent directory"""
loc = loc or self.location
@@ -2740,7 +2748,10 @@ class Distribution(object):
else:
if path is sys.path:
self.check_version_conflict()
- path.append(loc)
+ if replace:
+ path.insert(0, loc)
+ else:
+ path.append(loc)
return
# p is the spot where we found or inserted loc; now remove duplicates