From 5d477bc956e0033bd2816d48df1f4096856bc5fe Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Tue, 10 May 2016 23:19:30 +0200 Subject: fix setting config for list parameters --- lib/spack/spack/config.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index 336d47cbb7..06954f535b 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -545,7 +545,10 @@ def update_config(section, update_data, scope=None): # read in the config to ensure we've got current data configuration = get_config(section) - configuration.update(update_data) + if isinstance(update_data, list): + configuration = update_data + else: + configuration.extend(update_data) # read only the requested section's data. scope.sections[section] = {section: configuration} -- cgit v1.2.3-70-g09d2 From 6e462abb4d208584cb5f984f2f4c177bcec37dd4 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Tue, 10 May 2016 23:31:29 +0200 Subject: hmm... test before commit --- lib/spack/spack/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index 06954f535b..3bdefd3a6c 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -548,7 +548,7 @@ def update_config(section, update_data, scope=None): if isinstance(update_data, list): configuration = update_data else: - configuration.extend(update_data) + configuration.update(update_data) # read only the requested section's data. scope.sections[section] = {section: configuration} -- cgit v1.2.3-70-g09d2 From 05b6c3f8cfd065dcf4173613a64ed94fa1815d31 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Wed, 11 May 2016 00:14:24 +0200 Subject: add test for list parameters --- lib/spack/spack/test/config.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/spack/spack/test/config.py b/lib/spack/spack/test/config.py index 3977f0e7d4..ed0797a541 100644 --- a/lib/spack/spack/test/config.py +++ b/lib/spack/spack/test/config.py @@ -72,6 +72,10 @@ b_comps = { } } +# Some Sample repo data +repos_low = [ "/some/path" ] +repos_high = [ "/some/other/path" ] + class ConfigTest(MockPackagesTest): def setUp(self): @@ -95,6 +99,12 @@ class ConfigTest(MockPackagesTest): actual = config[arch][key][c] 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): # Write b_comps "on top of" a_comps. spack.config.update_config('compilers', a_comps, 'test_low_priority') -- cgit v1.2.3-70-g09d2 From c1e6b5218438988d7dc2da5ca577fe5a8752d6e1 Mon Sep 17 00:00:00 2001 From: Benedikt Hegner Date: Wed, 11 May 2016 00:28:12 +0200 Subject: first round of coding rules --- lib/spack/spack/config.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index 3bdefd3a6c..9da5d7aaf0 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -129,7 +129,6 @@ from ordereddict_backport import OrderedDict import llnl.util.tty as tty from llnl.util.filesystem import mkdirp -import copy import spack from spack.error import SpackError @@ -306,13 +305,14 @@ def extend_with_default(validator_class): yield err return validators.extend(validator_class, { - "properties" : set_defaults, - "patternProperties" : set_pp_defaults + "properties": set_defaults, + "patternProperties": set_pp_defaults }) DefaultSettingValidator = extend_with_default(Draft4Validator) + def validate_section(data, schema): """Validate data read in from a Spack YAML file. @@ -347,16 +347,14 @@ class ConfigScope(object): validate_section_name(section) return os.path.join(self.path, "%s.yaml" % section) - def get_section(self, section): - if not section in self.sections: + if section not in self.sections: path = self.get_section_filename(section) schema = section_schemas[section] data = _read_config_file(path, schema) self.sections[section] = data return self.sections[section] - def write_section(self, section): filename = self.get_section_filename(section) data = self.get_section(section) @@ -370,7 +368,6 @@ class ConfigScope(object): except (yaml.YAMLError, IOError) as e: raise ConfigFileError("Error writing to config file: '%s'" % str(e)) - def clear(self): """Empty cached config information.""" self.sections = {} @@ -476,7 +473,7 @@ def _merge_yaml(dest, source): # Source dict is merged into dest. elif they_are(dict): for sk, sv in source.iteritems(): - if not sk in dest: + if sk not in dest: dest[sk] = copy.copy(sv) else: dest[sk] = _merge_yaml(dest[sk], source[sk]) @@ -590,16 +587,20 @@ def spec_externals(spec): def is_spec_buildable(spec): """Return true if the spec pkgspec is configured as buildable""" allpkgs = get_config('packages') - name = spec.name - if not spec.name in allpkgs: + if spec.name not in allpkgs: return True - if not 'buildable' in allpkgs[spec.name]: + if 'buildable' not in allpkgs[spec.name]: return True return allpkgs[spec.name]['buildable'] -class ConfigError(SpackError): pass -class ConfigFileError(ConfigError): pass +class ConfigError(SpackError): + pass + + +class ConfigFileError(ConfigError): + pass + def get_path(path, data): if path: @@ -607,6 +608,7 @@ def get_path(path, data): else: return data + class ConfigFormatError(ConfigError): """Raised when a configuration format does not match its schema.""" def __init__(self, validation_error, data): @@ -641,5 +643,6 @@ class ConfigFormatError(ConfigError): message = '%s: %s' % (location, validation_error.message) super(ConfigError, self).__init__(message) + class ConfigSanityError(ConfigFormatError): """Same as ConfigFormatError, raised when config is written by Spack.""" -- cgit v1.2.3-70-g09d2