Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

derive EasyBuildError from LoggedException, deprecate log.error in favor of raise EasyBuildError #1218

Merged
merged 17 commits into from
Mar 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 68 additions & 61 deletions easybuild/framework/easyblock.py

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion easybuild/framework/easyconfig/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"""
from vsc.utils import fancylogger

from easybuild.tools.build_log import EasyBuildError


_log = fancylogger.getLogger('easyconfig.default', fname=False)

Expand Down Expand Up @@ -180,7 +182,7 @@ def sorted_categories():
def get_easyconfig_parameter_default(param):
"""Get default value for given easyconfig parameter."""
if param not in DEFAULT_CONFIG:
_log.error("Unkown easyconfig parameter: %s (known: %s)" % (param, sorted(DEFAULT_CONFIG.keys())))
raise EasyBuildError("Unkown easyconfig parameter: %s (known: %s)", param, sorted(DEFAULT_CONFIG.keys()))
else:
_log.debug("Returning default value for easyconfig parameter %s: %s" % (param, DEFAULT_CONFIG[param][0]))
return DEFAULT_CONFIG[param][0]
102 changes: 53 additions & 49 deletions easybuild/framework/easyconfig/easyconfig.py

Large diffs are not rendered by default.

53 changes: 26 additions & 27 deletions easybuild/framework/easyconfig/format/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from easybuild.framework.easyconfig.format.version import EasyVersion, OrderedVersionOperators
from easybuild.framework.easyconfig.format.version import ToolchainVersionOperator, VersionOperator
from easybuild.framework.easyconfig.format.convert import Dependency
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.configobj import Section


Expand All @@ -59,7 +60,7 @@ def get_format_version(txt):
maj_min = res.groupdict()
format_version = EasyVersion(FORMAT_VERSION_TEMPLATE % maj_min)
except (KeyError, TypeError), err:
_log.error("Failed to get version from match %s: %s" % (res.groups(), err))
raise EasyBuildError("Failed to get version from match %s: %s", res.groups(), err)
return format_version


Expand Down Expand Up @@ -242,13 +243,13 @@ def parse_sections(self, toparse, current):
new_value = []
for dep_name, dep_val in value.items():
if isinstance(dep_val, Section):
self.log.error("Unsupported nested section '%s' found in dependencies section" % dep_name)
raise EasyBuildError("Unsupported nested section '%s' in dependencies section", dep_name)
else:
# FIXME: parse the dependency specification for version, toolchain, suffix, etc.
dep = Dependency(dep_val, name=dep_name)
if dep.name() is None or dep.version() is None:
tmpl = "Failed to find name/version in parsed dependency: %s (dict: %s)"
self.log.error(tmpl % (dep, dict(dep)))
raise EasyBuildError("Failed to find name/version in parsed dependency: %s (dict: %s)",
dep, dict(dep))
new_value.append(dep)

tmpl = 'Converted dependency section %s to %s, passed it to parent section (or default)'
Expand All @@ -268,7 +269,7 @@ def parse_sections(self, toparse, current):
else:
self.log.debug("Not a %s section marker" % marker_type.__name__)
if not new_key:
self.log.error("Unsupported section marker '%s'" % key)
raise EasyBuildError("Unsupported section marker '%s'", key)

# parse value as a section, recursively
new_value = self.parse_sections(value, current.get_nested_dict())
Expand Down Expand Up @@ -296,10 +297,10 @@ def parse_sections(self, toparse, current):
# remove possible surrounding whitespace (some people add space after comma)
new_value = [value_type(x.strip()) for x in value]
if False in [x.is_valid() for x in new_value]:
self.log.error("Failed to parse '%s' as list of %s" % (value, value_type.__name__))
raise EasyBuildError("Failed to parse '%s' as list of %s", value, value_type.__name__)
else:
tup = (key, value, type(value))
self.log.error('Bug: supported but unknown key %s with non-string value: %s, type %s' % tup)
raise EasyBuildError('Bug: supported but unknown key %s with non-string value: %s, type %s',
key, value, type(value))

self.log.debug("Converted value '%s' for key '%s' into new value '%s'" % (value, key, new_value))
current[key] = new_value
Expand Down Expand Up @@ -334,7 +335,7 @@ def parse(self, configobj):
self.supported = self.sections.pop(self.SECTION_MARKER_SUPPORTED)
for key, value in self.supported.items():
if not key in self.VERSION_OPERATOR_VALUE_TYPES:
self.log.error('Unsupported key %s in %s section' % (key, self.SECTION_MARKER_SUPPORTED))
raise EasyBuildError('Unsupported key %s in %s section', key, self.SECTION_MARKER_SUPPORTED)
self.sections['%s' % key] = value

for key, supported_key, fn_name in [('version', 'versions', 'get_version_str'),
Expand All @@ -344,7 +345,7 @@ def parse(self, configobj):
first = self.supported[supported_key][0]
f_val = getattr(first, fn_name)()
if f_val is None:
self.log.error("First %s %s can't be used as default (%s returned None)" % (key, first, fn_name))
raise EasyBuildError("First %s %s can't be used as default (%s returned None)", key, first, fn_name)
else:
self.log.debug('Using first %s (%s) as default %s' % (key, first, f_val))
self.default[key] = f_val
Expand Down Expand Up @@ -438,8 +439,7 @@ def _squash_netsed_dict(self, key, nested_dict, squashed, sanity, vt_tuple):
tc_overops.add(key)

if key.test(tcname, tcversion):
tup = (tcname, tcversion, key)
self.log.debug("Found matching marker for specified toolchain '%s, %s': %s" % tup)
self.log.debug("Found matching marker for specified toolchain '%s, %s': %s", tcname, tcversion, key)
# TODO remove when unifying add_toolchina with .add()
tmp_squashed = self._squash(vt_tuple, nested_dict, sanity)
res_sections.update(tmp_squashed.result)
Expand All @@ -456,7 +456,7 @@ def _squash_netsed_dict(self, key, nested_dict, squashed, sanity, vt_tuple):
else:
self.log.debug('Found non-matching version marker %s. Ignoring this (nested) section.' % key)
else:
self.log.error("Unhandled section marker '%s' (type '%s')" % (key, type(key)))
raise EasyBuildError("Unhandled section marker '%s' (type '%s')", key, type(key))

return res_sections

Expand All @@ -479,8 +479,8 @@ def _squash_versop(self, key, value, squashed, sanity, vt_tuple):
tmp_tc_oversops = {} # temporary, only for conflict checking
for tcversop in value:
tc_overops = tmp_tc_oversops.setdefault(tcversop.tc_name, OrderedVersionOperators())
tup = (tcversop, tc_overops, tcname, tcversion)
self.log.debug('Add tcversop %s to tc_overops %s tcname %s tcversion %s' % tup)
self.log.debug("Add tcversop %s to tc_overops %s tcname %s tcversion %s",
tcversop, tc_overops, tcname, tcversion)
tc_overops.add(tcversop) # test non-conflicting list
if tcversop.test(tcname, tcversion):
matching_toolchains.append(tcversop)
Expand All @@ -507,7 +507,7 @@ def _squash_versop(self, key, value, squashed, sanity, vt_tuple):
self.log.debug('No matching versions, removing the whole current key %s' % key)
return Squashed()
else:
self.log.error('Unexpected VERSION_OPERATOR_VALUE_TYPES key %s value %s' % (key, value))
raise EasyBuildError('Unexpected VERSION_OPERATOR_VALUE_TYPES key %s value %s', key, value)

return None

Expand All @@ -520,41 +520,40 @@ def get_version_toolchain(self, version=None, tcname=None, tcversion=None):
version = self.default['version']
self.log.debug("No version specified, using default %s" % version)
else:
self.log.error("No version specified, no default found.")
raise EasyBuildError("No version specified, no default found.")
elif version in versions:
self.log.debug("Version '%s' is supported in easyconfig." % version)
else:
self.log.error("Version '%s' not supported in easyconfig (only %s)" % (version, versions))
raise EasyBuildError("Version '%s' not supported in easyconfig (only %s)", version, versions)

tcnames = [tc.tc_name for tc in self.supported['toolchains']]
if tcname is None:
if 'toolchain' in self.default and 'name' in self.default['toolchain']:
tcname = self.default['toolchain']['name']
self.log.debug("No toolchain name specified, using default %s" % tcname)
else:
self.log.error("No toolchain name specified, no default found.")
raise EasyBuildError("No toolchain name specified, no default found.")
elif tcname in tcnames:
self.log.debug("Toolchain '%s' is supported in easyconfig." % tcname)
else:
self.log.error("Toolchain '%s' not supported in easyconfig (only %s)" % (tcname, tcnames))
raise EasyBuildError("Toolchain '%s' not supported in easyconfig (only %s)", tcname, tcnames)

tcs = [tc for tc in self.supported['toolchains'] if tc.tc_name == tcname]
if tcversion is None:
if 'toolchain' in self.default and 'version' in self.default['toolchain']:
tcversion = self.default['toolchain']['version']
self.log.debug("No toolchain version specified, using default %s" % tcversion)
else:
self.log.error("No toolchain version specified, no default found.")
raise EasyBuildError("No toolchain version specified, no default found.")
elif any([tc.test(tcname, tcversion) for tc in tcs]):
self.log.debug("Toolchain '%s' version '%s' is supported in easyconfig" % (tcname, tcversion))
else:
tup = (tcname, tcversion, tcs)
self.log.error("Toolchain '%s' version '%s' not supported in easyconfig (only %s)" % tup)
raise EasyBuildError("Toolchain '%s' version '%s' not supported in easyconfig (only %s)",
tcname, tcversion, tcs)

tup = (version, tcname, tcversion)
self.log.debug('version %s, tcversion %s, tcname %s' % tup)
self.log.debug('version %s, tcversion %s, tcname %s', version, tcname, tcversion)

return tup
return (version, tcname, tcversion)

def get_specs_for(self, version=None, tcname=None, tcversion=None):
"""
Expand All @@ -578,7 +577,7 @@ def __init__(self):
self.log = fancylogger.getLogger(self.__class__.__name__, fname=False)

