Пример #1
0
 def apply_input_function(self,
                          func,
                          wildcards,
                          incomplete_checkpoint_func=lambda e: None,
                          raw_exceptions=False,
                          **aux_params):
     incomplete = False
     if isinstance(func, _IOFile):
         func = func._file.callable
     elif isinstance(func, AnnotatedString):
         func = func.callable
     sig = inspect.signature(func)
     _aux_params = {
         k: v
         for k, v in aux_params.items() if k in sig.parameters
     }
     try:
         value = func(Wildcards(fromdict=wildcards), **_aux_params)
     except IncompleteCheckpointException as e:
         value = incomplete_checkpoint_func(e)
         incomplete = True
     except FileNotFoundError as e:
         # Function evaluation can depend on input files. Since expansion can happen during dryrun,
         # where input files are not yet present, we need to skip such cases and
         # mark them as <TBD>.
         if e.filename in aux_params["input"]:
             value = TBDString()
         else:
             raise e
     except (Exception, BaseException) as e:
         if raw_exceptions:
             raise e
         else:
             raise InputFunctionException(e, rule=self, wildcards=wildcards)
     return value, incomplete
Пример #2
0
 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(
             "Rule parameter depends on checkpoint but checkpoint output is not defined as input file for the rule. "
             "Please add the output of the respective checkpoint to the rule inputs."
         )
Пример #3
0
def format_files(job, io, dynamicio):
    for f in io:
        if f in dynamicio:
            yield "{} (dynamic)".format(f.format_dynamic())
        elif is_flagged(f, "pipe"):
            yield "{} (pipe)".format(f)
        elif is_flagged(f, "checkpoint_target"):
            yield TBDString()
        else:
            yield f
Пример #4
0
    def apply_input_function(
        self,
        func,
        wildcards,
        incomplete_checkpoint_func=lambda e: None,
        raw_exceptions=False,
        groupid=None,
        **aux_params,
    ):
        incomplete = False
        if isinstance(func, _IOFile):
            func = func._file.callable
        elif isinstance(func, AnnotatedString):
            func = func.callable

        if "groupid" in get_function_params(func):
            if groupid is not None:
                aux_params["groupid"] = groupid
            else:
                # Return empty list of files and incomplete marker
                # the job will be reevaluated once groupids have been determined
                return [], True

        _aux_params = get_input_function_aux_params(func, aux_params)

        try:
            value = func(Wildcards(fromdict=wildcards), **_aux_params)
            if isinstance(value, types.GeneratorType):
                # generators should be immediately collected here,
                # otherwise we would miss any exceptions and
                # would have to capture them again later.
                value = list(value)
        except IncompleteCheckpointException as e:
            value = incomplete_checkpoint_func(e)
            incomplete = True
        except FileNotFoundError as e:
            # Function evaluation can depend on input files. Since expansion can happen during dryrun,
            # where input files are not yet present, we need to skip such cases and
            # mark them as <TBD>.
            if "input" in aux_params and e.filename in aux_params["input"]:
                value = TBDString()
            else:
                raise e
        except (Exception, BaseException) as e:
            if raw_exceptions:
                raise e
            else:
                raise InputFunctionException(e, rule=self, wildcards=wildcards)
        return value, incomplete