Skip to content

Commit

Permalink
rework get_config_dict to accept 'toolchain' key in build specs
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Jan 21, 2014
1 parent f7a1fe5 commit ffce5b1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
24 changes: 6 additions & 18 deletions easybuild/framework/easyconfig/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions easybuild/framework/easyconfig/format/one.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions easybuild/framework/easyconfig/format/two.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,23 @@ 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)
else:
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)

Expand Down
26 changes: 18 additions & 8 deletions easybuild/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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})

This comment has been minimized.

Copy link
@stdweird

stdweird Jan 21, 2014

build_specs[key]=opt ....

This comment has been minimized.

Copy link
@boegel

boegel Jan 21, 2014

Author Owner

urgh, wtf is wrong with me :)

# 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})

This comment has been minimized.

Copy link
@stdweird

stdweird Jan 21, 2014

idem

# only when a try option is set do we enable generating easyconfigs
try_to_generate = True

Expand All @@ -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:
Expand All @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ffce5b1

Please sign in to comment.