Commit 7e5bdea9 authored by Jim Fulton's avatar Jim Fulton

Added a recipe update method.

parent 65da05ac
...@@ -28,7 +28,12 @@ Next Release ...@@ -28,7 +28,12 @@ Next Release
Feature Changes Feature Changes
--------------- ---------------
Renamed the runsetup command to setup. (The old name still works.) - Renamed the runsetup command to setup. (The old name still works.)
- Added a recipe update method. Now install is only called when a part
is installed for the first time, or after an uninstall. Otherwise,
update is called. For backward compatibility, recipes that don't
define update methiods are still supported.
1.0.0b9 (2006-10-02) 1.0.0b9 (2006-10-02)
==================== ====================
......
...@@ -288,10 +288,21 @@ class Buildout(dict): ...@@ -288,10 +288,21 @@ class Buildout(dict):
for part in reversed(installed_parts): for part in reversed(installed_parts):
if part in install_parts: if part in install_parts:
old_options = installed_part_options[part].copy() old_options = installed_part_options[part].copy()
old_options.pop('__buildout_installed__') installed_files = old_options.pop('__buildout_installed__')
new_options = self.get(part) new_options = self.get(part)
if old_options == new_options: if old_options == new_options:
# The options are the same, but are all of the
# installed files still there? If not, we should
# reinstall.
if not installed_files:
continue continue
for f in installed_files.split('\n'):
if not os.path.exists(self._buildout_path(f)):
break
else:
continue
# output debugging info
for k in old_options: for k in old_options:
if k not in new_options: if k not in new_options:
self._logger.debug("Part: %s, dropped option %s", self._logger.debug("Part: %s, dropped option %s",
...@@ -305,6 +316,7 @@ class Buildout(dict): ...@@ -305,6 +316,7 @@ class Buildout(dict):
if k not in old_options: if k not in old_options:
self._logger.debug("Part: %s, new option %s", self._logger.debug("Part: %s, new option %s",
part, k) part, k)
elif not uninstall_missing: elif not uninstall_missing:
continue continue
...@@ -316,17 +328,52 @@ class Buildout(dict): ...@@ -316,17 +328,52 @@ class Buildout(dict):
# install new parts # install new parts
for part in install_parts: for part in install_parts:
signature = self[part].pop('__buildout_signature__')
saved_options = self[part].copy()
if part in installed_parts:
self._logger.info('Updating %s', part)
old_options = installed_part_options[part]
old_installed_files = old_options['__buildout_installed__']
try:
update = recipes[part].update
except AttributeError:
update = recipes[part].install
self._logger.warning(
"The recipe for %s doesn't define an update "
"method. Using it's install method",
part)
try:
installed_files = update()
except:
installed_parts.remove(part)
self._uninstall(old_installed_files)
raise
if installed_files is None:
installed_files = old_installed_files.split('\n')
else:
self._logger.info('Installing %s', part) self._logger.info('Installing %s', part)
installed_part_options[part] = self[part].copy() installed_files = recipes[part].install()
del self[part]['__buildout_signature__'] if installed_files is None:
installed_files = recipes[part].install() or () self._logger.warning(
"The %s install returned None. A path or "
"iterable os paths should be returned.",
part)
installed_files = ()
if isinstance(installed_files, str): if isinstance(installed_files, str):
installed_files = [installed_files] installed_files = [installed_files]
installed_part_options[part]['__buildout_installed__'] = (
'\n'.join(installed_files) installed_part_options[part] = saved_options
) saved_options['__buildout_installed__'
] = '\n'.join(installed_files)
saved_options['__buildout_signature__'] = signature
if part not in installed_parts: if part not in installed_parts:
installed_parts.append(part) installed_parts.append(part)
finally: finally:
installed_part_options['buildout']['parts'] = ' '.join( installed_part_options['buildout']['parts'] = ' '.join(
[p for p in conf_parts if p in installed_parts] [p for p in conf_parts if p in installed_parts]
...@@ -475,7 +522,9 @@ class Buildout(dict): ...@@ -475,7 +522,9 @@ class Buildout(dict):
return self._buildout_path(self['buildout']['installed']) return self._buildout_path(self['buildout']['installed'])
def _uninstall(self, installed): def _uninstall(self, installed):
for f in installed.split(): for f in installed.split('\n'):
if not f:
continue
f = self._buildout_path(f) f = self._buildout_path(f)
if os.path.isdir(f): if os.path.isdir(f):
shutil.rmtree(f) shutil.rmtree(f)
......
This diff is collapsed.
...@@ -178,6 +178,8 @@ def test_comparing_saved_options_with_funny_characters(): ...@@ -178,6 +178,8 @@ def test_comparing_saved_options_with_funny_characters():
... def install(self): ... def install(self):
... open('t', 'w').write('t') ... open('t', 'w').write('t')
... return 't' ... return 't'
...
... update = install
... ''') ... ''')
...@@ -214,7 +216,7 @@ uninstalling anything because the configuration hasn't changed. ...@@ -214,7 +216,7 @@ uninstalling anything because the configuration hasn't changed.
>>> print system(buildout), # doctest: +ELLIPSIS >>> print system(buildout), # doctest: +ELLIPSIS
buildout: Develop: ...setup.py buildout: Develop: ...setup.py
buildout: Installing debug buildout: Updating debug
""" """
...@@ -277,22 +279,22 @@ Options: ...@@ -277,22 +279,22 @@ Options:
<BLANKLINE> <BLANKLINE>
-q -q
<BLANKLINE> <BLANKLINE>
Deccreaae the level of verbosity. This option can be used multiple times. Decrease the level of verbosity. This option can be used multiple times.
<BLANKLINE> <BLANKLINE>
-c config_file -c config_file
<BLANKLINE> <BLANKLINE>
Specify the path to the buildout configuration file to be used. Specify the path to the buildout configuration file to be used.
This defaults to the file named"buildout.cfg" in the current This defaults to the file named "buildout.cfg" in the current
working directory. working directory.
<BLANKLINE> <BLANKLINE>
Assignments are of the form: section:option=value and are used to Assignments are of the form: section:option=value and are used to
provide configuration options that override those givem in the provide configuration options that override those given in the
configuration file. For example, to run the buildout in offline mode, configuration file. For example, to run the buildout in offline mode,
use buildout:offline=true. use buildout:offline=true.
<BLANKLINE> <BLANKLINE>
Options and assignments can be interspersed. Options and assignments can be interspersed.
<BLANKLINE> <BLANKLINE>
Commmonds: Commands:
<BLANKLINE> <BLANKLINE>
install [parts] install [parts]
<BLANKLINE> <BLANKLINE>
...@@ -324,22 +326,22 @@ Options: ...@@ -324,22 +326,22 @@ Options:
<BLANKLINE> <BLANKLINE>
-q -q
<BLANKLINE> <BLANKLINE>
Deccreaae the level of verbosity. This option can be used multiple times. Decrease the level of verbosity. This option can be used multiple times.
<BLANKLINE> <BLANKLINE>
-c config_file -c config_file
<BLANKLINE> <BLANKLINE>
Specify the path to the buildout configuration file to be used. Specify the path to the buildout configuration file to be used.
This defaults to the file named"buildout.cfg" in the current This defaults to the file named "buildout.cfg" in the current
working directory. working directory.
<BLANKLINE> <BLANKLINE>
Assignments are of the form: section:option=value and are used to Assignments are of the form: section:option=value and are used to
provide configuration options that override those givem in the provide configuration options that override those given in the
configuration file. For example, to run the buildout in offline mode, configuration file. For example, to run the buildout in offline mode,
use buildout:offline=true. use buildout:offline=true.
<BLANKLINE> <BLANKLINE>
Options and assignments can be interspersed. Options and assignments can be interspersed.
<BLANKLINE> <BLANKLINE>
Commmonds: Commands:
<BLANKLINE> <BLANKLINE>
install [parts] install [parts]
<BLANKLINE> <BLANKLINE>
......
...@@ -44,6 +44,7 @@ zc.buildout used: ...@@ -44,6 +44,7 @@ zc.buildout used:
... for project in 'zc.buildout', 'setuptools': ... for project in 'zc.buildout', 'setuptools':
... req = pkg_resources.Requirement.parse(project) ... req = pkg_resources.Requirement.parse(project)
... print project, pkg_resources.working_set.find(req).version ... print project, pkg_resources.working_set.find(req).version
... return ()
... """) ... """)
......
...@@ -8,6 +8,8 @@ To do ...@@ -8,6 +8,8 @@ To do
Change History Change History
************** **************
Updated to work with zc.buildout 1.0.0b10.
1.0.0b1 1.0.0b1
======= =======
......
...@@ -38,6 +38,9 @@ around the egg recipe: ...@@ -38,6 +38,9 @@ around the egg recipe:
... for d in ws: ... for d in ws:
... print d ... print d
... print 'extra paths:', self.egg.extra_paths ... print 'extra paths:', self.egg.extra_paths
... return ()
...
... update = install
... """) ... """)
Here we instantiated the egg recipe in the constructor, saving it in Here we instantiated the egg recipe in the constructor, saving it in
......
...@@ -67,7 +67,7 @@ class Custom: ...@@ -67,7 +67,7 @@ class Custom:
def install(self): def install(self):
if self.buildout['buildout'].get('offline') == 'true': if self.buildout['buildout'].get('offline') == 'true':
return return ()
options = self.options options = self.options
distribution = options.get('eggs', self.name).strip() distribution = options.get('eggs', self.name).strip()
build_ext = dict([ build_ext = dict([
...@@ -80,3 +80,6 @@ class Custom: ...@@ -80,3 +80,6 @@ class Custom:
self.links, self.index, options['executable'], [options['_e']], self.links, self.index, options['executable'], [options['_e']],
) )
return ()
update = install
...@@ -119,3 +119,6 @@ class Egg: ...@@ -119,3 +119,6 @@ class Egg:
interpreter=options.get('interpreter'), interpreter=options.get('interpreter'),
) )
return ()
update = install
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
Change History Change History
************** **************
Updated to work with zc.buildout 1.0.0b10.
1.0.0b2 1.0.0b2
======= =======
......
...@@ -54,6 +54,8 @@ class TestRunner: ...@@ -54,6 +54,8 @@ class TestRunner:
)), )),
) )
update = install
arg_template = """[ arg_template = """[
'--test-path', %(TESTPATH)s, '--test-path', %(TESTPATH)s,
]""" ]"""
......
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