Example #1
0
def cli(ctx, path, **kwds):
    """Launch a shell in the Docker container referenced by the specified
    tool. Prints a command to do this the way Galaxy would in job files it
    generates - so be sure to wrap this in $(...) to launch the subshell.::

        % $(planemo docker_shell bowtie2.xml)
        ...
        root@b8754062f875:/#

    """
    tool_xml = load_tool(path)
    requirements, containers = parse_requirements_from_xml(tool_xml)
    identifier = None
    for container in containers:
        if container.type == "docker":
            identifier = container.identifier

    if kwds["from_tag"]:
        identifier = "-t %s" % identifier

    script = docker_util.build_docker_run_command(
        "/bin/bash",
        identifier,
        interactive=True,
        **dockerfiles.docker_host_args(**kwds)
    )
    print(script)
Example #2
0
def cli(ctx, path, **kwds):
    """Launch a shell in the Docker container referenced by the specified
    tool. Prints a command to do this the way Galaxy would in job files it
    generates - so be sure to wrap this in $(...) to launch the subshell.::

        % $(planemo docker_shell bowtie2.xml)
        ...
        root@b8754062f875:/#

    """
    tool_xml = load_tool(path)
    requirements, containers = parse_requirements_from_xml(tool_xml)
    identifier = None
    for container in containers:
        if container.type == "docker":
            identifier = container.identifier

    if kwds["from_tag"]:
        identifier = "-t %s" % identifier

    script = docker_util.build_docker_run_command(
        "/bin/bash",
        identifier,
        interactive=True,
        **dockerfiles.docker_host_args(**kwds))
    print(script)
def cli(ctx, path, brew=None, skip_install=False, shell=None):
    """List commands to inject brew dependencies.

    Display commands used to modify environment to inject tool's brew
    dependencies.

    \b
        % . <(planemo brew_env bowtie2.xml)
        % which bowtie2
        /home/john/.linuxbrew/Cellar/bowtie2/2.1.0/bin/bowtie2

    By default this will attempt to attempt to install these recipes as needed.
    This automatic installation can be skipped with the ``--skip_install``
    flag.

    Intead of injecting the enviornment into your current shell using the above
    idiom, the ``--shell`` flag can be sent to launch a new subshell when
    sourced.

    \b
        % . <(planemo brew_env --skip_install --shell bowtie2.xml)
        (bowtie2) % which bowtie2
        /home/john/.linuxbrew/Cellar/bowtie2/2.1.0/bin/bowtie2

    """
    tool_xml = load_tool(path)
    mock_args = bunch.Bunch(brew=brew)
    brew_context = brew_exts.BrewContext(mock_args)
    requirements, containers = parse_requirements_from_xml(tool_xml)

    lines = []
    for recipe_context in brew_util.requirements_to_recipe_contexts(
        requirements,
        brew_context
    ):
        if not skip_install:
            brew_exts.versioned_install(recipe_context)
        lines = brew_exts.build_env_statements_from_recipe_context(
            recipe_context
        )
        split_lines = lines.split("\n")
        lines.extend(split_lines)
    if shell:
        # TODO: Would be cool if this wasn't a bunch of random hackery.
        launch_shell = os.environ.get("SHELL")
        if "bash" in launch_shell:
            ps1 = ps1_for_path(path)
            launch_shell = '(source ~/.bashrc; env PS1="%s" %s --norc)' % (
                ps1,
                launch_shell,
            )
        lines.extend([launch_shell])
        print(";".join(lines))
    else:
        print("\n".join(lines))
def cli(ctx, path, **kwds):
    """Launch shell in Docker container for a tool.

    Will launch a shell in the Docker container referenced by the specified
    tool. Prints a command to do this the way Galaxy would in job files it
    generates - so be sure to wrap this in $(...) to launch the subshell.

    \b
        $ $(planemo docker_shell bowtie2.xml)
        ...
        root@b8754062f875:/#

    """
    tool_xml = load_tool(path)
    requirements, containers = parse_requirements_from_xml(tool_xml)
    identifier = None
    for container in containers:
        if container.type == "docker":
            identifier = container.identifier

    # Refactor mulled container resolver to be able to do this.
    if kwds["from_tag"]:
        identifier = "-t %s" % identifier

    tool_dir = os.path.dirname(os.path.abspath(path))
    working_dir = os.path.abspath(os.getcwd())
    if tool_dir.startswith(working_dir):
        volumes = [
            "%s:%s" % (working_dir, working_dir)
        ]
    elif working_dir.startswith(tool_dir):
        volumes = [
            "%s:%s" % (tool_dir, tool_dir)
        ]
    else:
        volumes = [
            "%s:%s" % (working_dir, working_dir),
            "%s:%s" % (tool_dir, tool_dir)
        ]

    script = docker_util.build_docker_run_command(
        "/bin/bash",
        identifier,
        interactive=True,
        terminal=True,
        working_directory=working_dir,
        volumes=volumes,
        **dockerfiles.docker_host_args(**kwds)
    )
    print(script)
