Commit 7a735fcd authored by Xavier Thompson's avatar Xavier Thompson

component/macros: Add macro.variable.eggs

This is a generalisation of macro.pythonpath.eggs which allows paths
from eggs to be placed into any environment variable, and provides a
way to specify subpaths for each egg from the egg location.

Like macro.pythonpath.eggs, the environment variable is placed in an
environment section at install time after the eggs are installed and
before the environment section is read by the section which uses it.

```
[environment-section]
PATH = some/path

[modify-environment]
<= macro.variable.eggs
variable = ANY_VARIABLE
eggs =
  blue_egg
  yellow_egg
  red_egg
subpaths =
  blue_egg subpath/specific/to/blue
  yellow_egg subpath/specific/to/yellow

[section-that-uses-environment]
recipe = zc.recipe.egg:custom
environment = environment-section
depends =
  ${modify-environment:recipe}

```
parent 1ab0cd3b
[buildout]
parts =
[macro.pythonpath.eggs]
[macro.variable.eggs]
recipe = slapos.recipe.build
init =
self.eggs = [e.strip() for e in options['eggs'].splitlines() if e.strip()]
update =
import os
from zc.buildout.easy_install import working_set
buildout = self.buildout['buildout']
eggs_directory = buildout['eggs-directory']
develop_eggs_directory = buildout['develop-eggs-directory']
dists = working_set(self.eggs, [develop_eggs_directory, eggs_directory])
paths = ':'.join(dist.location for dist in dists)
self.buildout[options['environment']]['PYTHONPATH'] = paths
print("PYTHONPATH=" + paths)
subpaths = dict(l.split() for l in options['subpaths'].splitlines())
def make_path(dist):
subpath = subpaths.get(dist.key)
return os.path.join(dist.location, subpath) if subpath else dist.location
paths = ':'.join(make_path(dist) for dist in dists)
environment = self.buildout[options['environment']]
variable = options['variable']
value = environment.get(variable)
if value:
paths = '%s:%s' % (paths, value)
environment[variable] = paths
print("%s=%s" %(variable, paths))
variable = PYTHONPATH
subpaths =
[macro.pythonpath.eggs]
<= macro.variable.eggs
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