def find_extension(source_file, sourcecache: SourceCache): for ext in EXTENSIONS: if source_file.get_filename().endswith("wrapper{}".format(ext)): return source_file for ext in EXTENSIONS: script = source_file.join("wrapper{}".format(ext)) if sourcecache.exists(script): return script
def wrapper( path, input, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, prefix, jobid, bench_iteration, cleanup_scripts, shadow_dir, runtime_sourcecache_path, ): """ Load a wrapper from https://github.com/snakemake/snakemake-wrappers under the given path + wrapper.(py|R|Rmd) and execute it. """ path = get_script(path, SourceCache(runtime_cache_path=runtime_sourcecache_path), prefix=prefix) script( path, "", input, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, runtime_sourcecache_path, )
def find_extension(path, sourcecache: SourceCache, extensions=[".py", ".R", ".Rmd", ".jl"]): for ext in extensions: if path.endswith("wrapper{}".format(ext)): return path path = infer_source_file(path) for ext in extensions: script = path.join("wrapper{}".format(ext)) if sourcecache.exists(script): return script
def wrapper( path, input, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, prefix, jobid, bench_iteration, cleanup_scripts, shadow_dir, runtime_sourcecache_path, ): """ Load a wrapper from https://github.com/snakemake/snakemake-wrappers under the given path + wrapper.(py|R|Rmd) and execute it. """ assert path is not None script_source = get_script( path, SourceCache(runtime_cache_path=runtime_sourcecache_path), prefix=prefix ) if script_source is None: raise WorkflowError( f"Unable to locate wrapper script for wrapper {path}. " "This can be a network issue or a mistake in the wrapper URL." ) script( script_source.get_path_or_uri(), "", input, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, runtime_sourcecache_path, )
def notebook( path, basedir, input, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, edit, runtime_sourcecache_path, ): """ Load a script from the given basedir + path and execute it. """ draft = False if edit is not None: if is_local_file(path): if not os.path.isabs(path): local_path = os.path.join(basedir, path) else: local_path = path if not os.path.exists(local_path): # draft the notebook, it does not exist yet language = None draft = True path = "file://{}".format(os.path.abspath(local_path)) if path.endswith(".py.ipynb"): language = "jupyter_python" elif path.endswith(".r.ipynb"): language = "jupyter_r" else: raise WorkflowError( "Notebook to edit has to end on .py.ipynb or .r.ipynb in order " "to decide which programming language shall be used.") else: raise WorkflowError( "Notebook {} is not local, but edit mode is only allowed for " "local notebooks.".format(path)) if not draft: path, source, language, is_local = get_source( path, SourceCache(runtime_sourcecache_path), basedir, wildcards, params) else: source = None is_local = True exec_class = get_exec_class(language) executor = exec_class( path, source, basedir, input, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local, ) if draft: executor.draft(listen=edit) else: executor.evaluate(edit=edit)
def notebook( path, basedir, input, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, edit, runtime_sourcecache_path, ): """ Load a script from the given basedir + path and execute it. """ draft = False if edit is not None: if is_local_file(path): if not os.path.isabs(path): local_path = os.path.join(basedir, path) else: local_path = path if not os.path.exists(local_path): # draft the notebook, it does not exist yet language = None draft = True path = "file://{}".format(os.path.abspath(local_path)) if path.endswith(".py.ipynb"): language = "jupyter_python" elif path.endswith(".r.ipynb"): language = "jupyter_r" else: raise WorkflowError( "Notebook to edit has to end on .py.ipynb or .r.ipynb in order " "to decide which programming language shall be used.") else: raise WorkflowError( "Notebook {} is not local, but edit mode is only allowed for " "local notebooks.".format(path)) if not draft: path, source, language, is_local = get_source( path, SourceCache(runtime_sourcecache_path), basedir, wildcards, params) else: source = None is_local = True path = infer_source_file(path) exec_class = get_exec_class(language) executor = exec_class( path, source, basedir, input, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local, ) if edit is None: executor.evaluate(edit=edit) elif edit.draft_only: executor.draft() msg = "Generated skeleton notebook:\n{} ".format(path) if conda_env and not container_img: msg += ( "\n\nEditing with VSCode:\nOpen notebook, run command 'Select notebook kernel' (Ctrl+Shift+P or Cmd+Shift+P), and choose:" "\n{}\n".format( str( Path(conda_env) / "bin" / executor.get_interpreter_exec()))) msg += ("\nEditing with Jupyter CLI:" "\nconda activate {}\njupyter notebook {}\n".format( conda_env, path)) logger.info(msg) elif draft: executor.draft_and_edit(listen=edit) else: executor.evaluate(edit=edit)
def script( path, basedir, input, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, runtime_sourcecache_path, ): """ Load a script from the given basedir + path and execute it. """ path, source, language, is_local = get_source( path, SourceCache(runtime_sourcecache_path), basedir, wildcards, params ) exec_class = { "python": PythonScript, "r": RScript, "rmarkdown": RMarkdown, "julia": JuliaScript, "rust": RustScript, }.get(language, None) if exec_class is None: raise ValueError( "Unsupported script: Expecting either Python (.py), R (.R), RMarkdown (.Rmd) or Julia (.jl) script." ) executor = exec_class( path, source, basedir, input, output, params, wildcards, threads, resources, log, config, rulename, conda_env, conda_base_path, container_img, singularity_args, env_modules, bench_record, jobid, bench_iteration, cleanup_scripts, shadow_dir, is_local, ) executor.evaluate()