From ffce5b15386400f489fc11b1430441cea27031d2 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Tue, 21 Jan 2014 11:32:37 +0100 Subject: [PATCH] rework get_config_dict to accept 'toolchain' key in build specs --- easybuild/framework/easyconfig/easyconfig.py | 24 +++++------------- easybuild/framework/easyconfig/format/one.py | 19 +++++++------- easybuild/framework/easyconfig/format/two.py | 7 +++--- easybuild/main.py | 26 ++++++++++++++------ test/framework/easyconfig.py | 8 +++--- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/easybuild/framework/easyconfig/easyconfig.py b/easybuild/framework/easyconfig/easyconfig.py index bb35f002d6..426d0dbfc3 100644 --- a/easybuild/framework/easyconfig/easyconfig.py +++ b/easybuild/framework/easyconfig/easyconfig.py @@ -87,11 +87,10 @@ def __init__(self, path, extra_options=None, build_options=None, build_specs=Non self.log = fancylogger.getLogger(self.__class__.__name__, fname=False) - self.valid_module_classes = build_options.get('valid_module_classes', None) - if self.valid_module_classes: + # use legacy module classes as default + self.valid_module_classes = build_options.get('valid_module_classes', ['base', 'compiler', 'lib']) + if 'valid_module_classes' in build_options: self.log.info("Obtained list of valid module classes: %s" % self.valid_module_classes) - else: - self.valid_module_classes = ['base', 'compiler', 'lib'] # legacy module classes # replace the category name with the category self._config = {} @@ -118,8 +117,7 @@ def __init__(self, path, extra_options=None, build_options=None, build_specs=Non # set valid stops self.valid_stops = build_options.get('valid_stops', []) - if self.valid_stops: - self.log.debug("List of valid stops obtained: %s" % self.valid_stops) + self.log.debug("Non-empty list of valid stops obtained: %s" % self.valid_stops) # store toolchain self._toolchain = None @@ -204,20 +202,10 @@ def parse(self): arg_specs = {} elif isinstance(self.build_specs, dict): # build a new dictionary with only the expected keys, to pass as named arguments to get_config_dict() - arg_specs = {} - for key in ['toolchain_name', 'toolchain_version', 'version']: - if key in self.build_specs: - arg_specs[key] = self.build_specs[key] - if 'toolchain' in self.build_specs: - tc = self.build_specs['toolchain'] - if isinstance(tc, dict) and 'name' in tc and 'version' in tc: - arg_specs['toolchain_name'] = tc['name'] - arg_specs['toolchain_version'] = tc['version'] - else: - self.log.error("Wrong toolchain specification '%s', should be dict with 'name'/'version' keys." % tc) - self.log.debug("Constructed specs dict %s from obtained dict %s" % (arg_specs, self.build_specs)) + arg_specs = self.build_specs else: self.log.error("Specifications should be specified using a dictionary, got %s" % type(self.build_specs)) + self.log.debug("Obtained specs dict %s" % arg_specs) parser = EasyConfigParser(self.path) parser.set_specifications(arg_specs) diff --git a/easybuild/framework/easyconfig/format/one.py b/easybuild/framework/easyconfig/format/one.py index bafb7edf86..c021a9f537 100644 --- a/easybuild/framework/easyconfig/format/one.py +++ b/easybuild/framework/easyconfig/format/one.py @@ -64,19 +64,20 @@ def get_config_dict(self): Return parsed easyconfig as a dictionary, based on specified arguments. This is easyconfig format 1.x, so there is only one easyconfig instance available. """ - version = self.specs.get('version', None) - toolchain_name = self.specs.get('toolchain_name', None) - toolchain_version = self.specs.get('toolchain_version', None) + spec_version = self.specs.get('version', None) + spec_tc = self.specs.get('toolchain', {}) + spec_tc_name = spec_tc.get('name', None) + spec_tc_version = spec_tc.get('version', None) cfg = self.pyheader_localvars - if version is not None and not version == cfg['version']: - self.log.error('Requested version %s not available, only %s' % (version, cfg['version'])) + if spec_version is not None and not spec_version == cfg['version']: + self.log.error('Requested version %s not available, only %s' % (spec_version, cfg['version'])) tc_name = cfg['toolchain']['name'] tc_version = cfg['toolchain']['version'] - if toolchain_name is not None and not toolchain_name == tc_name: - self.log.error('Requested toolchain name %s not available, only %s' % (toolchain_name, tc_name)) - if toolchain_version is not None and not toolchain_version == tc_version: - self.log.error('Requested toolchain version %s not available, only %s' % (toolchain_version, tc_version)) + if spec_tc_name is not None and not spec_tc_name == tc_name: + self.log.error('Requested toolchain name %s not available, only %s' % (spec_tc_name, tc_name)) + if spec_tc_version is not None and not spec_tc_version == tc_version: + self.log.error('Requested toolchain version %s not available, only %s' % (spec_tc_version, tc_version)) return cfg diff --git a/easybuild/framework/easyconfig/format/two.py b/easybuild/framework/easyconfig/format/two.py index a76f3e7984..74a0b3c45b 100644 --- a/easybuild/framework/easyconfig/format/two.py +++ b/easybuild/framework/easyconfig/format/two.py @@ -116,14 +116,15 @@ def get_config_dict(self): else: self.log.debug("Using specified software version %s" % version) - toolchain_name = self.specs.get('toolchain_name', None) + tc_spec = self.specs.get('toolchain', {}) + toolchain_name = tc_spec.get('name', None) if toolchain_name is None: # check for default toolchain if 'default_toolchain' in cov.default: toolchain = cov.default['default_toolchain'] toolchain_name = toolchain.tc_name self.log.info("no toolchain name specified, using default '%s'" % toolchain_name) - toolchain_version = self.specs.get('toolchain_version', None) + toolchain_version = tc_spec.get('version', None) if toolchain_version is None: toolchain_version = toolchain.get_version_str() self.log.info("no toolchain version specified, using default '%s'" % toolchain_version) @@ -131,7 +132,7 @@ def get_config_dict(self): self.log.error("no toolchain name specified, no default toolchain found") else: self.log.debug("Using specified toolchain name %s" % toolchain_name) - toolchain_version = self.specs.get('toolchain_version', None) + toolchain_version = tc_spec.get('version', None) if toolchain_version is None: self.log.error("Toolchain specification incomplete: name %s provided, but no version" % toolchain_name) diff --git a/easybuild/main.py b/easybuild/main.py index 6c8eca48e1..85106b1d1e 100644 --- a/easybuild/main.py +++ b/easybuild/main.py @@ -642,7 +642,7 @@ def process_software_build_specs(options): """ try_to_generate = False - buildopts = {} + build_specs = {} # regular options: don't try to generate easyconfig, and search opts_map = { @@ -663,13 +663,13 @@ def process_software_build_specs(options): # process easy options for (key, opt) in opts_map.items(): if opt: - buildopts.update({key: opt}) + build_specs.update({key: opt}) # remove this key from the dict of try-options (overruled) try_opts_map.pop(key) for (key, opt) in try_opts_map.items(): if opt: - buildopts.update({key: opt}) + build_specs.update({key: opt}) # only when a try option is set do we enable generating easyconfigs try_to_generate = True @@ -680,9 +680,19 @@ def process_software_build_specs(options): print_warning("Ignoring --try-toolchain, only using --toolchain specification.") elif options.try_toolchain: try_to_generate = True - buildopts.update({'toolchain_name': tc[0], - 'toolchain_version': tc[1], - }) + build_specs.update({ + 'toolchain_name': tc[0], + 'toolchain_version': tc[1], + }) + + # provide both toolchain and toolchain_name/toolchain_version keys + if 'toolchain_name' in build_specs: + build_specs.update({ + 'toolchain': { + 'name': build_specs['toolchain_name'], + 'version': build_specs.get('toolchain_version', None), + }, + }) # process --amend and --try-amend if options.amend or options.try_amend: @@ -704,9 +714,9 @@ def process_software_build_specs(options): # e.g., 'foo=bar,baz' => foo = ['bar', 'baz'] if ',' in value: value = value.split(',') - buildopts.update({param: value}) + build_specs.update({param: value}) - return (try_to_generate, buildopts) + return (try_to_generate, build_specs) def obtain_path(specs, paths, try_to_generate=False, exit_on_error=True, silent=False): diff --git a/test/framework/easyconfig.py b/test/framework/easyconfig.py index 799aee7c51..d54c26db4f 100644 --- a/test/framework/easyconfig.py +++ b/test/framework/easyconfig.py @@ -802,10 +802,10 @@ def test_format_equivalence_basic(self): for eb_file1, eb_file2, specs in [ ('gzip-1.4.eb', 'gzip.eb', {}), ('gzip-1.4.eb', 'gzip.eb', {'version': '1.4'}), - ('gzip-1.4.eb', 'gzip.eb', {'version': '1.4', 'toolchain_name': 'dummy', 'toolchain_version': 'dummy'}), - ('gzip-1.4-GCC-4.6.3.eb', 'gzip.eb', {'version': '1.4', 'toolchain_name': 'GCC', 'toolchain_version': '4.6.3'}), - ('gzip-1.5-goolf-1.4.10.eb', 'gzip.eb', {'version': '1.5', 'toolchain_name': 'goolf', 'toolchain_version': '1.4.10'}), - ('gzip-1.5-ictce-4.1.13.eb', 'gzip.eb', {'version': '1.5', 'toolchain_name': 'ictce', 'toolchain_version': '4.1.13'}), + ('gzip-1.4.eb', 'gzip.eb', {'version': '1.4', 'toolchain': {'name': 'dummy', 'version': 'dummy'}}), + ('gzip-1.4-GCC-4.6.3.eb', 'gzip.eb', {'version': '1.4', 'toolchain': {'name': 'GCC', 'version': '4.6.3'}}), + ('gzip-1.5-goolf-1.4.10.eb', 'gzip.eb', {'version': '1.5', 'toolchain': {'name': 'goolf', 'version': '1.4.10'}}), + ('gzip-1.5-ictce-4.1.13.eb', 'gzip.eb', {'version': '1.5', 'toolchain': {'name': 'ictce', 'version': '4.1.13'}}), ]: ec1 = EasyConfig(os.path.join(easyconfigs_path, 'v1.0', eb_file1), build_options=build_options) ec2 = EasyConfig(os.path.join(easyconfigs_path, 'v2.0', eb_file2), build_options=build_options, build_specs=specs)