Ejemplo n.º 1
0
def lint_tool_source_with(lint_context, tool_source, extra_modules=[]):
    import galaxy.tools.linters
    tool_xml = getattr(tool_source, "xml_tree", None)
    linter_modules = submodules.import_submodules(galaxy.tools.linters, ordered=True)
    linter_modules.extend(extra_modules)
    for module in linter_modules:
        tool_type = tool_source.parse_tool_type() or "default"
        lint_tool_types = getattr(module, "lint_tool_types", ["default"])
        if not ("*" in lint_tool_types or tool_type in lint_tool_types):
            continue

        for (name, value) in inspect.getmembers(module):
            if callable(value) and name.startswith("lint_"):
                # Look at the first argument to the linter to decide
                # if we should lint the XML description or the abstract
                # tool parser object.
                first_arg = inspect.getargspec(value).args[0]
                if first_arg == "tool_xml":
                    if tool_xml is None:
                        # XML linter and non-XML tool, skip for now
                        continue
                    else:
                        lint_context.lint(name, value, tool_xml)
                else:
                    lint_context.lint(name, value, tool_source)
Ejemplo n.º 2
0
def lint_tool_source_with(lint_context, tool_source, extra_modules=[]):
    import galaxy.tool_util.linters
    tool_xml = getattr(tool_source, "xml_tree", None)
    linter_modules = submodules.import_submodules(galaxy.tool_util.linters,
                                                  ordered=True)
    linter_modules.extend(extra_modules)
    for module in linter_modules:
        tool_type = tool_source.parse_tool_type() or "default"
        lint_tool_types = getattr(module, "lint_tool_types", ["default"])
        if not ("*" in lint_tool_types or tool_type in lint_tool_types):
            continue

        for (name, value) in inspect.getmembers(module):
            if callable(value) and name.startswith("lint_"):
                # Look at the first argument to the linter to decide
                # if we should lint the XML description or the abstract
                # tool parser object.
                first_arg = getfullargspec(value).args[0]
                if first_arg == "tool_xml":
                    if tool_xml is None:
                        # XML linter and non-XML tool, skip for now
                        continue
                    else:
                        lint_context.lint(name, value, tool_xml)
                else:
                    lint_context.lint(name, value, tool_source)
Ejemplo n.º 3
0
def _get_interface_modules():
    interfaces = []
    modules = import_submodules(sys.modules[__name__])
    for module in modules:
        module_names = [getattr(module, _) for _ in dir(module)]
        classes = [_ for _ in module_names if inspect.isclass(_) and
            not _ == ContainerInterface and issubclass(_, ContainerInterface)]
        interfaces.extend(classes)
    return {x.container_type: x for x in interfaces}
Ejemplo n.º 4
0
def _get_interface_modules():
    interfaces = []
    modules = import_submodules(sys.modules[__name__])
    for module in modules:
        module_names = [getattr(module, _) for _ in dir(module)]
        classes = [_ for _ in module_names if inspect.isclass(_) and
            not _ == ContainerInterface and issubclass(_, ContainerInterface)]
        interfaces.extend(classes)
    return dict((x.container_type, x) for x in interfaces)
Ejemplo n.º 5
0
def _get_state_handlers_dict():
    state_handlers = {}
    for module in import_submodules(galaxy.jobs.runners.state_handlers, ordered=True):
        for func in getattr(module, "__all__", []):
            if func not in state_handlers:
                state_handlers[func] = []
            state_handlers[func].append(getattr(module, func))
            log.debug("Loaded '%s' state handler from module %s", func, module.__name__)
    return state_handlers
Ejemplo n.º 6
0
 def __get_rule_modules_or_defaults(self, rules_module_name):
     """
     Returns the rules under the given rules_module_name or default
     to returning the rules of the top-level rules module for the plugin
     """
     if rules_module_name:
         rules_module = importlib.import_module(rules_module_name)
     else:
         rules_module = self.rules_module
     return import_submodules(rules_module, ordered=True)
Ejemplo n.º 7
0
 def __get_rule_modules_or_defaults(self, rules_module_name):
     """
     Returns the rules under the given rules_module_name or default
     to returning the rules of the top-level rules module for the plugin
     """
     if rules_module_name:
         rules_module = importlib.import_module(rules_module_name)
     else:
         rules_module = self.rules_module
     return import_submodules(rules_module, ordered=True)
Ejemplo n.º 8
0
def _get_state_handlers_dict():
    state_handlers = {}
    for module in import_submodules(galaxy.jobs.runners.state_handlers,
                                    ordered=True):
        for func in getattr(module, "__all__", []):
            if func not in state_handlers:
                state_handlers[func] = []
            state_handlers[func].append(getattr(module, func))
            log.debug("Loaded '%s' state handler from module %s", func,
                      module.__name__)
    return state_handlers
Ejemplo n.º 9
0
def plugins_dict(module, plugin_type_identifier):
    """ Walk through all classes in submodules of module and find ones labelled
    with specified plugin_type_identifier and throw in a dictionary to allow
    constructions from plugins by these types later on.
    """
    plugin_dict = {}

    for plugin_module in import_submodules(module, ordered=True):
        for clazz in __plugin_classes_in_module(plugin_module):
            plugin_type = getattr(clazz, plugin_type_identifier, None)
            if plugin_type:
                plugin_dict[plugin_type] = clazz

    return plugin_dict
Ejemplo n.º 10
0
def plugins_dict(module, plugin_type_identifier):
    """ Walk through all classes in submodules of module and find ones labelled
    with specified plugin_type_identifier and throw in a dictionary to allow
    constructions from plugins by these types later on.
    """
    plugin_dict = {}

    for plugin_module in import_submodules(module, ordered=True):
        # FIXME: this is not how one is suppose to use __all__ why did you do
        # this past John?
        for clazz in getattr(plugin_module, "__all__", []):
            try:
                clazz = getattr(plugin_module, clazz)
            except TypeError:
                clazz = clazz
            plugin_type = getattr(clazz, plugin_type_identifier, None)
            if plugin_type:
                plugin_dict[plugin_type] = clazz

    return plugin_dict
Ejemplo n.º 11
0
def plugins_dict(module, plugin_type_identifier):
    """ Walk through all classes in submodules of module and find ones labelled
    with specified plugin_type_identifier and throw in a dictionary to allow
    constructions from plugins by these types later on.
    """
    plugin_dict = {}

    for plugin_module in import_submodules(module, ordered=True):
        # FIXME: this is not how one is suppose to use __all__ why did you do
        # this past John?
        for clazz in getattr(plugin_module, "__all__", []):
            try:
                clazz = getattr(plugin_module, clazz)
            except TypeError:
                clazz = clazz
            plugin_type = getattr(clazz, plugin_type_identifier, None)
            if plugin_type:
                plugin_dict[plugin_type] = clazz

    return plugin_dict