After generating some console scripts using zc.recipe.egg, I would like to have those scripts actually automatically run by buildout after everything else is installed.
I know of the z3c.recipe.runscript buildout recipe, but AFAIK, it would need to either set extra paths (so package imports won't fail) or execute the generated Python (script) module, neither of which it seems to be capable of.
Is there a way to accomplish this with z3c.recipe.runscript, or some other way?
To run arbitrary commands from a buildout script, use plone.recipe.command
:
[buildout]
parts =
some_console_script
command
[some_console_script]
recipe = zc.recipe.egg:scripts
scriptname = some_console_script
eggs =
foo_egg
bar_egg
scripts = console_entry_point=${:scriptname}
[command]
recipe = plone.recipe.command
command = ${buildout:bin-directory}/${some_console_script:scriptname}
update-command = command
The command
part will now run the console script on every run (command
when installing, update-command
to signal an update on each subsequent run).
This is not necessarily run all the way at the end of the buildout. It is run after all the dependencies of the [command]
section have run, but other sections can still be run after command
.
If you absolutely must run your command at the end of the buildout run, you need to create a buildout extension instead. Extensions can define entry points to be loaded at the start (zc.buildout.extension
) and the end (zc.buildout.unloadextension
) of a buildout run. Either entry point is passed the buildout
object as an argument. It should be trivial to write an extension that runs your command at the very end that way.