[Python-checkins] python/nondist/sandbox/setuptools pkg_resources.py, 1.70, 1.71
pje@users.sourceforge.net
pje at users.sourceforge.net
Sat Sep 24 19:58:26 CEST 2005
Update of /cvsroot/python/python/nondist/sandbox/setuptools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32232
Modified Files:
pkg_resources.py
Log Message:
Implement smart version conflict resolution for scripts, so that
installed applications will not have their eggs overridden by packages
installed locally on sys.path. This should also make things work a bit
better for "traditional" non-root Python setups on Unixy operating
systems. See:
http://mail.python.org/pipermail/distutils-sig/2005-September/005164.html
for more details.
Index: pkg_resources.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/pkg_resources.py,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- pkg_resources.py 19 Aug 2005 01:01:53 -0000 1.70
+++ pkg_resources.py 24 Sep 2005 17:58:22 -0000 1.71
@@ -463,7 +463,7 @@
requirements = list(requirements)[::-1] # set up the stack
processed = {} # set of processed requirements
- best = {} # key -> dist
+ best = dict([(d.key,d) for d in self]) # key -> dist
to_activate = []
while requirements:
@@ -2131,19 +2131,35 @@
# Set up global resource manager
-
_manager = ResourceManager()
-
def _initialize(g):
for name in dir(_manager):
if not name.startswith('_'):
g[name] = getattr(_manager, name)
_initialize(globals())
-
# Prepare the master working set and make the ``require()`` API available
-
working_set = WorkingSet()
+try:
+ # Does the main program list any requirements?
+ from __main__ import __requires__
+except ImportError:
+ pass # No: just use the default working set based on sys.path
+else:
+ # Yes: ensure the requirements are met, by prefixing sys.path if necessary
+ try:
+ working_set.require(__requires__)
+ except VersionConflict: # try it without defaults already on sys.path
+ working_set = WorkingSet([]) # by starting with an empty path
+ for dist in working_set.resolve(
+ parse_requirements(__requires__), Environment()
+ ):
+ working_set.add(dist)
+ for entry in sys.path: # add any missing entries from sys.path
+ if entry not in working_set.entries:
+ working_set.add_entry(entry)
+ sys.path[:] = working_set.entries # then copy back to sys.path
+
require = working_set.require
iter_entry_points = working_set.iter_entry_points
add_activation_listener = working_set.subscribe
@@ -2153,21 +2169,5 @@
# 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())
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
More information about the Python-checkins
mailing list