Merge branch 'bugfix/config' of git://github.com/hegner/spack into hegner-bugfix/config
This commit is contained in:
commit
fc8d18ebdc
@ -129,7 +129,6 @@
|
|||||||
|
|
||||||
import llnl.util.tty as tty
|
import llnl.util.tty as tty
|
||||||
from llnl.util.filesystem import mkdirp
|
from llnl.util.filesystem import mkdirp
|
||||||
import copy
|
|
||||||
|
|
||||||
import spack
|
import spack
|
||||||
from spack.error import SpackError
|
from spack.error import SpackError
|
||||||
@ -306,13 +305,14 @@ def set_pp_defaults(validator, properties, instance, schema):
|
|||||||
yield err
|
yield err
|
||||||
|
|
||||||
return validators.extend(validator_class, {
|
return validators.extend(validator_class, {
|
||||||
"properties" : set_defaults,
|
"properties": set_defaults,
|
||||||
"patternProperties" : set_pp_defaults
|
"patternProperties": set_pp_defaults
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
DefaultSettingValidator = extend_with_default(Draft4Validator)
|
DefaultSettingValidator = extend_with_default(Draft4Validator)
|
||||||
|
|
||||||
|
|
||||||
def validate_section(data, schema):
|
def validate_section(data, schema):
|
||||||
"""Validate data read in from a Spack YAML file.
|
"""Validate data read in from a Spack YAML file.
|
||||||
|
|
||||||
@ -347,16 +347,14 @@ def get_section_filename(self, section):
|
|||||||
validate_section_name(section)
|
validate_section_name(section)
|
||||||
return os.path.join(self.path, "%s.yaml" % section)
|
return os.path.join(self.path, "%s.yaml" % section)
|
||||||
|
|
||||||
|
|
||||||
def get_section(self, section):
|
def get_section(self, section):
|
||||||
if not section in self.sections:
|
if section not in self.sections:
|
||||||
path = self.get_section_filename(section)
|
path = self.get_section_filename(section)
|
||||||
schema = section_schemas[section]
|
schema = section_schemas[section]
|
||||||
data = _read_config_file(path, schema)
|
data = _read_config_file(path, schema)
|
||||||
self.sections[section] = data
|
self.sections[section] = data
|
||||||
return self.sections[section]
|
return self.sections[section]
|
||||||
|
|
||||||
|
|
||||||
def write_section(self, section):
|
def write_section(self, section):
|
||||||
filename = self.get_section_filename(section)
|
filename = self.get_section_filename(section)
|
||||||
data = self.get_section(section)
|
data = self.get_section(section)
|
||||||
@ -370,7 +368,6 @@ def write_section(self, section):
|
|||||||
except (yaml.YAMLError, IOError) as e:
|
except (yaml.YAMLError, IOError) as e:
|
||||||
raise ConfigFileError("Error writing to config file: '%s'" % str(e))
|
raise ConfigFileError("Error writing to config file: '%s'" % str(e))
|
||||||
|
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
"""Empty cached config information."""
|
"""Empty cached config information."""
|
||||||
self.sections = {}
|
self.sections = {}
|
||||||
@ -476,7 +473,7 @@ def they_are(t):
|
|||||||
# Source dict is merged into dest.
|
# Source dict is merged into dest.
|
||||||
elif they_are(dict):
|
elif they_are(dict):
|
||||||
for sk, sv in source.iteritems():
|
for sk, sv in source.iteritems():
|
||||||
if not sk in dest:
|
if sk not in dest:
|
||||||
dest[sk] = copy.copy(sv)
|
dest[sk] = copy.copy(sv)
|
||||||
else:
|
else:
|
||||||
dest[sk] = _merge_yaml(dest[sk], source[sk])
|
dest[sk] = _merge_yaml(dest[sk], source[sk])
|
||||||
@ -545,7 +542,10 @@ def update_config(section, update_data, scope=None):
|
|||||||
# read in the config to ensure we've got current data
|
# read in the config to ensure we've got current data
|
||||||
configuration = get_config(section)
|
configuration = get_config(section)
|
||||||
|
|
||||||
configuration.update(update_data)
|
if isinstance(update_data, list):
|
||||||
|
configuration = update_data
|
||||||
|
else:
|
||||||
|
configuration.update(update_data)
|
||||||
|
|
||||||
# read only the requested section's data.
|
# read only the requested section's data.
|
||||||
scope.sections[section] = {section: configuration}
|
scope.sections[section] = {section: configuration}
|
||||||
@ -587,16 +587,20 @@ def spec_externals(spec):
|
|||||||
def is_spec_buildable(spec):
|
def is_spec_buildable(spec):
|
||||||
"""Return true if the spec pkgspec is configured as buildable"""
|
"""Return true if the spec pkgspec is configured as buildable"""
|
||||||
allpkgs = get_config('packages')
|
allpkgs = get_config('packages')
|
||||||
name = spec.name
|
if spec.name not in allpkgs:
|
||||||
if not spec.name in allpkgs:
|
|
||||||
return True
|
return True
|
||||||
if not 'buildable' in allpkgs[spec.name]:
|
if 'buildable' not in allpkgs[spec.name]:
|
||||||
return True
|
return True
|
||||||
return allpkgs[spec.name]['buildable']
|
return allpkgs[spec.name]['buildable']
|
||||||
|
|
||||||
|
|
||||||
class ConfigError(SpackError): pass
|
class ConfigError(SpackError):
|
||||||
class ConfigFileError(ConfigError): pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigFileError(ConfigError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_path(path, data):
|
def get_path(path, data):
|
||||||
if path:
|
if path:
|
||||||
@ -604,6 +608,7 @@ def get_path(path, data):
|
|||||||
else:
|
else:
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
class ConfigFormatError(ConfigError):
|
class ConfigFormatError(ConfigError):
|
||||||
"""Raised when a configuration format does not match its schema."""
|
"""Raised when a configuration format does not match its schema."""
|
||||||
def __init__(self, validation_error, data):
|
def __init__(self, validation_error, data):
|
||||||
@ -638,5 +643,6 @@ def __init__(self, validation_error, data):
|
|||||||
message = '%s: %s' % (location, validation_error.message)
|
message = '%s: %s' % (location, validation_error.message)
|
||||||
super(ConfigError, self).__init__(message)
|
super(ConfigError, self).__init__(message)
|
||||||
|
|
||||||
|
|
||||||
class ConfigSanityError(ConfigFormatError):
|
class ConfigSanityError(ConfigFormatError):
|
||||||
"""Same as ConfigFormatError, raised when config is written by Spack."""
|
"""Same as ConfigFormatError, raised when config is written by Spack."""
|
||||||
|
@ -72,6 +72,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Some Sample repo data
|
||||||
|
repos_low = [ "/some/path" ]
|
||||||
|
repos_high = [ "/some/other/path" ]
|
||||||
|
|
||||||
class ConfigTest(MockPackagesTest):
|
class ConfigTest(MockPackagesTest):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -95,6 +99,12 @@ def check_config(self, comps, arch, *compiler_names):
|
|||||||
actual = config[arch][key][c]
|
actual = config[arch][key][c]
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
|
def test_write_list_in_memory(self):
|
||||||
|
spack.config.update_config('repos', repos_low, 'test_low_priority')
|
||||||
|
spack.config.update_config('repos', repos_high, 'test_high_priority')
|
||||||
|
config = spack.config.get_config('repos')
|
||||||
|
self.assertEqual(config, repos_high+repos_low)
|
||||||
|
|
||||||
def test_write_key_in_memory(self):
|
def test_write_key_in_memory(self):
|
||||||
# Write b_comps "on top of" a_comps.
|
# Write b_comps "on top of" a_comps.
|
||||||
spack.config.update_config('compilers', a_comps, 'test_low_priority')
|
spack.config.update_config('compilers', a_comps, 'test_low_priority')
|
||||||
|
Loading…
Reference in New Issue
Block a user