line34
Coding, Scripting, Administration

All scripts in the basket

In a buildout that has several sections using zc.recipe.egg I had the problem that a script I was building in one section ended up with the initialization of another script in another section.

Let's assume we have an egg "main_egg_a" that defines a script "script_a" and "common_egg" defines a script "common_script" and a couple of other scripts. The way we want to use script_a requires us to also include "common_egg" in the respective section. In the other section we want only "common_script", skipping any other scripts declared by "common_egg", so we declare it with the "scripts" option.

[script-a]
recipe = zc.recipe.egg
eggs = 
    main_egg_a
    common_egg
initialization =
    import os
    os.environ["foo"] = "emerald"

[script-b]
recipe = zc.recipe.egg
eggs =
    common_egg
scripts = common_script
initialization =
    import os
    os.environ["foo"] = "zirconia"

With this configuration however, bin/common_script kept having "emerald" set in the environment variable.

The problem is that the section [script-a] does not have a "scripts" option, but also includes common_egg. Without "scripts" declared it builds all the scripts in the given eggs, here script_a and common_script. If both sections build bin/common_script, the result depends on the order of execution. In my setup the script-b section always ran first, building bin/common_script with "zirconia" as the value for "foo". Then script-a ran afterwards, overwriting the previously built bin/common_script using its own setting for "foo", "emerald".

The fix is simple once you've figured out what's going on: Declare "scripts" if you give multiple eggs to the recipe.

[script-a]
recipe = zc.recipe.egg
eggs = 
    main_egg_a
    common_egg
scripts = script_a
initialization =
    import os
    os.environ["foo"] = "emerald"

[script-b]
recipe = zc.recipe.egg
eggs =
    common_egg
scripts = common_script
initialization =
    import os
    os.environ["foo"] = "zirconia"
20th March 2015Filed under: zc.buildout   zc.recipe.egg   buildout   scripts