modules : added hook for module specific extensions
This commit is contained in:
parent
c69acfa5c8
commit
18a241fe21
@ -276,6 +276,7 @@
|
|||||||
},
|
},
|
||||||
'autoload': {'$ref': '#/definitions/dependency_selection'},
|
'autoload': {'$ref': '#/definitions/dependency_selection'},
|
||||||
'prerequisites': {'$ref': '#/definitions/dependency_selection'},
|
'prerequisites': {'$ref': '#/definitions/dependency_selection'},
|
||||||
|
'conflict': {'type': 'string'},
|
||||||
'environment': {
|
'environment': {
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
'default': {},
|
'default': {},
|
||||||
@ -325,11 +326,7 @@
|
|||||||
'tcl': {
|
'tcl': {
|
||||||
'allOf': [
|
'allOf': [
|
||||||
{'$ref': '#/definitions/module_type_configuration'}, # Base configuration
|
{'$ref': '#/definitions/module_type_configuration'}, # Base configuration
|
||||||
{
|
{} # Specific tcl extensions
|
||||||
'properties': {
|
|
||||||
'conflict': {'type': 'string'}
|
|
||||||
}
|
|
||||||
} # Specific tcl extensions
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'dotkit': {
|
'dotkit': {
|
||||||
|
@ -146,6 +146,17 @@ def dependencies(spec, request='all'):
|
|||||||
return [xx for ii, xx in l if not (xx in seen or seen_add(xx))]
|
return [xx for ii, xx in l if not (xx in seen or seen_add(xx))]
|
||||||
|
|
||||||
|
|
||||||
|
def update_dictionary_extending_lists(target, update):
|
||||||
|
for key in update:
|
||||||
|
value = target.get(key, None)
|
||||||
|
if isinstance(value, list):
|
||||||
|
target[key].extend(update[key])
|
||||||
|
elif isinstance(value, dict):
|
||||||
|
update_dictionary_extending_lists(target[key], update[key])
|
||||||
|
else:
|
||||||
|
target[key] = update[key]
|
||||||
|
|
||||||
|
|
||||||
def parse_config_options(module_generator):
|
def parse_config_options(module_generator):
|
||||||
"""
|
"""
|
||||||
Parse the configuration file and returns a bunch of items that will be needed during module file generation
|
Parse the configuration file and returns a bunch of items that will be needed during module file generation
|
||||||
@ -159,19 +170,13 @@ def parse_config_options(module_generator):
|
|||||||
filters: list of environment variables whose modification is blacklisted in module files
|
filters: list of environment variables whose modification is blacklisted in module files
|
||||||
env: list of custom environment modifications to be applied in the module file
|
env: list of custom environment modifications to be applied in the module file
|
||||||
"""
|
"""
|
||||||
autoloads, prerequisites, filters = [], [], []
|
|
||||||
env = EnvironmentModifications()
|
|
||||||
# Get the configuration for this kind of generator
|
# Get the configuration for this kind of generator
|
||||||
try:
|
module_configuration = copy.copy(CONFIGURATION.get(module_generator.name, {}))
|
||||||
module_configuration = copy.copy(CONFIGURATION[module_generator.name])
|
|
||||||
except KeyError:
|
|
||||||
return autoloads, prerequisites, filters, env
|
|
||||||
|
|
||||||
# Get the defaults for all packages
|
|
||||||
all_conf = module_configuration.pop('all', {})
|
|
||||||
|
|
||||||
update_single(module_generator.spec, all_conf, autoloads, prerequisites, filters, env)
|
|
||||||
|
|
||||||
|
#####
|
||||||
|
# Merge all the rules
|
||||||
|
#####
|
||||||
|
module_file_actions = module_configuration.pop('all', {})
|
||||||
for spec, conf in module_configuration.items():
|
for spec, conf in module_configuration.items():
|
||||||
override = False
|
override = False
|
||||||
if spec.endswith(':'):
|
if spec.endswith(':'):
|
||||||
@ -179,45 +184,29 @@ def parse_config_options(module_generator):
|
|||||||
override = True
|
override = True
|
||||||
if module_generator.spec.satisfies(spec):
|
if module_generator.spec.satisfies(spec):
|
||||||
if override:
|
if override:
|
||||||
autoloads, prerequisites, filters = [], [], []
|
module_file_actions = {}
|
||||||
|
update_dictionary_extending_lists(module_file_actions, conf)
|
||||||
|
|
||||||
|
#####
|
||||||
|
# Process the common rules
|
||||||
|
#####
|
||||||
|
|
||||||
|
# Automatic loading loads
|
||||||
|
module_file_actions['autoload'] = dependencies(module_generator.spec, module_file_actions.get('autoload', 'none'))
|
||||||
|
# Prerequisites
|
||||||
|
module_file_actions['prerequisites'] = dependencies(module_generator.spec, module_file_actions.get('prerequisites', 'none'))
|
||||||
|
# Environment modifications
|
||||||
|
environment_actions = module_file_actions.pop('environment', {})
|
||||||
env = EnvironmentModifications()
|
env = EnvironmentModifications()
|
||||||
update_single(module_generator.spec, conf, autoloads, prerequisites, filters, env)
|
for method, arglist in environment_actions.items():
|
||||||
|
|
||||||
return autoloads, prerequisites, filters, env
|
|
||||||
|
|
||||||
|
|
||||||
def update_single(spec, configuration, autoloads, prerequisites, filters, env):
|
|
||||||
"""
|
|
||||||
Updates the entries in the arguments according to the configuration
|
|
||||||
|
|
||||||
Args:
|
|
||||||
spec: [in] target spec
|
|
||||||
configuration: [in] configuration file for the current type of module file generator
|
|
||||||
autoloads: [inout] list of dependencies to be automatically loaded
|
|
||||||
prerequisites: [inout] list of prerequisites
|
|
||||||
filters: [inout] list of environment variables whose modification is to be blacklisted
|
|
||||||
env: [inout] list of modifications to the environment
|
|
||||||
"""
|
|
||||||
# Get list of modules that will be loaded automatically
|
|
||||||
autoloads.extend(dependencies(spec, configuration.get('autoload', 'none')))
|
|
||||||
prerequisites.extend(dependencies(spec, configuration.get('prerequisites', 'none')))
|
|
||||||
|
|
||||||
# Filter modifications to environment variables
|
|
||||||
try:
|
|
||||||
filters.extend(configuration['filter']['environment_blacklist'])
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
for method, arglist in configuration['environment'].items():
|
|
||||||
for item in arglist:
|
for item in arglist:
|
||||||
if method == 'unset':
|
if method == 'unset':
|
||||||
args = [item]
|
args = [item]
|
||||||
else:
|
else:
|
||||||
args = item.split(',')
|
args = item.split(',')
|
||||||
getattr(env, method)(*args)
|
getattr(env, method)(*args)
|
||||||
except KeyError:
|
|
||||||
pass
|
return module_file_actions, env
|
||||||
|
|
||||||
|
|
||||||
def filter_blacklisted(specs, module_name):
|
def filter_blacklisted(specs, module_name):
|
||||||
@ -368,17 +357,19 @@ def write(self):
|
|||||||
self.spec.package.setup_environment(spack_env, env)
|
self.spec.package.setup_environment(spack_env, env)
|
||||||
|
|
||||||
# Parse configuration file
|
# Parse configuration file
|
||||||
autoloads, prerequisites, filters, conf_env = parse_config_options(self)
|
module_configuration, conf_env = parse_config_options(self)
|
||||||
env.extend(conf_env)
|
env.extend(conf_env)
|
||||||
|
filters = module_configuration.get('filter', {}).get('environment_blacklist',{})
|
||||||
# Build up the module file content
|
# Build up the module file content
|
||||||
module_file_content = self.header
|
module_file_content = self.header
|
||||||
for x in filter_blacklisted(autoloads, self.name):
|
for x in filter_blacklisted(module_configuration.pop('autoload', []), self.name):
|
||||||
module_file_content += self.autoload(x)
|
module_file_content += self.autoload(x)
|
||||||
for x in filter_blacklisted(prerequisites, self.name):
|
for x in filter_blacklisted(module_configuration.pop('prerequisites', []), self.name):
|
||||||
module_file_content += self.prerequisite(x)
|
module_file_content += self.prerequisite(x)
|
||||||
for line in self.process_environment_command(filter_environment_blacklist(env, filters)):
|
for line in self.process_environment_command(filter_environment_blacklist(env, filters)):
|
||||||
module_file_content += line
|
module_file_content += line
|
||||||
|
for line in self.module_specific_content(module_configuration):
|
||||||
|
module_file_content += line
|
||||||
|
|
||||||
# Dump to file
|
# Dump to file
|
||||||
with open(self.file_name, 'w') as f:
|
with open(self.file_name, 'w') as f:
|
||||||
@ -388,6 +379,9 @@ def write(self):
|
|||||||
def header(self):
|
def header(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def module_specific_content(self, configuration):
|
||||||
|
return tuple()
|
||||||
|
|
||||||
def autoload(self, spec):
|
def autoload(self, spec):
|
||||||
m = TclModule(spec)
|
m = TclModule(spec)
|
||||||
return self.autoload_format.format(module_file=m.use_name)
|
return self.autoload_format.format(module_file=m.use_name)
|
||||||
|
Loading…
Reference in New Issue
Block a user