diff options
| author | PJ Eby <distutils-sig@python.org> | 2005-09-24 17:58:22 +0000 |
|---|---|---|
| committer | PJ Eby <distutils-sig@python.org> | 2005-09-24 17:58:22 +0000 |
| commit | b6b29d019d1c33c75ee45fe8846525c75f1ed404 (patch) | |
| tree | 747afb3f844107fc6557513e2f76ec0a7b129c53 | |
| parent | b36d8cf48254de4e35688764e6026dfffdfa2b62 (diff) | |
| download | python-setuptools-git-b6b29d019d1c33c75ee45fe8846525c75f1ed404.tar.gz | |
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.
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041250
| -rw-r--r-- | pkg_resources.py | 42 | ||||
| -rwxr-xr-x | setuptools/command/easy_install.py | 6 |
2 files changed, 24 insertions, 24 deletions
diff --git a/pkg_resources.py b/pkg_resources.py index 60415c08..4cb9f957 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -463,7 +463,7 @@ class WorkingSet(object): 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 @@ def split_sections(s): # 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 @@ run_main = run_script # backward compatibility # 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()) - - - - - - - - - - - - - - - diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index ac7fe5a4..6f73383b 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -462,6 +462,7 @@ class easy_install(Command): script_text = get_script_header("") + ( "# EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r\n" + "__requires__ = %(spec)r\n" "import sys\n" "from pkg_resources import load_entry_point\n" "\n" @@ -489,7 +490,6 @@ class easy_install(Command): - def install_script(self, dist, script_name, script_text, dev_path=None): """Generate a legacy script wrapper and install it""" spec = str(dist.as_requirement()) @@ -497,6 +497,7 @@ class easy_install(Command): if dev_path: script_text = get_script_header(script_text) + ( "# EASY-INSTALL-DEV-SCRIPT: %(spec)r,%(script_name)r\n" + "__requires__ = %(spec)r\n" "from pkg_resources import require; require(%(spec)r)\n" "del require\n" "__file__ = %(dev_path)r\n" @@ -504,15 +505,14 @@ class easy_install(Command): ) % locals() else: script_text = get_script_header(script_text) + ( - "#!python\n" "# EASY-INSTALL-SCRIPT: %(spec)r,%(script_name)r\n" + "__requires__ = %(spec)r\n" "import pkg_resources\n" "pkg_resources.run_script(%(spec)r, %(script_name)r)\n" ) % locals() self.write_script(script_name, script_text) - def write_script(self, script_name, contents, mode="t"): """Write an executable file to the scripts directory""" log.info("Installing %s script to %s", script_name, self.script_dir) |