Example #5
0
def cli(ctx, path, **kwds):
    """Launch shell in Docker container for a tool.

    Will launch a shell in the Docker container referenced by the specified
    tool. Prints a command to do this the way Galaxy would in job files it
    generates - so be sure to wrap this in $(...) to launch the subshell.::

        % $(planemo docker_shell bowtie2.xml)
        ...
        root@b8754062f875:/#

    """
    tool_xml = load_tool(path)
    requirements, containers = parse_requirements_from_xml(tool_xml)
    identifier = None
    for container in containers:
        if container.type == "docker":
            identifier = container.identifier

    if kwds["from_tag"]:
        identifier = "-t %s" % identifier

    tool_dir = os.path.dirname(os.path.abspath(path))
    working_dir = os.path.abspath(os.getcwd())
    if tool_dir.startswith(working_dir):
        volumes = [
            "%s:%s" % (working_dir, working_dir)
        ]
    elif working_dir.startswith(tool_dir):
        volumes = [
            "%s:%s" % (tool_dir, tool_dir)
        ]
    else:
        volumes = [
            "%s:%s" % (working_dir, working_dir),
            "%s:%s" % (tool_dir, tool_dir)
        ]

    script = docker_util.build_docker_run_command(
        "/bin/bash",
        identifier,
        interactive=True,
        terminal=True,
        working_directory=working_dir,
        volumes=volumes,
        **dockerfiles.docker_host_args(**kwds)
    )
    print(script)
Example #6
0
def cli(ctx, path, expand_macros=False, **kwds):
    """Generate normalized tool XML from input (breaks formatting).

    This will break the formatting of your tool and is currently only intended
    for viewing macro expansions for for use with XSD validation (see
    https://github.com/JeanFred/Galaxy-XSD for instance). Please do not use
    the output as is - it frequently makes tool less readable not more.

    The top-level blocks will be reordered and whitespace fixed according to
    the tool development best practices outlined on the Galaxy wiki.

    ::

        % # Print normalized version of tool.
        % planemo normalize tool.xml
        <tool>
        ...
        % # Print a variant of tool with all macros expanded out, useful for
        % # debugging complex macros.
        % planemo normalize --expand_macros tool.xml
        <tool>
        ...
    """
    if expand_macros:
        tree = load_tool(path)
    else:
        tree = raw_tool_xml_tree(path)

    root = tree.getroot()
    if not kwds.get("skip_reorder", False):
        last_index = len(TAG_ORDER)
        data = []
        for elem in root:
            tag = elem.tag
            if tag in TAG_ORDER:
                key = TAG_ORDER.index(tag)
            else:
                key = last_index
                last_index += 1
            data.append((key, elem))
        data.sort()
        root[:] = [item[-1] for item in data]
    if not kwds.get("skip_reindent", False):
        _indent(root)
    ElementTree.dump(root)
Example #7
0
def cli(ctx, path, expand_macros=False, **kwds):
    """Generate normalized tool XML from input (breaks formatting).

    This will break the formatting of your tool and is currently only intended
    for viewing macro expansions for for use with XSD validation (see
    https://github.com/JeanFred/Galaxy-XSD for instance). Please do not use
    the output as is - it frequently makes tool less readable not more.

    The top-level blocks will be reordered and whitespace fixed according to
    the tool development best practices outlined on the Galaxy wiki.

    ::

        % # Print normalized version of tool.
        % planemo normalize tool.xml
        <tool>
        ...
        % # Print a variant of tool with all macros expanded out, useful for
        % # debugging complex macros.
        % planemo normalize --expand_macros tool.xml
        <tool>
        ...
    """
    if expand_macros:
        tree = load_tool(path)
    else:
        tree = raw_tool_xml_tree(path)

    root = tree.getroot()
    if not kwds.get("skip_reorder", False):
        last_index = len(TAG_ORDER)
        data = []
        for elem in root:
            tag = elem.tag
            if tag in TAG_ORDER:
                key = TAG_ORDER.index(tag)
            else:
                key = last_index
                last_index += 1
            data.append((key, elem))
        data.sort()
        root[:] = [item[-1] for item in data]
    if not kwds.get("skip_reindent", False):
        _indent(root)
    ElementTree.dump(root)
 def load(self, name="tool.xml", preprocess=True):
     path = os.path.join(self.temp_directory, name)
     if preprocess:
         return load_tool(path)
     else:
         return parse_xml(path)