Commit d3be41f6 authored by Reinout van Rees's avatar Reinout van Rees

Added show-picked-versions option (default false).

Included: functionality (copy/pasted from buildout-versions) to
actually record and print the picked versions. For this, two new
class-level attributes on the Installer are added.

TODO: testing whether the printing of what required what also
works.
parent 03e8aa86
......@@ -136,6 +136,7 @@ _buildout_default_options = _annotate_section({
'parts-directory': 'parts',
'prefer-final': 'true',
'python': 'buildout',
'show-picked-versions': 'false',
'socket-timeout': '',
'use-dependency-links': 'true',
}, 'DEFAULT_VALUE')
......@@ -243,7 +244,6 @@ class Buildout(DictMixin):
# file_name = buildout['buildout']['buildout_versions_file']
# REINOUT: add 'update-versions-file' option.
# REINOUT: add a nice boolean show_picked_versions option.
self._annotated = copy.deepcopy(data)
self._raw = _unannotate(data)
......@@ -334,6 +334,8 @@ class Buildout(DictMixin):
bool_option(options, 'use-dependency-links'))
zc.buildout.easy_install.allow_picked_versions(
bool_option(options, 'allow-picked-versions'))
zc.buildout.easy_install.show_picked_versions(
bool_option(options, 'show-picked-versions'))
download_cache = options.get('download-cache')
if download_cache:
......@@ -646,42 +648,9 @@ class Buildout(DictMixin):
elif (not installed_parts) and installed_exists:
os.remove(self['buildout']['installed'])
# REINOUT Print picked versions here.
# self._print_picked_versions()
zc.buildout.easy_install.print_picked_versions()
self._unload_extensions()
# def _print_picked_versions(self):
# if picked_versions:
# output = ['[versions]']
# required_output = []
# for dist_, version in sorted(picked_versions.items()):
# if dist_ in required_by:
# required_output.append('')
# required_output.append('# Required by:')
# for req_ in sorted(required_by[dist_]):
# required_output.append('# '+req_)
# target = required_output
# else:
# target = output
# target.append("%s = %s" % (dist_, version))
# output.extend(required_output)
# print "Versions had to be automatically picked."
# print "The following part definition lists the versions picked:"
# print '\n'.join(output)
# if file_name:
# if os.path.exists(file_name):
# output[:1] = [
# '',
# '# Added by Buildout Versions at %s' % datetime.now(),
# ]
# output.append('')
# f = open(file_name,'a')
# f.write('\n'.join(output))
# f.close()
# print "This information has been written to %r" % file_name
def _update_installed(self, **buildout_options):
installed = self['buildout']['installed']
f = open(installed, 'a')
......
......@@ -833,6 +833,8 @@ COMMAND_LINE_VALUE).
DEFAULT_VALUE
python= buildout
DEFAULT_VALUE
show-picked-versions= false
DEFAULT_VALUE
socket-timeout=
DEFAULT_VALUE
use-dependency-links= true
......@@ -2373,6 +2375,7 @@ database is shown.
parts-directory = /sample-buildout/parts
prefer-final = true
python = buildout
show-picked-versions = false
socket-timeout =
use-dependency-links = true
verbosity = 20
......
......@@ -69,9 +69,6 @@ buildout_and_distribute_path = [
FILE_SCHEME = re.compile('file://', re.I).match
# REINOUT: two new globals.
# required_by = {}
# picked_versions = {} # This one could perhaps be local, on Installer?
class AllowHostsPackageIndex(setuptools.package_index.PackageIndex):
"""Will allow urls that are local to the system.
......@@ -124,11 +121,14 @@ _easy_install_cmd = 'from setuptools.command.easy_install import main; main()'
class Installer:
_versions = {}
_required_by = {}
_picked_versions = {}
_download_cache = None
_install_from_cache = False
_prefer_final = True
_use_dependency_links = True
_allow_picked_versions = True
_show_picked_versions = False
def __init__(self,
dest=None,
......@@ -520,8 +520,7 @@ class Installer:
):
logger.debug('Picked: %s = %s',
dist.project_name, dist.version)
# REINOUT: add the next line.
# picked_versions[dist.project_name] = dist.version
self._picked_versions[dist.project_name] = dist.version
if not self._allow_picked_versions:
raise zc.buildout.UserError(
......@@ -732,6 +731,49 @@ def allow_picked_versions(setting=None):
Installer._allow_picked_versions = bool(setting)
return old
def show_picked_versions(setting=None):
old = Installer._show_picked_versions
if setting is not None:
Installer._show_picked_versions = bool(setting)
return old
def print_picked_versions():
if not Installer._show_picked_versions:
return
if not Installer._picked_versions:
# Don't print empty output.
return
output = ['[versions]']
required_output = []
for dist_, version in sorted(Installer._picked_versions.items()):
if dist_ in Installer._required_by:
required_output.append('')
required_output.append('# Required by:')
for req_ in sorted(Installer._required_by[dist_]):
required_output.append('# '+req_)
target = required_output
else:
target = output
target.append("%s = %s" % (dist_, version))
output.extend(required_output)
print "Versions had to be automatically picked."
print "The following part definition lists the versions picked:"
print '\n'.join(output)
# if file_name:
# if os.path.exists(file_name):
# output[:1] = [
# '',
# '# Added by Buildout Versions at %s' % datetime.now(),
# ]
# output.append('')
# f = open(file_name,'a')
# f.write('\n'.join(output))
# f.close()
# print "This information has been written to %r" % file_name
def install(specs, dest,
links=(), index=None,
executable=sys.executable,
......@@ -1240,26 +1282,25 @@ class MissingDistribution(zc.buildout.UserError):
return "Couldn't find a distribution for %r." % str(req)
def _log_requirement(ws, req):
if not logger.isEnabledFor(logging.DEBUG):
if (not logger.isEnabledFor(logging.DEBUG) and
not Installer._show_picked_versions):
# Sorting the working set and iterating over it's requirements
# is expensive, so short cirtuit the work if it won't even be
# is expensive, so short circuit the work if it won't even be
# logged. When profiling a simple buildout with 10 parts with
# identical and large working sets, this resulted in a
# decrease of run time from 93.411 to 15.068 seconds, about a
# 6 fold improvement.
return
# REINOUT add extra check for 'allow-picked-versions=show'.
ws = list(ws)
ws.sort()
for dist in ws:
if req in dist.requires():
logger.debug(" required by %s." % dist)
# REINOUT add the following lines.
# req_ = str(req)
# if req_ not in required_by:
# required_by[req_] = set()
# required_by[req_].add(str(dist.as_requirement()))
req_ = str(req)
if req_ not in Installer._required_by:
Installer._required_by[req_] = set()
Installer._required_by[req_].add(str(dist.as_requirement()))
def _fix_file_links(links):
for link in links:
......
......@@ -228,6 +228,40 @@ We can also disable checking versions:
Installing foo.
recipe v2
Easier reporting and managing of versions (new in buildout 2.0)
---------------------------------------------------------------
Since buildout 2.0, the functionality of the `buildout-versions
<http://packages.python.org/buildout-versions/>`_ extension is part of
buildout itself. This makes reporting and managing versions easier.
If you set the ``show-picked-versions`` option, buildout will print
versions it picked at the end of its run:
>>> write('buildout.cfg',
... '''
... [buildout]
... parts = foo
... find-links = %s
... show-picked-versions = true
...
... [versions]
...
... [foo]
... recipe = spam
... ''' % join('recipe', 'dist'))
>>> print_(system(buildout), end='') # doctest: +ELLIPSIS
Updating foo.
recipe v2
Versions had to be automatically picked.
The following part definition lists the versions picked:
[versions]
distribute = 0.6.34
spam = 2
Controlling the python version
-------------------------------
......
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