module file : added filtering based on environment variable name
This commit is contained in:
parent
faf4a1e370
commit
d546d828d3
@ -6,3 +6,7 @@
|
|||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
modules:
|
modules:
|
||||||
enable: ['tcl', 'dotkit']
|
enable: ['tcl', 'dotkit']
|
||||||
|
|
||||||
|
dotkit:
|
||||||
|
filter:
|
||||||
|
environment_modifications: ['CPATH', 'LIBRARY_PATH'] # Exclude changes to any of these variables
|
||||||
|
@ -146,7 +146,7 @@
|
|||||||
'type': 'object',
|
'type': 'object',
|
||||||
'additionalProperties': False,
|
'additionalProperties': False,
|
||||||
'patternProperties': {
|
'patternProperties': {
|
||||||
'compilers:?': { # optional colon for overriding site config.
|
'compilers:?': { # optional colon for overriding site config.
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
'default': {},
|
'default': {},
|
||||||
'additionalProperties': False,
|
'additionalProperties': False,
|
||||||
@ -195,6 +195,7 @@
|
|||||||
'default': [],
|
'default': [],
|
||||||
'items': {
|
'items': {
|
||||||
'type': 'string'},},},},
|
'type': 'string'},},},},
|
||||||
|
|
||||||
'packages': {
|
'packages': {
|
||||||
'$schema': 'http://json-schema.org/schema#',
|
'$schema': 'http://json-schema.org/schema#',
|
||||||
'title': 'Spack package configuration file schema',
|
'title': 'Spack package configuration file schema',
|
||||||
@ -238,11 +239,35 @@
|
|||||||
'default' : {},
|
'default' : {},
|
||||||
}
|
}
|
||||||
},},},},},},
|
},},},},},},
|
||||||
|
|
||||||
'modules': {
|
'modules': {
|
||||||
'$schema': 'http://json-schema.org/schema#',
|
'$schema': 'http://json-schema.org/schema#',
|
||||||
'title': 'Spack module file configuration file schema',
|
'title': 'Spack module file configuration file schema',
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
'additionalProperties': False,
|
'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': {
|
'patternProperties': {
|
||||||
r'modules:?': {
|
r'modules:?': {
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
@ -253,9 +278,22 @@
|
|||||||
'type': 'array',
|
'type': 'array',
|
||||||
'default': [],
|
'default': [],
|
||||||
'items': {
|
'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
|
||||||
|
]
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -250,3 +250,19 @@ def validate(env, errstream):
|
|||||||
modifications = env.group_by_name()
|
modifications = env.group_by_name()
|
||||||
for variable, list_of_changes in sorted(modifications.items()):
|
for variable, list_of_changes in sorted(modifications.items()):
|
||||||
set_or_unset_not_first(variable, list_of_changes, errstream)
|
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
|
||||||
|
@ -179,9 +179,17 @@ def write(self):
|
|||||||
if not env:
|
if not env:
|
||||||
return
|
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:
|
with open(self.file_name, 'w') as f:
|
||||||
self.write_header(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)
|
f.write(line)
|
||||||
|
|
||||||
def write_header(self, stream):
|
def write_header(self, stream):
|
||||||
|
Loading…
Reference in New Issue
Block a user