if not len(self.VERSION) == len(FORMAT_VERSION_TEMPLATE.split('.')):
self.log.error('Invalid version number %s (incorrect length)' % self.VERSION)
raise EasyBuildError('Invalid version number %s (incorrect length)', self.VERSION)

self.rawtext = None # text version of the easyconfig
self.header = None # easyconfig header (e.g., format version, license, ...)
Expand Down
15 changes: 7 additions & 8 deletions easybuild/framework/easyconfig/format/one.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from easybuild.framework.easyconfig.format.format import FORMAT_DEFAULT_VERSION, get_format_version
from easybuild.framework.easyconfig.format.pyheaderconfigobj import EasyConfigFormatConfigObj
from easybuild.framework.easyconfig.format.version import EasyVersion
from easybuild.tools.build_log import print_msg
from easybuild.tools.build_log import EasyBuildError, print_msg
from easybuild.tools.filetools import write_file


Expand Down Expand Up @@ -71,14 +71,14 @@ def get_config_dict(self):
spec_tc_version = spec_tc.get('version', None)
cfg = self.pyheader_localvars
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']))
raise EasyBuildError('Requested version %s not available, only %s', spec_version, cfg['version'])

tc_name = cfg['toolchain']['name']
tc_version = cfg['toolchain']['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))
raise EasyBuildError('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))
raise EasyBuildError('Requested toolchain version %s not available, only %s', spec_tc_version, tc_version)

return cfg

Expand All @@ -102,7 +102,7 @@ def retrieve_blocks_in_spec(spec, only_blocks, silent=False):
try:
txt = open(spec).read()
except IOError, err:
_log.error("Failed to read file %s: %s" % (spec, err))
raise EasyBuildError("Failed to read file %s: %s", spec, err)

# split into blocks using regex
pieces = reg_block.split(txt)
Expand All @@ -124,8 +124,7 @@ def retrieve_blocks_in_spec(spec, only_blocks, silent=False):
block_contents = pieces.pop(0)

if block_name in [b['name'] for b in blocks]:
msg = "Found block %s twice in %s." % (block_name, spec)
_log.error(msg)
raise EasyBuildError("Found block %s twice in %s.", block_name, spec)

block = {'name': block_name, 'contents': block_contents}

Expand Down Expand Up @@ -157,7 +156,7 @@ def retrieve_blocks_in_spec(spec, only_blocks, silent=False):
if 'dependencies' in block:
for dep in block['dependencies']:
if not dep in [b['name'] for b in blocks]:
_log.error("Block %s depends on %s, but block was not found." % (name, dep))
raise EasyBuildError("Block %s depends on %s, but block was not found.", name, dep)

dep = [b for b in blocks if b['name'] == dep][0]
txt += "\n# Dependency block %s" % (dep['name'])
Expand Down
21 changes: 11 additions & 10 deletions easybuild/framework/easyconfig/format/pyheaderconfigobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from easybuild.framework.easyconfig.format.format import get_format_version, EasyConfigFormat
from easybuild.framework.easyconfig.licenses import EASYCONFIG_LICENSES_DICT
from easybuild.framework.easyconfig.templates import TEMPLATE_CONSTANTS
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.configobj import ConfigObj
from easybuild.tools.systemtools import get_shared_lib_ext

Expand Down Expand Up @@ -68,7 +69,7 @@ def build_easyconfig_constants_dict():
const_dict[cst_key] = cst_val

if len(err) > 0:
_log.error("EasyConfig constants sanity check failed: %s" % ("\n".join(err)))
raise EasyBuildError("EasyConfig constants sanity check failed: %s", '\n'.join(err))
else:
return const_dict

Expand Down Expand Up @@ -128,8 +129,8 @@ def parse(self, txt, strict_section_markers=False):
last_n = 100
pre_section_tail = txt[start_section-last_n:start_section]
sections_head = txt[start_section:start_section+last_n]
tup = (start_section, last_n, pre_section_tail, sections_head)
self.log.debug('Sections start at index %s, %d-chars context:\n"""%s""""\n<split>\n"""%s..."""' % tup)
self.log.debug('Sections start at index %s, %d-chars context:\n"""%s""""\n<split>\n"""%s..."""',
start_section, last_n, pre_section_tail, sections_head)

self.parse_pre_section(txt[:start_section])
if start_section is not None:
Expand All @@ -148,7 +149,7 @@ def parse_pre_section(self, txt):
format_version = get_format_version(line)
if format_version is not None:
if not format_version == self.VERSION:
self.log.error("Invalid format version %s for current format class" % format_version)
raise EasyBuildError("Invalid format version %s for current format class", format_version)
else:
self.log.info("Valid format version %s found" % format_version)
# version is not part of header
Expand Down Expand Up @@ -185,7 +186,7 @@ def parse_pyheader(self, pyheader):
try:
exec(pyheader, global_vars, local_vars)
except SyntaxError, err:
self.log.error("SyntaxError in easyconfig pyheader %s: %s" % (pyheader, err))
raise EasyBuildError("SyntaxError in easyconfig pyheader %s: %s", pyheader, err)

self.log.debug("pyheader final global_vars %s" % global_vars)
self.log.debug("pyheader final local_vars %s" % local_vars)
Expand Down Expand Up @@ -230,14 +231,14 @@ def _validate_pyheader(self):
blacklisted parameters are not allowed, mandatory parameters are mandatory unless blacklisted
"""
if self.pyheader_localvars is None:
self.log.error("self.pyheader_localvars must be initialized")
raise EasyBuildError("self.pyheader_localvars must be initialized")
if self.PYHEADER_BLACKLIST is None or self.PYHEADER_MANDATORY is None:
self.log.error('Both PYHEADER_BLACKLIST and PYHEADER_MANDATORY must be set')
raise EasyBuildError('Both PYHEADER_BLACKLIST and PYHEADER_MANDATORY must be set')

for param in self.PYHEADER_BLACKLIST:
if param in self.pyheader_localvars:
# TODO add to easyconfig unittest (similar to mandatory)
self.log.error('blacklisted param %s not allowed in pyheader' % param)
raise EasyBuildError('blacklisted param %s not allowed in pyheader', param)

missing = []
for param in self.PYHEADER_MANDATORY:
Expand All @@ -246,13 +247,13 @@ def _validate_pyheader(self):
if not param in self.pyheader_localvars:
missing.append(param)
if missing:
self.log.error('mandatory parameters not provided in pyheader: %s' % ', '.join(missing))
raise EasyBuildError('mandatory parameters not provided in pyheader: %s', ', '.join(missing))

def parse_section_block(self, section):
"""Parse the section block by trying to convert it into a ConfigObj instance"""
try:
self.configobj = ConfigObj(section.split('\n'))
except SyntaxError, err:
self.log.error('Failed to convert section text %s: %s' % (section, err))
raise EasyBuildError('Failed to convert section text %s: %s', section, err)

self.log.debug("Found ConfigObj instance %s" % self.configobj)
5 changes: 3 additions & 2 deletions easybuild/framework/easyconfig/format/two.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from easybuild.framework.easyconfig.format.pyheaderconfigobj import EasyConfigFormatConfigObj
from easybuild.framework.easyconfig.format.format import EBConfigObj
from easybuild.framework.easyconfig.format.version import EasyVersion, ToolchainVersionOperator, VersionOperator
from easybuild.tools.build_log import EasyBuildError


class FormatTwoZero(EasyConfigFormatConfigObj):
Expand Down Expand Up @@ -89,10 +90,10 @@ def _check_docstring(self):
maintainers.append(res['name'])

if self.AUTHOR_REQUIRED and not authors:
self.log.error("No author in docstring (regex: '%s')" % self.AUTHOR_DOCSTRING_REGEX.pattern)
raise EasyBuildError("No author in docstring (regex: '%s')", self.AUTHOR_DOCSTRING_REGEX.pattern)

if self.MAINTAINER_REQUIRED and not maintainers:
self.log.error("No maintainer in docstring (regex: '%s')" % self.MAINTAINER_DOCSTRING_REGEX.pattern)
raise EasyBuildError("No maintainer in docstring (regex: '%s')", self.MAINTAINER_DOCSTRING_REGEX.pattern)

def get_config_dict(self):
"""Return the best matching easyconfig dict"""
Expand Down
Loading