Commit abf2b64e authored by Tres Seaver's avatar Tres Seaver

Merge branch 'refactor-pickedversions' of https://github.com/jaap3/buildout...

Merge branch 'refactor-pickedversions' of https://github.com/jaap3/buildout into jaap3-refactor-pickedversions
parents a79bf008 bb335abb
......@@ -120,6 +120,24 @@ def _unannotate(data):
data[key] = _unannotate_section(data[key])
return data
def _format_picked_versions(picked_versions, required_by):
output = ['[versions]']
required_output = []
for dist_, version in picked_versions:
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)
return output
_buildout_default_options = _annotate_section({
'allow-hosts': '*',
'allow-picked-versions': 'true',
......@@ -323,8 +341,8 @@ class Buildout(DictMixin):
self.show_picked_versions = bool_option(options,
'show-picked-versions')
self.update_versions_file = options['update-versions-file']
zc.buildout.easy_install.store_picked_versions(
self.show_picked_versions or self.update_versions_file)
zc.buildout.easy_install.store_required_by(self.show_picked_versions or
self.update_versions_file)
download_cache = options.get('download-cache')
if download_cache:
......@@ -637,7 +655,8 @@ class Buildout(DictMixin):
elif (not installed_parts) and installed_exists:
os.remove(self['buildout']['installed'])
self._print_picked_versions()
if self.show_picked_versions or self.update_versions_file:
self._print_picked_versions()
self._unload_extensions()
def _update_installed(self, **buildout_options):
......@@ -987,24 +1006,13 @@ class Buildout(DictMixin):
ep.load()(self)
def _print_picked_versions(self):
Installer = zc.buildout.easy_install.Installer
if not Installer._picked_versions:
picked_versions, required_by = (zc.buildout.easy_install
.get_picked_versions())
if not 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)
output = _format_picked_versions(picked_versions, required_by)
if self.show_picked_versions:
print_("Versions had to be automatically picked.")
......@@ -1016,11 +1024,11 @@ class Buildout(DictMixin):
if os.path.exists(self.update_versions_file):
output[:1] = [
'',
'# Added by buildout at %s' % datetime.datetime.now(),
]
'# Added by buildout at %s' % datetime.datetime.now()
]
output.append('')
f = open(self.update_versions_file, 'a')
f.write('\n'.join(output))
f.write(('\n'.join(output)))
f.close()
print_("Picked versions have been written to " +
self.update_versions_file)
......
......@@ -151,7 +151,7 @@ class Installer:
_prefer_final = True
_use_dependency_links = True
_allow_picked_versions = True
_store_picked_versions = False
_store_required_by = False
def __init__(self,
dest=None,
......@@ -756,12 +756,17 @@ def allow_picked_versions(setting=None):
Installer._allow_picked_versions = bool(setting)
return old
def store_picked_versions(setting=None):
old = Installer._store_picked_versions
def store_required_by(setting=None):
old = Installer._store_required_by
if setting is not None:
Installer._store_picked_versions = bool(setting)
Installer._store_required_by = bool(setting)
return old
def get_picked_versions():
picked_versions = sorted(Installer._picked_versions.items())
required_by = Installer._required_by
return (picked_versions, required_by)
def install(specs, dest,
links=(), index=None,
......@@ -1288,7 +1293,7 @@ class MissingDistribution(zc.buildout.UserError):
def _log_requirement(ws, req):
if (not logger.isEnabledFor(logging.DEBUG) and
not Installer._store_picked_versions):
not Installer._store_required_by):
# Sorting the working set and iterating over it's requirements
# is expensive, so short circuit the work if it won't even be
# logged. When profiling a simple buildout with 10 parts with
......
......@@ -368,8 +368,13 @@ at the end.
The versions file now contains the extra pin:
>>> 'spam = 2' in open('my_versions.cfg').read()
True
>>> print_(open('my_versions.cfg').read()) # doctest: +ELLIPSIS
<BLANKLINE>
...
<BLANKLINE>
# Added by buildout at YYYY-MM-DD hh:mm:ss.dddddd
spam = 2
<BLANKLINE>
And re-running buildout doesn't report any picked versions anymore:
......@@ -405,8 +410,13 @@ printing them to the console):
The versions file contains the extra pin:
>>> 'spam = 2' in open('my_versions.cfg').read()
True
>>> print_(open('my_versions.cfg').read()) # doctest: +ELLIPSIS
<BLANKLINE>
...
<BLANKLINE>
# Added by buildout at YYYY-MM-DD hh:mm:ss.dddddd
spam = 2
<BLANKLINE>
Because buildout now includes buildout-versions' (and part of the older
buildout.dumppickedversions') functionality, it warns if these extensions are
......
......@@ -3295,7 +3295,9 @@ def test_suite():
),
(re.compile('executable = %s' % re.escape(sys.executable)),
'executable = python'),
])
(re.compile(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{6}'),
'YYYY-MM-DD hh:mm:ss.dddddd'),
]),
),
doctest.DocFileSuite(
'debugging.txt',
......
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