Beispiel #1
0
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))
Beispiel #2
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.

    \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)
def cli(ctx, path, brew=None):
    """Install tool requirements using brew.

    An experimental approach to versioning brew recipes will be used.
    See full discussion on the homebrew-science issues page here -
    https://github.com/Homebrew/homebrew-science/issues/1191. Information
    on the implementation can be found at
    https://github.com/jmchilton/platform-brew
    until a more permanent project home is setup.
    """
    for (tool_path, tool_xml) in load_tool_elements_from_path(path):
        ctx.log('Brewing requirements from tool %s',
                click.format_filename(tool_path))
        mock_args = bunch.Bunch(brew=brew)
        brew_context = brew_exts.BrewContext(mock_args)
        requirements, containers = parse_requirements_from_xml(tool_xml)

        for recipe_context in brew_util.requirements_to_recipe_contexts(
                requirements, brew_context):
            brew_exts.versioned_install(recipe_context)
def dockerfile_build(path, dockerfile=None, error=log.error, **kwds):
    expected_container_names = set()
    tool_directories = set()
    for (tool_path, tool_xml) in load_tool_elements_from_path(path):
        requirements, containers = parse_requirements_from_xml(tool_xml)
        for container in containers:
            if container.type == "docker":
                expected_container_names.add(container.identifier)
                tool_directories.add(os.path.dirname(tool_path))
                break

    if len(expected_container_names) == 0:
        error("Could not find any docker identifiers to generate.")

    if len(expected_container_names) > 1:
        error(
            "Multiple different docker identifiers found for selected tools [%s]",
            expected_container_names)

    image_identifier = expected_container_names.pop()

    dockerfile = __find_dockerfile(dockerfile, tool_directories)
    if dockerfile is not None:
        docker_command_parts = docker_util.build_command(
            image_identifier, dockerfile, **docker_host_args(**kwds))
    else:
        docker_command_parts = docker_util.build_pull_command(
            image_identifier, **docker_host_args(**kwds))
        commands.execute(docker_command_parts)

    commands.execute(docker_command_parts)
    docker_image_cache = kwds['docker_image_cache']
    if docker_image_cache:
        destination = docker_cache_path(docker_image_cache, image_identifier)
        save_image_command_parts = docker_util.build_save_image_command(
            image_identifier, destination, **docker_host_args(**kwds))
        commands.execute(save_image_command_parts)
Beispiel #5
0
 def parse_requirements_and_containers(self):
     return requirements.parse_requirements_from_xml(self.root)