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, **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 implementation(logger, args): list_of_files = {} if path_exists(args.sg_local_path, logger=logger, force=True): for (dirpath, dirnames, filenames) in os.walk(args.sg_local_path): for filename in filenames: list_of_files[filename] = os.sep.join([dirpath, filename]) logger.debug(list_of_files) gi = GalaxyInstance(args.url, key=args.key) tools = gi.tools.get_tools() counter_singularity = 0 counter_docker = 0 match = {} unmatch = [] for t in tools: t_id = t['id'] t_xml_file = gi.tools.show_tool(t['id'])['config_file'] container_name = None try: tool_xml = load(t_xml_file) requirements, containers = parse_requirements_from_xml(tool_xml) conda_targets = requirements_to_conda_targets(requirements) mulled_targets = [ build_target(c.package, c.version) for c in conda_targets ] container_name = mulled_container_name("biocontainers", mulled_targets) except Exception as ex: logger.exception('Caught an error at {} with tid: {}'.format( args.url, t_id)) pass singularity = 'not_found' if container_name: container_name = container_name.lower() counter_docker += 1 if os.path.basename(container_name) in list_of_files: singularity = os.path.join(args.sg_local_path, os.path.basename(container_name)) counter_singularity += 1 match[t_id] = { 'docker': "docker://{}".format(container_name), 'singularity': singularity } unmatch.append(t_id) print(t_id, container_name, singularity) dump(match, "{}_{}".format(args.url.split('/')[2], args.matched)) dump(unmatch, "{}_{}".format(args.url.split('/')[2], args.notmatched)) print("number of tools {}".format(len(tools))) print("number of docker images matched {}".format(counter_docker)) print("number of singularity images in CVMFS {}".format( len(list_of_files))) print( "number of singularity images matched {}".format(counter_singularity))
def collect_conda_targets(path, found_tool_callback=None, conda_context=None): conda_targets = [] for (tool_path, tool_xml) in load_tool_elements_from_path(path): if found_tool_callback: found_tool_callback(tool_path) requirements, containers = parse_requirements_from_xml(tool_xml) conda_targets.extend(conda_util.requirements_to_conda_targets(requirements)) return conda_targets
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)
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)
def cli(ctx, path, brew=None): """Install tool requirements using brew. (**Experimental**) 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 cli(ctx, path, brew=None): """Install tool requirements using brew. (**Experimental**) 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 parse_requirements_and_containers(self): return requirements.parse_requirements_from_xml(self.root)