How to use the easybuild.tools.build_log.EasyBuildError function in easybuild

To help you get started, we’ve selected a few easybuild examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github easybuilders / easybuild-framework / test / framework / robot.py View on Github external
self.assertTrue('intel/2018a' in full_mod_names)

        # here we have included a dependency in the easyconfig list
        easyconfig['full_mod_name'] = 'gzip/1.4'

        ecs = [deepcopy(easyconfig_dep), deepcopy(easyconfig)]
        build_options.update({'robot_path': None})
        init_config(build_options=build_options)
        res = resolve_dependencies(ecs, self.modtool)
        # all dependencies should be resolved
        self.assertEqual(0, sum(len(ec['dependencies']) for ec in res))

        # this should not resolve (cannot find gzip-1.4.eb), both with and without robot enabled
        ecs = [deepcopy(easyconfig_dep)]
        msg = "Missing dependencies"
        self.assertErrorRegex(EasyBuildError, msg, resolve_dependencies, ecs, self.modtool)

        # test if dependencies of an automatically found file are also loaded
        easyconfig_dep['dependencies'] = [{
            'name': 'gzip',
            'version': '1.4',
            'versionsuffix': '',
            'toolchain': {'name': 'GCC', 'version': '4.6.3'},
            'dummy': True,
            'hidden': False,
        }]
        ecs = [deepcopy(easyconfig_dep)]
        build_options.update({'robot_path': base_easyconfig_dir})
        init_config(build_options=build_options)
        res = resolve_dependencies([deepcopy(easyconfig_dep)], self.modtool)

        # GCC should be first (required by gzip dependency)
github easybuilders / easybuild-framework / easybuild / framework / easyconfig / format / format.py View on Github external
# parse individual key-value assignments
                elif key in self.VERSION_OPERATOR_VALUE_TYPES:
                    value_type = self.VERSION_OPERATOR_VALUE_TYPES[key]
                    # list of supported toolchains/versions
                    # first one is default
                    if isinstance(value, string_type):
                        # so the split should be unnecessary
                        # (if it's not a list already, it's just one value)
                        # TODO this is annoying. check if we can force this in configobj
                        value = value.split(',')
                    # 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]:
                        raise EasyBuildError("Failed to parse '%s' as list of %s", value, value_type.__name__)
                else:
                    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

        return current
github easybuilders / easybuild-framework / easybuild / tools / repository / repository.py View on Github external
"""Return an instance of the selected repository class."""
    inited_repo = None
    if isinstance(repository, Repository):
        inited_repo = repository
    elif isinstance(repository, basestring):
        repo = avail_repositories().get(repository)
        try:
            if isinstance(repository_path, basestring):
                inited_repo = repo(repository_path)
            elif isinstance(repository_path, (tuple, list)) and len(repository_path) <= 2:
                inited_repo = repo(*repository_path)
            else:
                raise EasyBuildError("repository_path should be a string or list/tuple of maximum 2 elements "
                                     "(current: %s, type %s)", repository_path, type(repository_path))
        except Exception, err:
            raise EasyBuildError("Failed to create a repository instance for %s (class %s) with args %s (msg: %s)",
                                 repository, repo.__name__, repository_path, err)
    else:
        raise EasyBuildError("Unknown typo of repository spec: %s (type %s)", repo, type(repo))

    inited_repo.init()
    return inited_repo
github easybuilders / easybuild-framework / easybuild / framework / easyblock.py View on Github external
if not len(patch_spec) == 2:
                    raise EasyBuildError("Unknown patch specification '%s', only 2-element lists/tuples are supported!",
                                         str(patch_spec))
                patch_file = patch_spec[0]

                # this *must* be of typ int, nothing else
                # no 'isinstance(..., int)', since that would make True/False also acceptable
                if type(patch_spec[1]) == int:
                    level = patch_spec[1]
                elif isinstance(patch_spec[1], basestring):
                    # non-patch files are assumed to be files to copy
                    if not patch_spec[0].endswith('.patch'):
                        copy_file = True
                    suff = patch_spec[1]
                else:
                    raise EasyBuildError("Wrong patch spec '%s', only int/string are supported as 2nd element",
                                         str(patch_spec))
            else:
                patch_file = patch_spec

            path = self.obtain_file(patch_file, extension=extension)
            if path:
                self.log.debug('File %s found for patch %s' % (path, patch_spec))
                patchspec = {
                    'name': patch_file,
                    'path': path,
                    'checksum': self.get_checksum_for(checksums, filename=patch_file, index=index),
                }
                if suff:
                    if copy_file:
                        patchspec['copy'] = suff
                    else:
