diff options
author | Min RK <benjaminrk@gmail.com> | 2016-07-27 13:35:44 +0200 |
---|---|---|
committer | Min RK <benjaminrk@gmail.com> | 2016-07-28 16:42:03 +0200 |
commit | 279e625938d7991755c0aeba63f4293d9b67fa0f (patch) | |
tree | cc2e17793032335c50a1eb1ba2dfd0d3cce09525 | |
parent | 93c69277ef3519239857263d8c996fce23335d38 (diff) | |
download | external_python_setuptools-279e625938d7991755c0aeba63f4293d9b67fa0f.tar.gz external_python_setuptools-279e625938d7991755c0aeba63f4293d9b67fa0f.tar.bz2 external_python_setuptools-279e625938d7991755c0aeba63f4293d9b67fa0f.zip |
only insert eggs ahead of parent if not already on path
in `insert_on(replace=False)`
and set `replace=False` by default in `activate()`
Fixes pkg_resources modifying sys.path for all eggs
with SETUPTOOLS_SYS_PATH_TECHINQUE=raw
-rw-r--r-- | pkg_resources/__init__.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 6337db99..602549be 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -2503,11 +2503,11 @@ class Distribution(object): for line in self.get_metadata_lines(name): yield line - def activate(self, path=None): + def activate(self, path=None, replace=False): """Ensure distribution is importable on `path` (default=sys.path)""" if path is None: path = sys.path - self.insert_on(path, replace=True) + self.insert_on(path, replace=replace) if path is sys.path: fixup_namespace_packages(self.location) for pkg in self._get_metadata('namespace_packages.txt'): @@ -2585,7 +2585,24 @@ class Distribution(object): return self.get_entry_map(group).get(name) def insert_on(self, path, loc=None, replace=False): - """Insert self.location in path before its nearest parent directory""" + """Ensure self.location is on path + + If replace=False (default): + - If location is already in path anywhere, do nothing. + - Else: + - If it's an egg and its parent directory is on path, + insert just ahead of the parent. + - Else: add to the end of path. + If replace=True: + - If location is already on path anywhere (not eggs) + or higher priority than its parent (eggs) + do nothing. + - Else: + - If it's an egg and its parent directory is on path, + insert just ahead of the parent, + removing any lower-priority entries. + - Else: add it to the front of path. + """ loc = loc or self.location if not loc: @@ -2600,6 +2617,9 @@ class Distribution(object): break elif item == bdir and self.precedence == EGG_DIST: # if it's an .egg, give it precedence over its directory + # UNLESS it's already been added to sys.path and replace=False + if (not replace) and nloc in npath[p:]: + return if path is sys.path: self.check_version_conflict() path.insert(p, loc) |