Commit 9cb1d5dc authored by jim's avatar jim

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.


git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@73015 62d5b8a3-27da-0310-9561-8e5933582275
parent da688181
...@@ -33,6 +33,9 @@ Feature Changes ...@@ -33,6 +33,9 @@ Feature Changes
emitted indicating the version picked. This is useful for setting emitted indicating the version picked. This is useful for setting
versions options. 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 - Adjusted the output for verbosity levels. Using a single -v option
no longer causes voluminous setuptools output. Uisng -vv and -vvv no longer causes voluminous setuptools output. Uisng -vv and -vvv
now triggers extra setuptools output. now triggers extra setuptools output.
......
...@@ -105,6 +105,8 @@ _easy_install_cmd = _safe_arg( ...@@ -105,6 +105,8 @@ _easy_install_cmd = _safe_arg(
class Installer: class Installer:
_versions = {}
def __init__(self, def __init__(self,
dest=None, dest=None,
links=(), links=(),
...@@ -128,7 +130,9 @@ class Installer: ...@@ -128,7 +130,9 @@ class Installer:
self._env = pkg_resources.Environment(path, self._env = pkg_resources.Environment(path,
python=_get_version(executable)) python=_get_version(executable))
self._index = _get_index(executable, index, links) self._index = _get_index(executable, index, links)
self._versions = versions or {}
if versions is not None:
self._versions = versions
def _satisfied(self, req): def _satisfied(self, req):
dists = [dist for dist in self._env[req.project_name] if dist in req] dists = [dist for dist in self._env[req.project_name] if dist in req]
...@@ -414,9 +418,9 @@ class Installer: ...@@ -414,9 +418,9 @@ class Installer:
# trying to resolve requirements, adding missing requirements as they # trying to resolve requirements, adding missing requirements as they
# are reported. # are reported.
# #
# Note that we don't pass in the environment, because we # Note that we don't pass in the environment, because we want
# want to look for new eggs unless what we have is the best that matches # to look for new eggs unless what we have is the best that
# the requirement. # matches the requirement.
while 1: while 1:
try: try:
ws.resolve(requirements) ws.resolve(requirements)
...@@ -492,6 +496,11 @@ class Installer: ...@@ -492,6 +496,11 @@ class Installer:
undo.reverse() undo.reverse()
[f() for f in undo] [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, def install(specs, dest,
links=(), index=None, links=(), index=None,
......
...@@ -260,6 +260,44 @@ reporting that a version was picked automatically: ...@@ -260,6 +260,44 @@ reporting that a version was picked automatically:
>>> handler.uninstall() >>> handler.uninstall()
>>> logging.getLogger('zc.buildout.easy_install').propagate = True >>> 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 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