Commit ae984452 authored by Jim Fulton's avatar Jim Fulton

Added an api to set a default value for the versions option.

This will allow a versions feature to be added without updating all
recipes initially.  Later, recipes that support custom versions will
be able to override the defaults by passing options.
parent 2ba02437
......@@ -33,6 +33,9 @@ Feature Changes
emitted indicating the version picked. This is useful for setting
versions options.
A default_versions function can be used to set a default value for
this option.
- Adjusted the output for verbosity levels. Using a single -v option
no longer causes voluminous setuptools output. Uisng -vv and -vvv
now triggers extra setuptools output.
......
......@@ -105,6 +105,8 @@ _easy_install_cmd = _safe_arg(
class Installer:
_versions = {}
def __init__(self,
dest=None,
links=(),
......@@ -128,7 +130,9 @@ class Installer:
self._env = pkg_resources.Environment(path,
python=_get_version(executable))
self._index = _get_index(executable, index, links)
self._versions = versions or {}
if versions is not None:
self._versions = versions
def _satisfied(self, req):
dists = [dist for dist in self._env[req.project_name] if dist in req]
......@@ -414,9 +418,9 @@ class Installer:
# trying to resolve requirements, adding missing requirements as they
# are reported.
#
# Note that we don't pass in the environment, because we
# want to look for new eggs unless what we have is the best that matches
# the requirement.
# Note that we don't pass in the environment, because we want
# to look for new eggs unless what we have is the best that
# matches the requirement.
while 1:
try:
ws.resolve(requirements)
......@@ -492,6 +496,11 @@ class Installer:
undo.reverse()
[f() for f in undo]
def default_versions(versions=None):
old = Installer._versions
if versions is not None:
Installer._versions = versions
return old
def install(specs, dest,
links=(), index=None,
......
......@@ -260,6 +260,44 @@ reporting that a version was picked automatically:
>>> handler.uninstall()
>>> logging.getLogger('zc.buildout.easy_install').propagate = True
The function default_versions can be used to get and set default
version information to be used when no version information is passes.
If called with an argument, it sets the default versions:
>>> zc.buildout.easy_install.default_versions(dict(demoneeded='1'))
{}
It always returns the previous default versions. If called without an
argument, it simply returns the default versions without changing
them:
>>> zc.buildout.easy_install.default_versions()
{'demoneeded': '1'}
So with the default versions set, we'll get the requested version even
if the versions option isn't used:
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... )
>>> [d.version for d in ws]
['0.3', '1.0']
Of course, we can unset the default versions by passing an empty
dictionary:
>>> zc.buildout.easy_install.default_versions({})
{'demoneeded': '1'}
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server], index=link_server+'index/',
... )
>>> [d.version for d in ws]
['0.3', '1.1']
Script generation
-----------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment