def get_format_version_classes(version=None): """Return the (usable) subclasses from EasyConfigFormat that have a matching version.""" all_classes = get_subclasses(EasyConfigFormat) if version is None: return all_classes else: return [x for x in all_classes if x.VERSION == version and x.USABLE]
def search_toolchain(name): """ Obtain a Toolchain instance for the toolchain with specified name, next to a list of available toolchains. :param name: toolchain name :return: Toolchain instance (or None), found_toolchains """ package = easybuild.tools.toolchain check_attr_name = '%s_PROCESSED' % TC_CONST_PREFIX if not hasattr(package, check_attr_name) or not getattr(package, check_attr_name): # import all available toolchains, so we know about them tc_modules = import_available_modules('easybuild.toolchains') # make sure all defined toolchain constants are available in toolchain module tc_const_re = re.compile('^%s(.*)$' % TC_CONST_PREFIX) for tc_mod in tc_modules: # determine classes imported in this module mod_classes = [] for elem in [getattr(tc_mod, x) for x in dir(tc_mod)]: if hasattr(elem, '__module__'): # exclude the toolchain class defined in that module if not tc_mod.__file__ == sys.modules[elem.__module__].__file__: elem_name = elem.__name__ if hasattr(elem, '__name__') else elem _log.debug("Adding %s to list of imported classes used for looking for constants", elem_name) mod_classes.append(elem) # look for constants in modules of imported classes, and make them available for mod_class_mod in [sys.modules[mod_class.__module__] for mod_class in mod_classes]: for elem in dir(mod_class_mod): res = tc_const_re.match(elem) if res: tc_const_name = res.group(1) tc_const_value = getattr(mod_class_mod, elem) _log.debug("Found constant %s ('%s') in module %s, adding it to %s", tc_const_name, tc_const_value, mod_class_mod.__name__, package.__name__) if hasattr(package, tc_const_name): cur_value = getattr(package, tc_const_name) if not tc_const_value == cur_value: raise EasyBuildError("Constant %s.%s defined as '%s', can't set it to '%s'.", package.__name__, tc_const_name, cur_value, tc_const_value) else: setattr(package, tc_const_name, tc_const_value) # indicate that processing of toolchain constants is done, so it's not done again setattr(package, check_attr_name, True) else: _log.debug("Skipping importing of toolchain modules, processing of toolchain constants is already done.") # obtain all subclasses of toolchain found_tcs = nub(get_subclasses(Toolchain)) # filter found toolchain subclasses based on whether they can be used a toolchains found_tcs = [tc for tc in found_tcs if tc._is_toolchain_for(None)] for tc in found_tcs: if tc._is_toolchain_for(name): return tc, found_tcs return None, found_tcs
def avail_job_backends(check_usable=True): """ Return all known job execution backends. """ import_available_modules('easybuild.tools.job') class_dict = dict([(x.__name__, x) for x in get_subclasses(JobBackend)]) return class_dict
def avail_package_naming_schemes(): """ Returns the list of valed naming schemes They are loaded from the easybuild.package.package_naming_scheme namespace """ import_available_modules('easybuild.tools.package.package_naming_scheme') class_dict = dict([(x.__name__, x) for x in get_subclasses(PackageNamingScheme)]) return class_dict
def what_licenses(): """Return a dict of License subclasses names and license instances""" res = {} for lic in get_subclasses(License): if lic.HIDDEN: continue res[lic.__name__] = lic return res
def avail_module_naming_schemes(): """ Returns a list of available module naming schemes. """ # all ModuleNamingScheme subclasses available in easybuild.tools.module_naming_scheme namespace are eligible import_available_modules('easybuild.tools.module_naming_scheme') # construct name-to-class dict of available module naming scheme avail_mnss = dict([(x.__name__, x) for x in get_subclasses(ModuleNamingScheme)]) return avail_mnss
def avail_repositories(check_useable=True): """ Return all available repositories. check_useable: boolean, if True, only return usable repositories """ import_available_modules('easybuild.tools.repository') class_dict = dict([(x.__name__, x) for x in get_subclasses(Repository) if x.USABLE or not check_useable]) if 'FileRepository' not in class_dict: raise EasyBuildError("avail_repositories: FileRepository missing from list of repositories") return class_dict