Exemple #1
0
def cli(ctx, paths, **kwds):
    """Install conda packages for tool requirements."""
    conda_context = build_conda_context(ctx, **kwds)
    if not conda_context.is_conda_installed():
        auto_init = kwds.get("conda_auto_init", False)
        failed = True
        if auto_init:
            if conda_context.can_install_conda():
                if conda_util.install_conda(conda_context):
                    error("Attempted to install conda and failed.")
                else:
                    failed = False
            else:
                error("Cannot install conda, failing conda_install.")
        else:
            error(
                "Conda not configured - run planemo conda_init' or pass --conda_auto_init to continue."
            )

        if failed:
            raise ExitCodeException(EXIT_CODE_FAILED_DEPENDENCIES)

    return_codes = []
    for conda_target in collect_conda_targets(ctx, paths):
        ctx.log("Install conda target %s" % conda_target)
        return_code = conda_util.install_conda_target(
            conda_target, conda_context=conda_context)
        return_codes.append(return_code)
    return coalesce_return_codes(return_codes, assert_at_least_one=True)
Exemple #2
0
def cli(ctx, paths, **kwds):
    """Install conda packages for tool requirements."""
    conda_context = build_conda_context(ctx, **kwds)
    if not conda_context.is_conda_installed():
        auto_init = kwds.get("conda_auto_init", False)
        failed = True
        if auto_init:
            if conda_context.can_install_conda():
                if conda_util.install_conda(conda_context):
                    error("Attempted to install conda and failed.")
                else:
                    failed = False
            else:
                error("Cannot install conda, failing conda_install.")
        else:
            error("Conda not configured - run planemo conda_init' or pass --conda_auto_init to continue.")

        if failed:
            raise ExitCodeException(EXIT_CODE_FAILED_DEPENDENCIES)

    return_codes = []
    for conda_target in collect_conda_targets(ctx, paths):
        ctx.log("Install conda target %s" % conda_target)
        return_code = conda_util.install_conda_target(
            conda_target, conda_context=conda_context
        )
        return_codes.append(return_code)
    return coalesce_return_codes(return_codes, assert_at_least_one=True)
Exemple #3
0
def cli(ctx, path, **kwds):
    """Install conda packages for tool requirements."""
    conda_context = build_conda_context(**kwds)
    return_codes = []
    for conda_target in collect_conda_targets(path):
        ctx.log("Install conda target %s" % conda_target)
        return_code = conda_util.install_conda_target(
            conda_target, conda_context=conda_context)
        return_codes.append(return_code)
    return coalesce_return_codes(return_codes, assert_at_least_one=True)
def cli(ctx, paths, **kwds):
    """Install conda packages for tool requirements."""
    conda_context = build_conda_context(ctx, handle_auto_init=True, **kwds)
    return_codes = []
    for conda_target in collect_conda_targets(ctx, paths, recursive=kwds["recursive"]):
        ctx.log("Install conda target %s" % conda_target)
        return_code = conda_util.install_conda_target(
            conda_target, conda_context=conda_context, skip_environment=kwds.get("global", False)
        )
        return_codes.append(return_code)
    return coalesce_return_codes(return_codes, assert_at_least_one=True)
Exemple #5
0
def lint_recipes_on_paths(ctx, paths, **kwds):
    """Apply conda linting procedure to recipes on supplied paths."""
    assert_tools = kwds.get("assert_recipes", True)
    recursive = kwds.get("recursive", False)
    exit_codes = []
    for recipe_dir in yield_recipes_on_paths(ctx, paths, recursive):
        if lint_conda_recipe(ctx, recipe_dir, **kwds) != 0:
            exit_codes.append(EXIT_CODE_GENERIC_FAILURE)
        else:
            exit_codes.append(EXIT_CODE_OK)
    return coalesce_return_codes(exit_codes, assert_at_least_one=assert_tools)
Exemple #6
0
def lint_recipes_on_paths(ctx, paths, **kwds):
    """Apply conda linting procedure to recipes on supplied paths."""
    assert_tools = kwds.get("assert_recipes", True)
    recursive = kwds.get("recursive", False)
    exit_codes = []
    for recipe_dir in yield_recipes_on_paths(ctx, paths, recursive):
        if lint_conda_recipe(ctx, recipe_dir, **kwds) != 0:
            exit_codes.append(EXIT_CODE_GENERIC_FAILURE)
        else:
            exit_codes.append(EXIT_CODE_OK)
    return coalesce_return_codes(exit_codes, assert_at_least_one=assert_tools)
