code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def print_exception_warning(ex, linemaps=None, footer_message=""):
"""
Print an error message for a given exception using logger warning.
Arguments
ex -- the exception
linemaps -- a dict of a dict that maps for each snakefile
the compiled lines to source code lines in the snakefile.
"""... |
Print an error message for a given exception using logger warning.
Arguments
ex -- the exception
linemaps -- a dict of a dict that maps for each snakefile
the compiled lines to source code lines in the snakefile.
| print_exception_warning | python | snakemake/snakemake | src/snakemake/exceptions.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/exceptions.py | MIT |
def print_exception(ex, linemaps=None):
"""
Print an error message for a given exception.
Arguments
ex -- the exception
linemaps -- a dict of a dict that maps for each snakefile
the compiled lines to source code lines in the snakefile.
"""
from snakemake.logging import logger
l... |
Print an error message for a given exception.
Arguments
ex -- the exception
linemaps -- a dict of a dict that maps for each snakefile
the compiled lines to source code lines in the snakefile.
| print_exception | python | snakemake/snakemake | src/snakemake/exceptions.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/exceptions.py | MIT |
def __init__(
self, message=None, include=None, lineno=None, snakefile=None, rule=None
):
"""
Creates a new instance of RuleException.
Arguments
message -- the exception message
include -- iterable of other exceptions to be included
lineno -- the line the exc... |
Creates a new instance of RuleException.
Arguments
message -- the exception message
include -- iterable of other exceptions to be included
lineno -- the line the exception originates
snakefile -- the file the exception originates
| __init__ | python | snakemake/snakemake | src/snakemake/exceptions.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/exceptions.py | MIT |
def logfile_suggestion(self, prefix: str) -> str:
"""Return a suggestion for the log file name given a prefix."""
return (
"/".join(
[prefix, self.rule.name]
+ [
f"{w}_{v}"
for w, v in sorted(
sel... | Return a suggestion for the log file name given a prefix. | logfile_suggestion | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
async def outputs_older_than_script_or_notebook(self):
"""return output that's older than script, i.e. script has changed"""
path = self.rule.script or self.rule.notebook
if not path:
return
path: SourceFile = self._path_to_source_file(path)
if isinstance(path, Loca... | return output that's older than script, i.e. script has changed | outputs_older_than_script_or_notebook | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
def _get_resources_to_skip(self):
"""Return a set of resource names that are callable and depend on input files."""
return {
name
for name, val in self.rule.resources.items()
if is_callable(val) and "input" in get_function_params(val)
} | Return a set of resource names that are callable and depend on input files. | _get_resources_to_skip | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
def archive_conda_env(self):
"""Archive a conda environment into a custom local channel."""
if self.conda_env_spec:
if self.conda_env.is_externally_managed:
raise WorkflowError(
"Workflow archives cannot be created for workflows using externally managed co... | Archive a conda environment into a custom local channel. | archive_conda_env | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
async def inputsize(self):
"""
Return the size of the input files.
Input files need to be present.
"""
if self._inputsize is None:
self._inputsize = sum([await f.size() for f in self.input])
return self._inputsize |
Return the size of the input files.
Input files need to be present.
| inputsize | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
def message(self):
"""Return the message for this job."""
try:
return (
self.format_wildcards(self.rule.message) if self.rule.message else None
)
except AttributeError as ex:
raise RuleException(str(ex), rule=self.rule)
except KeyError ... | Return the message for this job. | message | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
def _path_to_source_file(self, path: Union[str, Path]) -> SourceFile:
"""Return the path to source file referred by rule, while expanding
wildcards and params.
"""
if isinstance(path, Path):
path = str(path)
if self.wildcards is not None or self.params is not None:
... | Return the path to source file referred by rule, while expanding
wildcards and params.
| _path_to_source_file | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
def shadowed_path(self, f):
"""Get the shadowed path of IOFile f."""
if not self.shadow_dir:
return f
f_ = IOFile(os.path.join(self.shadow_dir, f), self.rule)
# The shadowed path does not need the storage object, storage will be handled
# after shadowing.
f_.c... | Get the shadowed path of IOFile f. | shadowed_path | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
async def remove_existing_output(self):
"""Clean up output before rules actually run"""
for f, f_ in zip(self.output, self.rule.output):
if is_flagged(f, "update"):
# output files marked as to be updated are not removed
continue
try:
... | Clean up output before rules actually run | remove_existing_output | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
async def prepare(self):
"""
Prepare execution of job.
This includes creation of directories and deletion of previously
created files.
Creates a shadow directory for the job if specified.
"""
await self.check_protected_output()
unexpected_output = self.d... |
Prepare execution of job.
This includes creation of directories and deletion of previously
created files.
Creates a shadow directory for the job if specified.
| prepare | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
def format_wildcards(self, string, **variables):
"""Format a string with variables from the job."""
_variables = dict()
_variables.update(self.rule.workflow.globals)
_variables.update(
dict(
input=self.input,
output=self.output,
... | Format a string with variables from the job. | format_wildcards | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
def expanded_output(self):
"""Yields the entire expanded output of all jobs"""
for job in self.jobs:
yield from job.output | Yields the entire expanded output of all jobs | expanded_output | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
def is_provenance_triggered(self):
"""Return True if reason is triggered by provenance information."""
return (
self.params_changed
or self.code_changed
or self.software_stack_changed
or self.input_changed
) | Return True if reason is triggered by provenance information. | is_provenance_triggered | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
def mark_finished(self):
"called if the job has been run"
self.finished = True | called if the job has been run | mark_finished | python | snakemake/snakemake | src/snakemake/jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/jobs.py | MIT |
def format_percentage(done, total):
"""Format percentage from given fraction while avoiding superfluous precision."""
if done == total:
return "100%"
if done == 0:
return "0%"
precision = 0
fraction = done / total
fmt_precision = "{{:.{}%}}".format
def fmt(fraction):
... | Format percentage from given fraction while avoiding superfluous precision. | format_percentage | python | snakemake/snakemake | src/snakemake/logging.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/logging.py | MIT |
def get_event_level(record: logging.LogRecord) -> tuple[LogEvent, str]:
"""
Gets snakemake log level from a log record. If there is no snakemake log level,
returns the log record's level name.
Args:
record (logging.LogRecord)
Returns:
tuple[LogEvent, str]
"""
event = record... |
Gets snakemake log level from a log record. If there is no snakemake log level,
returns the log record's level name.
Args:
record (logging.LogRecord)
Returns:
tuple[LogEvent, str]
| get_event_level | python | snakemake/snakemake | src/snakemake/logging.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/logging.py | MIT |
def format(self, record):
"""
Override format method to format Snakemake-specific log messages.
"""
event, level = get_event_level(record)
record_dict = record.__dict__.copy()
def default_formatter(rd):
return rd["msg"]
formatters = {
Non... |
Override format method to format Snakemake-specific log messages.
| format | python | snakemake/snakemake | src/snakemake/logging.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/logging.py | MIT |
def _format_job_info(self, msg):
"""Helper method to format job info details."""
def format_item(item, omit=None, valueformat=str):
value = msg[item]
if value != omit:
return f" {item}: {valueformat(value)}"
output = [
f"{'local' if msg['l... | Helper method to format job info details. | _format_job_info | python | snakemake/snakemake | src/snakemake/logging.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/logging.py | MIT |
def _format_job_error(self, msg):
"""Helper method to format job error details."""
output = [f"Error in rule {msg['rule_name']}:"]
if msg["msg"]:
output.append(f" message: {msg['rule_msg']}")
output.append(f" jobid: {msg['jobid']}")
if msg["input"]:
... | Helper method to format job error details. | _format_job_error | python | snakemake/snakemake | src/snakemake/logging.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/logging.py | MIT |
def _format_group_error(self, msg):
"""Helper method to format group error details."""
output = []
if msg["msg"]:
output.append(f" message: {msg['msg']}")
if msg["aux_logs"]:
output.append(
f" log: {', '.join(msg['aux_logs'])} (check log fil... | Helper method to format group error details. | _format_group_error | python | snakemake/snakemake | src/snakemake/logging.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/logging.py | MIT |
def can_color_tty(self, mode):
"""
Colors are supported when:
1. Terminal is not "dumb"
2. Running in subprocess mode
3. Using a TTY on non-Windows systems
"""
from snakemake_interface_executor_plugins.settings import ExecMode
# Case 1: Check if terminal ... |
Colors are supported when:
1. Terminal is not "dumb"
2. Running in subprocess mode
3. Using a TTY on non-Windows systems
| can_color_tty | python | snakemake/snakemake | src/snakemake/logging.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/logging.py | MIT |
def decorate(self, record, message):
"""
Add color to the log message based on its level.
"""
message = [message]
event, level = get_event_level(record)
if not self.nocolor and record.levelname in self.colors:
if level == "INFO" and event in self.yellow_info... |
Add color to the log message based on its level.
| decorate | python | snakemake/snakemake | src/snakemake/logging.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/logging.py | MIT |
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,
s... |
Load a script from the given basedir + path and execute it.
| notebook | python | snakemake/snakemake | src/snakemake/notebook.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/notebook.py | MIT |
def match(self, targetfile: str) -> set[Rule]:
"""Returns all rules that match the given target file, considering only the prefix and suffix up to the
first wildcard.
To further verify the match, the returned rules should be checked with ``Rule.is_producer(targetfile)``.
"""
ret... | Returns all rules that match the given target file, considering only the prefix and suffix up to the
first wildcard.
To further verify the match, the returned rules should be checked with ``Rule.is_producer(targetfile)``.
| match | python | snakemake/snakemake | src/snakemake/output_index.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/output_index.py | MIT |
def parse_fstring(self, token: tokenize.TokenInfo):
"""
only for python >= 3.12, since then python changed the
parsing manner of f-string, see
[pep-0701](https://peps.python.org/pep-0701)
Here, we just read where the f-string start and end from tokens.
Luckily, each toke... |
only for python >= 3.12, since then python changed the
parsing manner of f-string, see
[pep-0701](https://peps.python.org/pep-0701)
Here, we just read where the f-string start and end from tokens.
Luckily, each token records the content of the line,
and we can just take... | parse_fstring | python | snakemake/snakemake | src/snakemake/parser.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/parser.py | MIT |
def apply_default_storage(self, path):
"""Apply the defined default remote provider to the given path and return the updated _IOFile.
Asserts that default remote provider is defined.
"""
from snakemake.storage import flag_with_storage_object
def is_annotated_callable(value):
... | Apply the defined default remote provider to the given path and return the updated _IOFile.
Asserts that default remote provider is defined.
| apply_default_storage | python | snakemake/snakemake | src/snakemake/path_modifier.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/path_modifier.py | MIT |
def input_checksums(self, job, input_path):
"""Return all checksums of the given input file
recorded for the output of the given job.
"""
return set(
self.metadata(output_path).get("input_checksums", {}).get(input_path)
for output_path in job.output
) | Return all checksums of the given input file
recorded for the output of the given job.
| input_checksums | python | snakemake/snakemake | src/snakemake/persistence.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/persistence.py | MIT |
def params_changed(self, job, file=None):
"""Yields output files with changed params or bool if file given."""
files = [file] if file is not None else job.output
changes = NO_PARAMS_CHANGE
new = set(self._params(job))
for outfile in files:
fmt_version = self.record... | Yields output files with changed params or bool if file given. | params_changed | python | snakemake/snakemake | src/snakemake/persistence.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/persistence.py | MIT |
def _get_layers(cls, resources, constraints, sortby=None):
"""Calculate required consecutive job layers.
Layers are used to keep resource requirements within given
constraint. For instance, if the jobs together require 50 threads,
but only 12 are available, we will use 5 layers. If mult... | Calculate required consecutive job layers.
Layers are used to keep resource requirements within given
constraint. For instance, if the jobs together require 50 threads,
but only 12 are available, we will use 5 layers. If multiple constraints are
used, all will be considered and met. Any... | _get_layers | python | snakemake/snakemake | src/snakemake/resources.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/resources.py | MIT |
def infer_resources(name, value, resources: dict):
"""Infer resources from a given one, if possible."""
from humanfriendly import parse_size, parse_timespan, InvalidTimespan, InvalidSize
if isinstance(value, str):
value = value.strip("'\"")
if (
(name == "mem" or name == "disk")
... | Infer resources from a given one, if possible. | infer_resources | python | snakemake/snakemake | src/snakemake/resources.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/resources.py | MIT |
def apply_modifier(
self,
modifier,
rulename,
prefix_replacables={"input", "output", "log", "benchmark"},
):
"""Update this ruleinfo with the given one (used for 'use rule' overrides)."""
path_modifier = modifier.path_modifier
skips = set()
if modifie... | Update this ruleinfo with the given one (used for 'use rule' overrides). | apply_modifier | python | snakemake/snakemake | src/snakemake/ruleinfo.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/ruleinfo.py | MIT |
def __init__(self, name, workflow, lineno=None, snakefile=None):
"""
Create a rule
Arguments
name -- the name of the rule
"""
self._name = name
self.workflow = workflow
self.docstring = None
self.message = None
self._input = InputFiles()
... |
Create a rule
Arguments
name -- the name of the rule
| __init__ | python | snakemake/snakemake | src/snakemake/rules.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/rules.py | MIT |
def set_input(self, *input, **kwinput):
"""
Add a list of input files. Recursive lists are flattened.
Arguments
input -- the list of input files
"""
consider_ancient = self.workflow.workflow_settings.consider_ancient.get(
self.name, frozenset()
)
... |
Add a list of input files. Recursive lists are flattened.
Arguments
input -- the list of input files
| set_input | python | snakemake/snakemake | src/snakemake/rules.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/rules.py | MIT |
def set_output(self, *output, **kwoutput):
"""
Add a list of output files. Recursive lists are flattened.
After creating the output files, they are checked for duplicates.
Arguments
output -- the list of output files
"""
for item in output:
# Named m... |
Add a list of output files. Recursive lists are flattened.
After creating the output files, they are checked for duplicates.
Arguments
output -- the list of output files
| set_output | python | snakemake/snakemake | src/snakemake/rules.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/rules.py | MIT |
def check_output_duplicates(self):
"""Check ``Namedlist`` for duplicate entries and raise a ``WorkflowError``
on problems. Does not raise if the entry is empty.
"""
seen = dict()
idx = None
for name, value in self.output._allitems():
if name is None:
... | Check ``Namedlist`` for duplicate entries and raise a ``WorkflowError``
on problems. Does not raise if the entry is empty.
| check_output_duplicates | python | snakemake/snakemake | src/snakemake/rules.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/rules.py | MIT |
def _set_inoutput_item(self, item, output=False, name=None, mark_ancient=False):
"""
Set an item to be input or output.
Arguments
item -- the item
inoutput -- a Namedlist of either input or output items
name -- an optional name for the item
"""
i... |
Set an item to be input or output.
Arguments
item -- the item
inoutput -- a Namedlist of either input or output items
name -- an optional name for the item
| _set_inoutput_item | python | snakemake/snakemake | src/snakemake/rules.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/rules.py | MIT |
def handle_incomplete_checkpoint(exception):
"""If checkpoint is incomplete, target it such that it is completed
before this rule gets executed."""
if exception.targetfile in input:
return TBDString()
else:
raise WorkflowError(
... | If checkpoint is incomplete, target it such that it is completed
before this rule gets executed. | handle_incomplete_checkpoint | python | snakemake/snakemake | src/snakemake/rules.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/rules.py | MIT |
def is_producer(self, requested_output):
"""
Returns True if this rule is a producer of the requested output.
"""
try:
for o in self.products():
if o.match(requested_output):
return True
return False
except sre_constants... |
Returns True if this rule is a producer of the requested output.
| is_producer | python | snakemake/snakemake | src/snakemake/rules.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/rules.py | MIT |
def get_wildcards(self, requested_output, wildcards_dict=None):
"""
Return wildcard dictionary by
1. trying to format the output with the given wildcards and comparing with the requested output
2. matching regular expression output files to the requested concrete ones.
Arguments... |
Return wildcard dictionary by
1. trying to format the output with the given wildcards and comparing with the requested output
2. matching regular expression output files to the requested concrete ones.
Arguments
requested_output -- a concrete filepath
| get_wildcards | python | snakemake/snakemake | src/snakemake/rules.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/rules.py | MIT |
def compare(self, rule1, rule2):
"""
Return whether rule2 has a higher priority than rule1.
"""
if rule1.name != rule2.name:
# try the last clause first,
# i.e. clauses added later overwrite those before.
for clause in reversed(self.order):
... |
Return whether rule2 has a higher priority than rule1.
| compare | python | snakemake/snakemake | src/snakemake/rules.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/rules.py | MIT |
def remaining_jobs(self):
"""Return jobs to be scheduled including not yet ready ones."""
return [
job
for job in self.workflow.dag.needrun_jobs()
if job not in self.running
and not self.workflow.dag.finished(job)
and job not in self.failed
... | Return jobs to be scheduled including not yet ready ones. | remaining_jobs | python | snakemake/snakemake | src/snakemake/scheduler.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/scheduler.py | MIT |
def schedule(self):
"""Schedule jobs that are ready, maximizing cpu usage."""
try:
while True:
if self.workflow.dag.queue_input_jobs:
self.update_queue_input_jobs()
# work around so that the wait does not prevent keyboard interrupts
... | Schedule jobs that are ready, maximizing cpu usage. | schedule | python | snakemake/snakemake | src/snakemake/scheduler.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/scheduler.py | MIT |
def _proceed(self, job):
"""Do stuff after job is finished."""
with self._lock:
self._tofinish.append(job)
if self.dryrun:
if len(self.running) - len(self._tofinish) - len(self._toerror) <= 0:
# During dryrun, only release when all running job... | Do stuff after job is finished. | _proceed | python | snakemake/snakemake | src/snakemake/scheduler.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/scheduler.py | MIT |
def _handle_error(self, job, postprocess_job: bool = True):
"""Clear jobs and stop the workflow.
If Snakemake is configured to restart jobs then the job might have
"restart_times" left and we just decrement and let the scheduler
try to run the job again.
"""
# must be ca... | Clear jobs and stop the workflow.
If Snakemake is configured to restart jobs then the job might have
"restart_times" left and we just decrement and let the scheduler
try to run the job again.
| _handle_error | python | snakemake/snakemake | src/snakemake/scheduler.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/scheduler.py | MIT |
def job_selector_ilp(self, jobs):
"""
Job scheduling by optimization of resource usage by solving ILP using pulp
"""
import pulp
from pulp import lpSum
if len(jobs) == 1:
return self.job_selector_greedy(jobs)
with self._lock:
if not self.... |
Job scheduling by optimization of resource usage by solving ILP using pulp
| job_selector_ilp | python | snakemake/snakemake | src/snakemake/scheduler.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/scheduler.py | MIT |
def job_selector_greedy(self, jobs):
"""
Using the greedy heuristic from
"A Greedy Algorithm for the General Multidimensional Knapsack
Problem", Akcay, Li, Xu, Annals of Operations Research, 2012
Args:
jobs (list): list of jobs
"""
logger.debug("Se... |
Using the greedy heuristic from
"A Greedy Algorithm for the General Multidimensional Knapsack
Problem", Akcay, Li, Xu, Annals of Operations Research, 2012
Args:
jobs (list): list of jobs
| job_selector_greedy | python | snakemake/snakemake | src/snakemake/scheduler.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/scheduler.py | MIT |
def general_args(
self,
executor_common_settings: CommonSettings,
) -> str:
"""Return a string to add to self.exec_job that includes additional
arguments from the command line. This is currently used in the
ClusterExecutor and CPUExecutor, as both were using the same
... | Return a string to add to self.exec_job that includes additional
arguments from the command line. This is currently used in the
ClusterExecutor and CPUExecutor, as both were using the same
code. Both have base class of the RealExecutor.
| general_args | python | snakemake/snakemake | src/snakemake/spawn_jobs.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/spawn_jobs.py | MIT |
def validate(data, schema, set_default=True):
"""Validate data with JSON schema at given path.
Args:
data (object): data to validate. Can be a config dict or a pandas data frame.
schema (str): Path to JSON schema used for validation. The schema can also be
in YAML format. If validat... | Validate data with JSON schema at given path.
Args:
data (object): data to validate. Can be a config dict or a pandas data frame.
schema (str): Path to JSON schema used for validation. The schema can also be
in YAML format. If validating a pandas data frame, the schema has to
... | validate | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def simplify_path(path):
"""Return a simplified version of the given path."""
relpath = os.path.relpath(path)
if relpath.startswith("../../"):
return path
else:
return relpath | Return a simplified version of the given path. | simplify_path | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def linecount(filename):
"""Return the number of lines of the given file.
Args:
filename (str): the path to the file
"""
with open(filename) as f:
return sum(1 for l in f) | Return the number of lines of the given file.
Args:
filename (str): the path to the file
| linecount | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def makedirs(dirnames):
"""Recursively create the given directory or directories without
reporting errors if they are present.
"""
if isinstance(dirnames, str):
dirnames = [dirnames]
for dirname in dirnames:
os.makedirs(dirname, exist_ok=True) | Recursively create the given directory or directories without
reporting errors if they are present.
| makedirs | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def report(
text,
path,
stylesheet=None,
defaultenc="utf8",
template=None,
metadata=None,
**files,
):
"""Create an HTML report using python docutils.
This is deprecated in favor of the --report flag.
Attention: This function needs Python docutils to be installed for the
pyt... | Create an HTML report using python docutils.
This is deprecated in favor of the --report flag.
Attention: This function needs Python docutils to be installed for the
python installation you use with Snakemake.
All keywords not listed below are interpreted as paths to files that shall
be embedded ... | report | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def R(code):
"""Execute R code.
This is deprecated in favor of the ``script`` directive.
This function executes the R code given as a string.
The function requires rpy2 to be installed.
Args:
code (str): R code to be executed
"""
try:
import rpy2.robjects as robjects
ex... | Execute R code.
This is deprecated in favor of the ``script`` directive.
This function executes the R code given as a string.
The function requires rpy2 to be installed.
Args:
code (str): R code to be executed
| R | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def format(_pattern, *args, stepout=1, _quote_all=False, quote_func=None, **kwargs):
"""Format a pattern in Snakemake style.
This means that keywords embedded in braces are replaced by any variable
values that are available in the current namespace.
"""
frame = inspect.currentframe().f_back
wh... | Format a pattern in Snakemake style.
This means that keywords embedded in braces are replaced by any variable
values that are available in the current namespace.
| format | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def read_job_properties(
jobscript, prefix="# properties", pattern=re.compile("# properties = (.*)")
):
"""Read the job properties defined in a snakemake jobscript.
This function is a helper for writing custom wrappers for the
snakemake --cluster functionality. Applying this function to a
jobscript... | Read the job properties defined in a snakemake jobscript.
This function is a helper for writing custom wrappers for the
snakemake --cluster functionality. Applying this function to a
jobscript will return a dict containing information about the job.
| read_job_properties | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def min_version(version):
"""Require minimum snakemake version, raise workflow error if not met."""
from packaging.version import parse
from snakemake.common import __version__
if parse(__version__) < parse(version):
raise WorkflowError(
"Expecting Snakemake version {} or higher (yo... | Require minimum snakemake version, raise workflow error if not met. | min_version | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def update_config(config, overwrite_config):
"""Recursively update dictionary config with overwrite_config in-place.
See
https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth
for details.
Args:
config (dict): dictionary to update
overwrite_con... | Recursively update dictionary config with overwrite_config in-place.
See
https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth
for details.
Args:
config (dict): dictionary to update
overwrite_config (dict): dictionary whose items will overwrite th... | update_config | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def _update_config(config, overwrite_config):
"""Necessary as recursive calls require a return value,
but `update_config()` has no return value.
"""
for key, value in overwrite_config.items():
if not isinstance(config, collections.abc.Mapping):
# the config ca... | Necessary as recursive calls require a return value,
but `update_config()` has no return value.
| _update_config | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def available_cpu_count():
"""
Return the number of available virtual or physical CPUs on this system.
The number of available CPUs can be smaller than the total number of CPUs
when the cpuset(7) mechanism is in use, as is the case on some cluster
systems.
Adapted from https://stackoverflow.com... |
Return the number of available virtual or physical CPUs on this system.
The number of available CPUs can be smaller than the total number of CPUs
when the cpuset(7) mechanism is in use, as is the case on some cluster
systems.
Adapted from https://stackoverflow.com/a/1006301/715090
| available_cpu_count | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def argvquote(arg, force=True):
"""Returns an argument quoted in such a way that CommandLineToArgvW
on Windows will return the argument string unchanged.
This is the same thing Popen does when supplied with a list of arguments.
Arguments in a command line should be separated by spaces; this
function... | Returns an argument quoted in such a way that CommandLineToArgvW
on Windows will return the argument string unchanged.
This is the same thing Popen does when supplied with a list of arguments.
Arguments in a command line should be separated by spaces; this
function does not add these spaces. This implem... | argvquote | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def cmd_exe_quote(arg):
"""Quotes an argument in a cmd.exe compliant way."""
arg = argvquote(arg)
cmd_exe_metachars = '^()%!"<>&|'
for char in cmd_exe_metachars:
arg.replace(char, "^" + char)
return arg | Quotes an argument in a cmd.exe compliant way. | cmd_exe_quote | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def find_bash_on_windows():
"""
Find the path to a usable bash on windows.
The first attempt is to look for a bash installed with a git conda package.
Alternatively, try bash installed with 'Git for Windows'.
"""
if not ON_WINDOWS:
return None
# First look for bash in git's conda pac... |
Find the path to a usable bash on windows.
The first attempt is to look for a bash installed with a git conda package.
Alternatively, try bash installed with 'Git for Windows'.
| find_bash_on_windows | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def wildcard_pattern(self):
"""Wildcard pattern over all columns of the underlying dataframe of the form
column1~{column1}/column2~{column2}/*** or of the provided custom pattern.
"""
if self.single_wildcard:
return f"{{{self.single_wildcard}}}"
else:
retu... | Wildcard pattern over all columns of the underlying dataframe of the form
column1~{column1}/column2~{column2}/*** or of the provided custom pattern.
| wildcard_pattern | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def instance_patterns(self):
"""Iterator over all instances of the parameter space (dataframe rows),
formatted as file patterns of the form column1~{value1}/column2~{value2}/...
or of the provided custom pattern.
"""
import pandas as pd
fmt_value = lambda value: "NA" if ... | Iterator over all instances of the parameter space (dataframe rows),
formatted as file patterns of the form column1~{value1}/column2~{value2}/...
or of the provided custom pattern.
| instance_patterns | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def instance(self, wildcards):
"""Obtain instance (dataframe row) with the given wildcard values."""
import pandas as pd
from snakemake.io import regex_from_filepattern
def convert_value_dtype(name, value):
if self.dataframe.dtypes[name] == bool and value == "False":
... | Obtain instance (dataframe row) with the given wildcard values. | instance | python | snakemake/snakemake | src/snakemake/utils.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/utils.py | MIT |
def cleanup_source_archive(self):
"""cleanup source archive form remote storage"""
if self._source_archive is not None:
obj = self.storage_registry.default_storage_provider.object(
self._source_archive.query
)
async_run(obj.managed_remove()) | cleanup source archive form remote storage | cleanup_source_archive | python | snakemake/snakemake | src/snakemake/workflow.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/workflow.py | MIT |
def get_rule(self, name):
"""
Get rule by name.
Arguments
name -- the name of the rule
"""
if not self._rules:
raise NoRulesException()
if name not in self._rules:
raise UnknownRuleException(name)
return self._rules[name] |
Get rule by name.
Arguments
name -- the name of the rule
| get_rule | python | snakemake/snakemake | src/snakemake/workflow.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/workflow.py | MIT |
def inputfile(self, path):
"""Mark file as being an input file of the workflow.
This also means that eventual --default-remote-provider/prefix settings
will be applied to this file. The file is returned as _IOFile object,
such that it can e.g. be transparently opened with _IOFile.open()... | Mark file as being an input file of the workflow.
This also means that eventual --default-remote-provider/prefix settings
will be applied to this file. The file is returned as _IOFile object,
such that it can e.g. be transparently opened with _IOFile.open().
| inputfile | python | snakemake/snakemake | src/snakemake/workflow.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/workflow.py | MIT |
def generate_unit_tests(self, path: Path):
"""Generate unit tests for the workflow.
Arguments
path -- Path to the directory where the unit tests shall be generated.
"""
from snakemake import unit_tests
assert self.dag_settings is not None
self._prepare_dag(
... | Generate unit tests for the workflow.
Arguments
path -- Path to the directory where the unit tests shall be generated.
| generate_unit_tests | python | snakemake/snakemake | src/snakemake/workflow.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/workflow.py | MIT |
def export_cwl(self, path: Path):
"""Export the workflow as CWL document.
Arguments
path -- the path to the CWL document to be created.
"""
assert self.dag_settings is not None
self._prepare_dag(
forceall=self.dag_settings.forceall,
ignore_incompl... | Export the workflow as CWL document.
Arguments
path -- the path to the CWL document to be created.
| export_cwl | python | snakemake/snakemake | src/snakemake/workflow.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/workflow.py | MIT |
def source_path(self, rel_path):
"""Return path to source file from work dir derived from given path relative to snakefile"""
# TODO download to disk (use source cache) in case of remote file
import inspect
frame = inspect.currentframe()
assert frame is not None and frame.f_back... | Return path to source file from work dir derived from given path relative to snakefile | source_path | python | snakemake/snakemake | src/snakemake/workflow.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/workflow.py | MIT |
def register_envvars(self, *envvars):
"""
Register environment variables that shall be passed to jobs.
If used multiple times, union is taken.
"""
invalid_envvars = [
envvar
for envvar in envvars
if re.match(r"^\w+$", envvar, flags=re.ASCII) is... |
Register environment variables that shall be passed to jobs.
If used multiple times, union is taken.
| register_envvars | python | snakemake/snakemake | src/snakemake/workflow.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/workflow.py | MIT |
def configfile(self, fp):
"""Update the global config with data from the given file."""
from snakemake.common.configfile import load_configfile
if not self.modifier.skip_configfile:
if os.path.exists(fp):
self.configfiles.append(fp)
c = load_configfil... | Update the global config with data from the given file. | configfile | python | snakemake/snakemake | src/snakemake/workflow.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/workflow.py | MIT |
def report(self, path):
"""Define a global report description in .rst format."""
if not self.modifier.skip_global_report_caption:
self.report_text = self.current_basedir.join(path) | Define a global report description in .rst format. | report | python | snakemake/snakemake | src/snakemake/workflow.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/workflow.py | MIT |
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,
sha... |
Load a wrapper from https://github.com/snakemake/snakemake-wrappers under
the given path + wrapper.(py|R|Rmd) and execute it.
| wrapper | python | snakemake/snakemake | src/snakemake/wrapper.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/wrapper.py | MIT |
def _get_provenance_hash(self, job: Job, cache_mode: str):
"""
Recursively calculate hash for the output of the given job
and all upstream jobs in a blockchain fashion.
This is based on an idea of Sven Nahnsen.
Fails if job has more than one output file. The reason is that there... |
Recursively calculate hash for the output of the given job
and all upstream jobs in a blockchain fashion.
This is based on an idea of Sven Nahnsen.
Fails if job has more than one output file. The reason is that there
is no way to generate a per-output file hash without generati... | _get_provenance_hash | python | snakemake/snakemake | src/snakemake/caching/hash.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/caching/hash.py | MIT |
async def store(self, job: Job, cache_mode: str):
"""
Store generated job output in the cache.
"""
if not os.access(self.path, os.W_OK):
raise WorkflowError(
"Cannot access cache location {}. Please ensure that "
"it is present and writeable."... |
Store generated job output in the cache.
| store | python | snakemake/snakemake | src/snakemake/caching/local.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/caching/local.py | MIT |
async def fetch(self, job: Job, cache_mode: str):
"""
Retrieve cached output file and symlink to the place where the job expects it's output.
"""
for outputfile, cachefile in self.get_outputfiles_and_cachefiles(
job, cache_mode
):
if not cachefile.exists()... |
Retrieve cached output file and symlink to the place where the job expects it's output.
| fetch | python | snakemake/snakemake | src/snakemake/caching/local.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/caching/local.py | MIT |
async def exists(self, job: Job, cache_mode: str):
"""
Return True if job is already cached
"""
for outputfile, cachefile in self.get_outputfiles_and_cachefiles(
job, cache_mode
):
if not cachefile.exists():
return False
logger... |
Return True if job is already cached
| exists | python | snakemake/snakemake | src/snakemake/caching/local.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/caching/local.py | MIT |
def _load_configfile(configpath_or_obj, filetype="Config"):
"Tries to load a configfile first as JSON, then as YAML, into a dict."
import yaml
if isinstance(configpath_or_obj, str) or isinstance(configpath_or_obj, Path):
obj = open(configpath_or_obj, encoding="utf-8")
else:
obj = config... | Tries to load a configfile first as JSON, then as YAML, into a dict. | _load_configfile | python | snakemake/snakemake | src/snakemake/common/configfile.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/configfile.py | MIT |
def load_configfile(configpath):
"Loads a JSON or YAML configfile as a dict, then checks that it's a dict."
config = _load_configfile(configpath)
if not isinstance(config, dict):
raise WorkflowError(
"Config file must be given as JSON or YAML with keys at top level."
)
return... | Loads a JSON or YAML configfile as a dict, then checks that it's a dict. | load_configfile | python | snakemake/snakemake | src/snakemake/common/configfile.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/configfile.py | MIT |
def get_git_root(path):
"""
Args:
path: (str) Path a to a directory/file that is located inside the repo
Returns:
path to the root folder for git repo
"""
import git
try:
git_repo = git.Repo(path, search_parent_directories=True)
return git_repo.git.rev_parse("--s... |
Args:
path: (str) Path a to a directory/file that is located inside the repo
Returns:
path to the root folder for git repo
| get_git_root | python | snakemake/snakemake | src/snakemake/common/git.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/git.py | MIT |
def get_git_root_parent_directory(path, input_path):
"""
This function will recursively go through parent directories until a git
repository is found or until no parent directories are left, in which case
an error will be raised. This is needed when providing a path to a
file/folder that is located ... |
This function will recursively go through parent directories until a git
repository is found or until no parent directories are left, in which case
an error will be raised. This is needed when providing a path to a
file/folder that is located on a branch/tag not currently checked out.
Args:
... | get_git_root_parent_directory | python | snakemake/snakemake | src/snakemake/common/git.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/git.py | MIT |
def git_content(git_file):
"""
This function will extract a file from a git repository, one located on
the filesystem.
The expected format is git+file:///path/to/your/repo/path_to_file@version
Args:
env_file (str): consist of path to repo, @, version, and file information
... |
This function will extract a file from a git repository, one located on
the filesystem.
The expected format is git+file:///path/to/your/repo/path_to_file@version
Args:
env_file (str): consist of path to repo, @, version, and file information
Ex: git+file:///home/smeds/snake... | git_content | python | snakemake/snakemake | src/snakemake/common/git.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/git.py | MIT |
def match_iter(self, query: str) -> Generator[V, None, None]:
"""Yields all entries which are prefixes of the given key.
E.g. if "abc" is the key then "abc", "ab", "a", and "" are considered
valid prefixes.
Yields entries as (key, value) tuples as supplied to __init__()
"""
... | Yields all entries which are prefixes of the given key.
E.g. if "abc" is the key then "abc", "ab", "a", and "" are considered
valid prefixes.
Yields entries as (key, value) tuples as supplied to __init__()
| match_iter | python | snakemake/snakemake | src/snakemake/common/prefix_lookup.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/prefix_lookup.py | MIT |
def _common_prefix(self, s1: str, s2: str) -> str:
"""Utility function that gives the common prefix of two strings.
Except, if the strings are identical, returns the string minus one letter.
Behaviour is undefined if either string is empty.
"""
for i, (l1, l2) in enumerate(zip(s... | Utility function that gives the common prefix of two strings.
Except, if the strings are identical, returns the string minus one letter.
Behaviour is undefined if either string is empty.
| _common_prefix | python | snakemake/snakemake | src/snakemake/common/prefix_lookup.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/prefix_lookup.py | MIT |
def async_run(coroutine):
"""Attaches to running event loop or creates a new one to execute a
coroutine.
.. seealso::
https://github.com/snakemake/snakemake/issues/1105
https://stackoverflow.com/a/65696398
"""
try:
return asyncio.run(coroutine)
except RuntimeError as e:... | Attaches to running event loop or creates a new one to execute a
coroutine.
.. seealso::
https://github.com/snakemake/snakemake/issues/1105
https://stackoverflow.com/a/65696398
| async_run | python | snakemake/snakemake | src/snakemake/common/__init__.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/__init__.py | MIT |
def num_if_possible(s):
"""Convert string to number if possible, otherwise return string."""
try:
return int(s)
except ValueError:
try:
return float(s)
except ValueError:
return s | Convert string to number if possible, otherwise return string. | num_if_possible | python | snakemake/snakemake | src/snakemake/common/__init__.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/__init__.py | MIT |
def get_file_hash(filename, algorithm="sha256"):
"""find the SHA256 hash string of a file. We use this so that the
user can choose to cache working directories in storage.
"""
from snakemake.logging import logger
# The algorithm must be available
try:
hasher = hashlib.new(algorithm)
... | find the SHA256 hash string of a file. We use this so that the
user can choose to cache working directories in storage.
| get_file_hash | python | snakemake/snakemake | src/snakemake/common/__init__.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/__init__.py | MIT |
def bytesto(bytes, to, bsize=1024):
"""convert bytes to megabytes.
bytes to mb: bytesto(bytes, 'm')
bytes to gb: bytesto(bytes, 'g' etc.
From https://gist.github.com/shawnbutts/3906915
"""
levels = {"k": 1, "m": 2, "g": 3, "t": 4, "p": 5, "e": 6}
answer = float(bytes)
for _ in range(leve... | convert bytes to megabytes.
bytes to mb: bytesto(bytes, 'm')
bytes to gb: bytesto(bytes, 'g' etc.
From https://gist.github.com/shawnbutts/3906915
| bytesto | python | snakemake/snakemake | src/snakemake/common/__init__.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/__init__.py | MIT |
def group_into_chunks(n, iterable):
"""Group iterable into chunks of size at most n.
See https://stackoverflow.com/a/8998040.
"""
it = iter(iterable)
while True:
chunk = tuple(itertools.islice(it, n))
if not chunk:
return
yield chunk | Group iterable into chunks of size at most n.
See https://stackoverflow.com/a/8998040.
| group_into_chunks | python | snakemake/snakemake | src/snakemake/common/__init__.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/__init__.py | MIT |
def unique_justseen(iterable, key=None):
"""
List unique elements, preserving order. Remember only the element just seen.
From https://docs.python.org/3/library/itertools.html#itertools-recipes
"""
# unique_justseen('AAAABBBCCDAABBB') --> A B C D A B
# unique_justseen('ABBcCAD', str.lower) --> ... |
List unique elements, preserving order. Remember only the element just seen.
From https://docs.python.org/3/library/itertools.html#itertools-recipes
| unique_justseen | python | snakemake/snakemake | src/snakemake/common/__init__.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/__init__.py | MIT |
def set_env(**environ):
"""
Temporarily set the process environment variables.
>>> with set_env(PLUGINS_DIR='test/plugins'):
... "PLUGINS_DIR" in os.environ
True
>>> "PLUGINS_DIR" in os.environ
False
:type environ: Dict[str, unicode]
:param environ: Environment variables to set
... |
Temporarily set the process environment variables.
>>> with set_env(PLUGINS_DIR='test/plugins'):
... "PLUGINS_DIR" in os.environ
True
>>> "PLUGINS_DIR" in os.environ
False
:type environ: Dict[str, unicode]
:param environ: Environment variables to set
| set_env | python | snakemake/snakemake | src/snakemake/common/__init__.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/__init__.py | MIT |
def copy_permission_safe(src: str, dst: str):
"""Copy a file to a given destination.
If destination exists, it is removed first in order to avoid permission issues when
the destination permissions are tried to be applied to an already existing
destination.
"""
if os.path.exists(dst):
os... | Copy a file to a given destination.
If destination exists, it is removed first in order to avoid permission issues when
the destination permissions are tried to be applied to an already existing
destination.
| copy_permission_safe | python | snakemake/snakemake | src/snakemake/common/__init__.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/common/__init__.py | MIT |
def address(self):
"""Path to directory of the conda environment.
First tries full hash, if it does not exist, (8-prefix) is used
as default.
"""
if self.name:
return self.name
elif self.dir:
return self.dir
else:
env_dir = se... | Path to directory of the conda environment.
First tries full hash, if it does not exist, (8-prefix) is used
as default.
| address | python | snakemake/snakemake | src/snakemake/deployment/conda.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/deployment/conda.py | MIT |
def archive_file(self):
"""Path to archive of the conda environment, which may or may not exist."""
if self._archive_file is None:
self._archive_file = os.path.join(self._env_archive_dir, self.content_hash)
return self._archive_file | Path to archive of the conda environment, which may or may not exist. | archive_file | python | snakemake/snakemake | src/snakemake/deployment/conda.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/deployment/conda.py | MIT |
def create_archive(self):
"""Create self-contained archive of environment."""
from snakemake.shell import shell
# importing requests locally because it interferes with instantiating conda environments
import requests
self.check_is_file_based()
env_archive = self.archiv... | Create self-contained archive of environment. | create_archive | python | snakemake/snakemake | src/snakemake/deployment/conda.py | https://github.com/snakemake/snakemake/blob/master/src/snakemake/deployment/conda.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.