diff options
author | alalazo <massimiliano.culpo@googlemail.com> | 2016-04-05 13:20:28 +0200 |
---|---|---|
committer | alalazo <massimiliano.culpo@googlemail.com> | 2016-04-05 13:20:28 +0200 |
commit | d546d828d322d54bb61c10dbf1fa42831049001e (patch) | |
tree | f1ca7e0c4be36b46de171cc104ab74bc89342afc | |
parent | faf4a1e37044cfafe6b96f989b106c800c3f240a (diff) | |
download | spack-d546d828d322d54bb61c10dbf1fa42831049001e.tar.gz spack-d546d828d322d54bb61c10dbf1fa42831049001e.tar.bz2 spack-d546d828d322d54bb61c10dbf1fa42831049001e.tar.xz spack-d546d828d322d54bb61c10dbf1fa42831049001e.zip |
module file : added filtering based on environment variable name
-rw-r--r-- | etc/spack/modules.yaml | 4 | ||||
-rw-r--r-- | lib/spack/spack/config.py | 44 | ||||
-rw-r--r-- | lib/spack/spack/environment.py | 16 | ||||
-rw-r--r-- | lib/spack/spack/modules.py | 10 |
4 files changed, 70 insertions, 4 deletions
diff --git a/etc/spack/modules.yaml b/etc/spack/modules.yaml index aa2a2c3fe2..395cf9c2cd 100644 --- a/etc/spack/modules.yaml +++ b/etc/spack/modules.yaml @@ -6,3 +6,7 @@ # ------------------------------------------------------------------------- modules: enable: ['tcl', 'dotkit'] + + dotkit: + filter: + environment_modifications: ['CPATH', 'LIBRARY_PATH'] # Exclude changes to any of these variables 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): |