summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoralalazo <massimiliano.culpo@googlemail.com>2016-06-30 12:56:47 +0200
committeralalazo <massimiliano.culpo@googlemail.com>2016-06-30 12:56:47 +0200
commit1b7eedbb7df7c6dee9ab84217e75dc8ec54dcee1 (patch)
treeb9b2b297f88e81300a3fa0567de8d8ca2bf19b41 /lib
parentb71d430af6025cb46ac574e91e516bc5c4caf048 (diff)
downloadspack-1b7eedbb7df7c6dee9ab84217e75dc8ec54dcee1.tar.gz
spack-1b7eedbb7df7c6dee9ab84217e75dc8ec54dcee1.tar.bz2
spack-1b7eedbb7df7c6dee9ab84217e75dc8ec54dcee1.tar.xz
spack-1b7eedbb7df7c6dee9ab84217e75dc8ec54dcee1.zip
modules.yaml : added hash_length as a new keyword
config : - added `hash_length` under the modules section EnvModules : - take into consideration hash_length when constructing `file_name` - added logic to warn and skip module file writing in case of file name clash
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/config.py5
-rw-r--r--lib/spack/spack/modules.py16
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py
index 84179e1469..3a66e9f2a6 100644
--- a/lib/spack/spack/config.py
+++ b/lib/spack/spack/config.py
@@ -328,6 +328,11 @@ section_schemas = {
'anyOf': [
{
'properties': {
+ 'hash_length': {
+ 'type': 'integer',
+ 'minimum': 0,
+ 'default': 7
+ },
'whitelist': {'$ref': '#/definitions/array_of_strings'},
'blacklist': {'$ref': '#/definitions/array_of_strings'},
'naming_scheme': {
diff --git a/lib/spack/spack/modules.py b/lib/spack/spack/modules.py
index 068179c0ce..82016feb84 100644
--- a/lib/spack/spack/modules.py
+++ b/lib/spack/spack/modules.py
@@ -188,6 +188,7 @@ def parse_config_options(module_generator):
#####
# Automatic loading loads
+ module_file_actions['hash_length'] = module_configuration.get('hash_length', 7)
module_file_actions['autoload'] = dependencies(
module_generator.spec, module_file_actions.get('autoload', 'none'))
# Prerequisites
@@ -295,7 +296,9 @@ class EnvModule(object):
if constraint in self.spec:
suffixes.append(suffix)
# Always append the hash to make the module file unique
- suffixes.append(self.spec.dag_hash())
+ hash_length = configuration.pop('hash_length', 7)
+ if hash_length != 0:
+ suffixes.append(self.spec.dag_hash(length=hash_length))
name = '-'.join(suffixes)
return name
@@ -338,7 +341,7 @@ class EnvModule(object):
return False
- def write(self):
+ def write(self, overwrite=False):
"""
Writes out a module file for this object.
@@ -399,6 +402,15 @@ class EnvModule(object):
for line in self.module_specific_content(module_configuration):
module_file_content += line
+ # Print a warning in case I am accidentally overwriting
+ # a module file that is already there (name clash)
+ if not overwrite and os.path.exists(self.file_name):
+ message = 'Module file already exists : skipping creation\n'
+ message += 'file : {0.file_name}\n'
+ message += 'spec : {0.spec}'
+ tty.warn(message.format(self))
+ return
+
# Dump to file
with open(self.file_name, 'w') as f:
f.write(module_file_content)