From d546d828d322d54bb61c10dbf1fa42831049001e Mon Sep 17 00:00:00 2001 From: alalazo Date: Tue, 5 Apr 2016 13:20:28 +0200 Subject: module file : added filtering based on environment variable name --- lib/spack/spack/config.py | 44 +++++++++++++++++++++++++++++++++++++++--- lib/spack/spack/environment.py | 16 +++++++++++++++ lib/spack/spack/modules.py | 10 +++++++++- 3 files changed, 66 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index 14e5aaf4fb..4fca735fc9 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -146,7 +146,7 @@ section_schemas = { '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 @@ section_schemas = { 'default': [], 'items': { 'type': 'string'},},},}, + 'packages': { '$schema': 'http://json-schema.org/schema#', 'title': 'Spack package configuration file schema', @@ -238,11 +239,35 @@ section_schemas = { '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 @@ section_schemas = { '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 + ] + }, } }, }, diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index 72aafa4e2d..3d18d3a63f 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -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 diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py index d797af287d..aca37ae14b 100644 --- a/lib/spack/spack/modules.py +++ b/lib/spack/spack/modules.py @@ -179,9 +179,17 @@ class EnvModule(object): 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): -- cgit v1.2.3-70-g09d2