module file : added filtering based on environment variable name

This commit is contained in:
alalazo 2016-04-05 13:20:28 +02:00
parent faf4a1e370
commit d546d828d3
4 changed files with 70 additions and 4 deletions

View File

@ -6,3 +6,7 @@
# -------------------------------------------------------------------------
modules:
enable: ['tcl', 'dotkit']
dotkit:
filter:
environment_modifications: ['CPATH', 'LIBRARY_PATH'] # Exclude changes to any of these variables

View File

@ -146,7 +146,7 @@
'type': 'object',
'additionalProperties': False,
'patternProperties': {
'compilers:?': { # optional colon for overriding site config.
'compilers:?': { # optional colon for overriding site config.
'type': 'object',
'default': {},
'additionalProperties': False,
@ -195,6 +195,7 @@
'default': [],
'items': {
'type': 'string'},},},},
'packages': {
'$schema': 'http://json-schema.org/schema#',
'title': 'Spack package configuration file schema',
@ -238,11 +239,35 @@
'default' : {},
}
},},},},},},
'modules': {
'$schema': 'http://json-schema.org/schema#',
'title': 'Spack module file configuration file schema',
'type': 'object',
'additionalProperties': False,
'definitions': {
'module_type_configuration': {
'type': 'object',
'default': {},
'additionalProperties': False,
'properties': {
'filter': {
'type': 'object',
'default': {},
'additionalProperties': False,
'properties': {
'environment_modifications': {
'type': 'array',
'default': [],
'items': {
'type': 'string'
}
}
}
}
}
}
},
'patternProperties': {
r'modules:?': {
'type': 'object',
@ -253,9 +278,22 @@
'type': 'array',
'default': [],
'items': {
'type': 'string'
'type': 'string',
'enum': ['tcl', 'dotkit']
}
}
},
'tcl': {
'allOf': [
{'$ref': '#/definitions/module_type_configuration'}, # Base configuration
{} # Specific tcl extensions
]
},
'dotkit': {
'allOf': [
{'$ref': '#/definitions/module_type_configuration'}, # Base configuration
{} # Specific dotkit extensions
]
},
}
},
},

View File

@ -250,3 +250,19 @@ def validate(env, errstream):
modifications = env.group_by_name()
for variable, list_of_changes in sorted(modifications.items()):
set_or_unset_not_first(variable, list_of_changes, errstream)
def filter_environment_modifications(env, variables):
"""
Generator that filters out any change to environment variables present in the input list
Args:
env: list of environment modifications
variables: list of variable names to be filtered
Yields:
items in env if they are not in variables
"""
for item in env:
if item.name not in variables:
yield item

View File

@ -179,9 +179,17 @@ def write(self):
if not env:
return
# Filter modifications to the environment according to configuration files
try:
filter_list = CONFIGURATION[self.name]['filter']['environment_modifications']
except KeyError:
filter_list = []
with open(self.file_name, 'w') as f:
self.write_header(f)
for line in self.process_environment_command(env):
for line in self.process_environment_command(
filter_environment_modifications(env, filter_list)
):
f.write(line)
def write_header(self, stream):