def cli(ctx, path, **kwds):
    """Install conda packages for tool requirements."""
    conda_context = build_conda_context(**kwds)
    return_codes = []
    for conda_target in collect_conda_targets(path):
        ctx.log("Install conda target %s" % conda_target)
        return_code = conda_util.install_conda_target(
            conda_target, conda_context=conda_context
        )
        return_codes.append(return_code)
    return coalesce_return_codes(return_codes, assert_at_least_one=True)
Exemple #8
0
def cli(ctx, paths, **kwds):
    """Auto-update tool requirements by checking against Conda and updating if newer versions are available."""
    assert_tools = kwds.get("assert_tools", True)
    recursive = kwds.get("recursive", False)
    exit_codes = []
    modified_files = set()
    tools_to_skip = [line.rstrip() for line in open(kwds['skiplist'])
                     ] if kwds['skiplist'] else []
    for (tool_path,
         tool_xml) in yield_tool_sources_on_paths(ctx, paths, recursive):
        if tool_path.split('/')[-1] in tools_to_skip:
            info("Skipping tool %s" % tool_path)
            continue
        info("Auto-updating tool %s" % tool_path)
        try:
            updated = autoupdate.autoupdate_tool(ctx,
                                                 tool_path,
                                                 modified_files=modified_files,
                                                 **kwds)
            if updated:
                modified_files.update(updated)
        except Exception as e:
            error(
                "{} could not be updated - the following error was raised: {}".
                format(tool_path, e.__str__()))
        if handle_tool_load_error(tool_path, tool_xml):
            exit_codes.append(EXIT_CODE_GENERIC_FAILURE)
            continue
        else:
            exit_codes.append(EXIT_CODE_OK)

    if kwds['test']:
        if not modified_files:
            info("No tools were updated, so no tests were run.")
        else:
            with temp_directory(dir=ctx.planemo_directory) as temp_path:
                # only test tools in updated directories
                modified_paths = [
                    path for path, tool_xml in yield_tool_sources_on_paths(
                        ctx, paths, recursive) if path in modified_files
                ]
                info(
                    f"Running tests for the following auto-updated tools: {', '.join(modified_paths)}"
                )
                runnables = for_paths(modified_paths, temp_path=temp_path)
                kwds["engine"] = "galaxy"
                return_value = test_runnables(ctx,
                                              runnables,
                                              original_paths=paths,
                                              **kwds)
                exit_codes.append(return_value)
    return coalesce_return_codes(exit_codes, assert_at_least_one=assert_tools)
Exemple #9
0
def for_each_repository(ctx, function, paths, **kwds):
    ret_codes = []
    for path in paths:
        with _path_on_disk(ctx, path) as raw_path:
            try:
                for realized_repository in _realize_effective_repositories(
                        ctx, raw_path, **kwds):
                    ret_codes.append(function(realized_repository))
            except RealizationException:
                error(REALIZAION_PROBLEMS_MESSAGE)
                return 254

    return coalesce_return_codes(ret_codes)
Exemple #10
0
def cli(ctx, paths, **kwds):
    """Install conda packages for tool requirements."""
    conda_context = build_conda_context(ctx, handle_auto_init=True, **kwds)
    return_codes = []
    for conda_target in collect_conda_targets(ctx,
                                              paths,
                                              recursive=kwds["recursive"]):
        ctx.log("Install conda target %s" % conda_target)
        return_code = conda_util.install_conda_target(
            conda_target,
            conda_context=conda_context,
            skip_environment=kwds.get("global", False))
        return_codes.append(return_code)
    return coalesce_return_codes(return_codes, assert_at_least_one=True)
Exemple #11
0
def lint_tools_on_path(ctx, paths, lint_args, **kwds):
    assert_tools = kwds.get("assert_tools", True)
    recursive = kwds.get("recursive", False)
    exit_codes = []
    for (tool_path, tool_xml) in yield_tool_sources_on_paths(ctx, paths, recursive):
        if handle_tool_load_error(tool_path, tool_xml):
            exit_codes.append(EXIT_CODE_GENERIC_FAILURE)
            continue
        info("Linting tool %s" % tool_path)
        if not lint_tool_source(tool_xml, **lint_args):
            error("Failed linting")
            exit_codes.append(EXIT_CODE_GENERIC_FAILURE)
        else:
            exit_codes.append(EXIT_CODE_OK)
    return coalesce_return_codes(exit_codes, assert_at_least_one=assert_tools)
Exemple #12
0
def for_each_repository(ctx, function, paths, **kwds):
    ret_codes = []
    for path in paths:
        with _path_on_disk(path) as raw_path:
            try:
                for realized_repository in _realize_effective_repositories(
                    ctx, raw_path, **kwds
                ):
                    ret_codes.append(
                        function(realized_repository)
                    )
            except RealizationException:
                error(REALIZAION_PROBLEMS_MESSAGE)
                return 254

    return coalesce_return_codes(ret_codes)
