aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMin RK <benjaminrk@gmail.com>2016-07-27 14:42:38 +0200
committerMin RK <benjaminrk@gmail.com>2016-07-28 16:42:03 +0200
commit4d158f842cbadb0d4b3bbeee3a8488f5f9a3dee4 (patch)
tree2d7efe0bd2a9ba9c3a8ffc337b855736ea332819
parent279e625938d7991755c0aeba63f4293d9b67fa0f (diff)
downloadexternal_python_setuptools-4d158f842cbadb0d4b3bbeee3a8488f5f9a3dee4.tar.gz
external_python_setuptools-4d158f842cbadb0d4b3bbeee3a8488f5f9a3dee4.tar.bz2
external_python_setuptools-4d158f842cbadb0d4b3bbeee3a8488f5f9a3dee4.zip
only call `dist.activate(True)` for *new* dists,
not those loaded by default.
-rw-r--r--pkg_resources/__init__.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index 602549be..6aabd4c5 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -947,11 +947,17 @@ class WorkingSet(object):
return needed
- def subscribe(self, callback):
- """Invoke `callback` for all distributions (including existing ones)"""
+ def subscribe(self, callback, existing=True):
+ """Invoke `callback` for all distributions
+
+ If `existing=True` (default),
+ call on all existing ones, as well.
+ """
if callback in self.callbacks:
return
self.callbacks.append(callback)
+ if not existing:
+ return
for dist in self:
callback(dist)
@@ -2967,10 +2973,14 @@ def _initialize_master_working_set():
run_script = working_set.run_script
# backward compatibility
run_main = run_script
- # Activate all distributions already on sys.path, and ensure that
- # all distributions added to the working set in the future (e.g. by
- # calling ``require()``) will get activated as well.
- add_activation_listener(lambda dist: dist.activate())
+ # Activate all distributions already on sys.path with replace=False and
+ # ensure that all distributions added to the working set in the future
+ # (e.g. by calling ``require()``) will get activated as well,
+ # with higher priority (replace=True).
+ for dist in working_set:
+ dist.activate(replace=False)
+ del dist
+ add_activation_listener(lambda dist: dist.activate(replace=True), existing=False)
working_set.entries=[]
# match order
list(map(working_set.add_entry, sys.path))