github easybuilders / easybuild-framework / easybuild / framework / easyconfig / format / format.py View on Github external
# handle supported section
        # supported should only have 'versions' and 'toolchains' keys
        self.supported = self.sections.pop(self.SECTION_MARKER_SUPPORTED)
        for key, value in self.supported.items():
            if key not in self.VERSION_OPERATOR_VALUE_TYPES:
                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'),
                                            ('toolchain', 'toolchains', 'as_dict')]:
            if supported_key in self.supported:
                self.log.debug('%s in supported section, trying to determine default for %s' % (supported_key, key))
                first = self.supported[supported_key][0]
                f_val = getattr(first, fn_name)()
                if f_val is None:
                    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

        # TODO is it verified somewhere that the defaults are supported?

        self.log.debug("(parse) supported: %s" % self.supported)
        self.log.debug("(parse) default: %s" % self.default)
        self.log.debug("(parse) sections: %s" % self.sections)
github easybuilders / easybuild-framework / easybuild / tools / repository / hgrepo.py View on Github external
def setup_repo(self):
        """
        Set up mercurial repository.
        """
        if not HAVE_HG:
            raise EasyBuildError("python-hglib is not available, which is required for Mercurial support.")

        self.wc = tempfile.mkdtemp(prefix='hg-wc-')
github easybuilders / easybuild-framework / easybuild / framework / easyconfig / parser.py View on Github external
self.auto_convert = auto_convert_value_types

        self.get_fn = None  # read method and args
        self.set_fn = None  # write method and args

        self.format_version = format_version
        self._formatter = None
        if rawcontent is not None:
            self.rawcontent = rawcontent
            self._set_formatter(filename)
        elif filename is not None:
            self._check_filename(filename)
            self.process()
        else:
            raise EasyBuildError("Neither filename nor rawcontent provided to EasyConfigParser")

        self._formatter.extract_comments(self.rawcontent)
github easybuilders / easybuild-framework / easybuild / framework / easyconfig / tools.py View on Github external
resolved_eb_path = resolve_path(eb_path)
            if eb_path != resolved_eb_path:
                install_prefix = os.path.dirname(os.path.dirname(resolved_eb_path))
                path_list.append(install_prefix)
                _log.info("Also considering installation prefix %s (via resolved path to 'eb')...", install_prefix)

    # look for desired subdirs
    for path in path_list:
        path = os.path.join(path, "easybuild", subdir)
        _log.debug("Checking for easybuild/%s at %s" % (subdir, path))
        try:
            if os.path.exists(path):
                paths.append(os.path.abspath(path))
                _log.debug("Added %s to list of paths for easybuild/%s" % (path, subdir))
        except OSError as err:
            raise EasyBuildError(str(err))

    return paths
github easybuilders / easybuild-framework / easybuild / tools / containers / base.py View on Github external
def validate_tools(self):
        """
        A method that gets called as part of image generation
        that uses TOOLS class attribute to check for the existence
        of the needed binary/tools on the host system.
        """
        for tool_name, tool_version in self.TOOLS.items():
            if not check_tool(tool_name, tool_version):
                err_msg = "".join([
                    tool_name,
                    " with version {0} or higher".format(tool_version) if tool_version else "",
                    " not found on your system.",
                ])
                raise EasyBuildError(err_msg)
github easybuilders / easybuild-framework / easybuild / tools / filetools.py View on Github external
def det_common_path_prefix(paths):
    """Determine common path prefix for a given list of paths."""
    if not isinstance(paths, list):
        raise EasyBuildError("det_common_path_prefix: argument must be of type list (got %s: %s)", type(paths), paths)
    elif not paths:
        return None

    # initial guess for common prefix
    prefix = paths[0]
    found_common = False
    while not found_common and prefix != os.path.dirname(prefix):
        prefix = os.path.dirname(prefix)
        found_common = all([p.startswith(prefix) for p in paths])

    if found_common:
        # prefix may be empty string for relative paths with a non-common prefix
        return prefix.rstrip(os.path.sep) or None
    else:
        return None