Exemple #13
0
def lint_tools_on_path(ctx, paths, lint_args, **kwds):
    assert_tools = kwds.get("assert_tools", True)
    recursive = kwds.get("recursive", False)
    exit_codes = []
    for (tool_path,
         tool_xml) in yield_tool_sources_on_paths(ctx, paths, recursive):
        if handle_tool_load_error(tool_path, tool_xml):
            exit_codes.append(EXIT_CODE_GENERIC_FAILURE)
            continue
        info("Linting tool %s" % tool_path)
        if not lint_tool_source(tool_xml, **lint_args):
            error("Failed linting")
            exit_codes.append(EXIT_CODE_GENERIC_FAILURE)
        else:
            exit_codes.append(EXIT_CODE_OK)
    return coalesce_return_codes(exit_codes, assert_at_least_one=assert_tools)
Exemple #14
0
def cli(ctx, paths, **kwds):  # noqa C901
    """Auto-update tool requirements by checking against Conda and updating if newer versions are available."""
    assert_tools = kwds.get("assert_tools", True)
    recursive = kwds.get("recursive", False)
    exit_codes = []
    modified_files = set()
    tools_to_skip = [line.rstrip() for line in open(kwds['skiplist'])
                     ] if kwds['skiplist'] else []
    runnables = for_paths(paths)

    if any(r.type in {RunnableType.galaxy_tool, RunnableType.directory}
           for r in runnables):
        # update Galaxy tools
        for (tool_path,
             tool_xml) in yield_tool_sources_on_paths(ctx, paths, recursive):
            if tool_path.split('/')[-1] in tools_to_skip:
                info("Skipping tool %s" % tool_path)
                continue
            info("Auto-updating tool %s" % tool_path)
            try:
                updated = autoupdate.autoupdate_tool(
                    ctx, tool_path, modified_files=modified_files, **kwds)
                if updated:
                    modified_files.update(updated)
            except Exception as e:
                error(
                    f"{tool_path} could not be updated - the following error was raised: {e.__str__()}"
                )
            if handle_tool_load_error(tool_path, tool_xml):
                exit_codes.append(EXIT_CODE_GENERIC_FAILURE)
                continue
            else:
                exit_codes.append(EXIT_CODE_OK)

    workflows = [
        r for r in runnables if r.type == RunnableType.galaxy_workflow
    ]
    modified_workflows = []
    if workflows:
        assert is_galaxy_engine(**kwds)
        if kwds.get("engine") != "external_galaxy":
            kwds["install_most_recent_revision"] = True
            kwds["install_resolver_dependencies"] = False
            kwds["install_repository_dependencies"] = False
            kwds['shed_install'] = True

        with engine_context(ctx, **kwds) as galaxy_engine:
            with galaxy_engine.ensure_runnables_served(workflows) as config:
                for workflow in workflows:
                    if config.updated_repos.get(workflow.path) or kwds.get(
                            "engine") == "external_galaxy":
                        info("Auto-updating workflow %s" % workflow.path)
                        updated_workflow = autoupdate.autoupdate_wf(
                            ctx, config, workflow)
                        if workflow.path.endswith(".ga"):
                            with open(workflow.path, 'w') as f:
                                json.dump(updated_workflow,
                                          f,
                                          indent=4,
                                          sort_keys=True)
                        else:
                            format2_wrapper = from_galaxy_native(
                                updated_workflow, json_wrapper=True)
                            with open(workflow.path, "w") as f:
                                f.write(format2_wrapper["yaml_content"])
                        modified_workflows.append(workflow.path)
                    else:
                        info(
                            "No newer tool versions were found, so the workflow was not updated."
                        )

    if kwds['test']:
        if not modified_files:
            info("No tools were updated, so no tests were run.")
        else:
            with temp_directory(dir=ctx.planemo_directory) as temp_path:
                # only test tools in updated directories
                modified_paths = [
                    path for path, tool_xml in yield_tool_sources_on_paths(
                        ctx, paths, recursive) if path in modified_files
                ]
                info(
                    f"Running tests for the following auto-updated tools: {', '.join(modified_paths)}"
                )
                runnables = for_paths(modified_paths + modified_workflows,
                                      temp_path=temp_path)
                kwds["engine"] = "galaxy"
                return_value = test_runnables(ctx,
                                              runnables,
                                              original_paths=paths,
                                              **kwds)
                exit_codes.append(return_value)
    return coalesce_return_codes(exit_codes, assert_at_least_one=assert_tools)