Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions easybuild/framework/easyconfig/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@author: Pieter De Baets (Ghent University)
@author: Jens Timmerman (Ghent University)
@author: Toon Willems (Ghent University)
@author: Ward Poelmans (Ghent University)
"""

import copy
Expand Down Expand Up @@ -133,6 +134,9 @@ def __init__(self, path, extra_options=None, validate=True, valid_module_classes
# parse easyconfig file
self.parse(path)

# update easyconfig using env vars
self.parse_env()

# handle allowed system dependencies
self.handle_allowed_system_deps()

Expand Down Expand Up @@ -238,6 +242,32 @@ def parse(self, path):
# indicate that this is a parsed easyconfig
self._config['parsed'] = [True, "This is a parsed easyconfig", "HIDDEN"]

def parse_env(self):
"""
Override easyconfig settings from the environment.
When a environment variable of the form EB_EC_PARAM_<EB NAME>_<CONFIG> the value for
<CONFIG> is overriden.
"""
env_re = re.compile("^EB_EC_PARAM_%s_(\w+)$" % self.name.upper())
for env_var in os.environ.keys():
check_env = env_re.search(env_var)
if check_env is not None:
new_config = check_env.group(1).lower()
if new_config in self._config:
if isinstance(self[new_config], basestring):
self[new_config] = os.environ[env_var]
elif isinstance(self[new_config], list):
self[new_config] = os.environ[env_var].split(os.pathsep)
elif isinstance(self[new_config], dict):
try:
self[new_config] = {x.split('=')[0] : x.split('=')[1] for x in os.environ[env_var].split(os.pathsep)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no dict comprehension in python 2.4

except IndexError, err:
self.log.error("Environment variable %s has an invalid syntax for a dict: %s" % (env_var,err))

self.log.info("Environment config option override for %s to %s" % (new_config,self[new_config]))
else:
self.log.debug("Ignoring unknown environment config override for %s (value: %s)" % (new_config,os.environ[env_var]))

def handle_allowed_system_deps(self):
"""Handle allowed system dependencies."""
for (name, version) in self['allow_system_deps']:
Expand Down