From 3959ca627046ff7d6519da9c5375a0ae6da50b74 Mon Sep 17 00:00:00 2001 From: alalazo Date: Mon, 11 Apr 2016 18:10:06 +0200 Subject: [PATCH] modules : added possibility to blacklist or whitelist module files --- lib/spack/spack/cmd/module.py | 1 - lib/spack/spack/config.py | 17 +++++++++++------ lib/spack/spack/modules.py | 32 +++++++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/lib/spack/spack/cmd/module.py b/lib/spack/spack/cmd/module.py index a67f5c0c13..f996f4eb84 100644 --- a/lib/spack/spack/cmd/module.py +++ b/lib/spack/spack/cmd/module.py @@ -89,7 +89,6 @@ def module_refresh(): shutil.rmtree(cls.path, ignore_errors=False) mkdirp(cls.path) for spec in specs: - tty.debug(" Writing file for %s" % spec) cls(spec).write() diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index e696a62e96..da4e787f18 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -292,12 +292,17 @@ 'module_type_configuration': { 'type': 'object', 'default': {}, - 'properties': { - 'all': {'$ref': '#/definitions/module_file_configuration'} - }, - 'patternProperties': { - r'\w[\w-]*': {'$ref': '#/definitions/module_file_configuration'} - } + 'oneOf': [ + { + 'properties': { + 'whitelist': {'$ref': '#/definitions/array_of_strings'}, + 'blacklist': {'$ref': '#/definitions/array_of_strings'}, + } + }, + { + 'patternProperties': {r'\w[\w-]*': {'$ref': '#/definitions/module_file_configuration'}} + } + ] } }, 'patternProperties': { diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py index 8a96d49144..04f43b9605 100644 --- a/lib/spack/spack/modules.py +++ b/lib/spack/spack/modules.py @@ -40,17 +40,15 @@ Each hook in hooks/ implements the logic for writing its specific type of module file. """ +import copy import os import os.path import re -import shutil import textwrap -import copy import llnl.util.tty as tty import spack import spack.config - from llnl.util.filesystem import join_path, mkdirp from spack.build_environment import parent_class_modules, set_module_variables_for_package from spack.environment import * @@ -225,6 +223,30 @@ def category(self): # Not very descriptive fallback return 'spack installed package' + @property + def blacklisted(self): + configuration = CONFIGURATION.get(self.name, {}) + whitelist_matches = [x for x in configuration.get('whitelist', []) if self.spec.satisfies(x)] + blacklist_matches = [x for x in configuration.get('blacklist', []) if self.spec.satisfies(x)] + if whitelist_matches: + message = '\t%s is whitelisted [matches : ' % self.spec.cshort_spec + for rule in whitelist_matches: + message += '%s ' % rule + message += ' ]' + tty.debug(message) + + if blacklist_matches: + message = '\t%s is blacklisted [matches : ' % self.spec.cshort_spec + for rule in blacklist_matches: + message += '%s ' % rule + message += ' ]' + tty.debug(message) + + if not whitelist_matches and blacklist_matches: + return True + + return False + def write(self): """ Writes out a module file for this object. @@ -233,6 +255,10 @@ def write(self): - override the header property - provide formats for autoload, prerequisites and environment changes """ + if self.blacklisted: + return + tty.debug("\t%s : writing module file" % self.spec.cshort_spec) + module_dir = os.path.dirname(self.file_name) if not os.path.exists(module_dir): mkdirp(module_dir)