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