Exemplo n.º 1
0
 def _apply_wildcards(
     newitems,
     olditems,
     wildcards,
     wildcards_obj,
     concretize = apply_wildcards,
     ruleio = None):
     for name, item in olditems.allitems():
         start = len(newitems)
         if callable(item):
             item = item(wildcards_obj)
             if not_iterable(item):
                 item = [item]
             for item_ in item:
                 if not isinstance(item_, str):
                     raise RuleException("Input function did not return str or list of str.", rule=self)
                 concrete = concretize(item_, wildcards)
                 newitems.append(concrete)
                 if ruleio is not None:
                     ruleio[concrete] = item_
         else:
             if not_iterable(item):
                 item = [item]
             for item_ in item:
                 concrete = concretize(item_, wildcards)
                 newitems.append(concrete)
                 if ruleio is not None:
                     ruleio[concrete] = item_
         if name:
             newitems.set_name(name, start, end=len(newitems))
Exemplo n.º 2
0
        def _apply_wildcards(newitems, olditems, wildcards, wildcards_obj,
                             concretize=apply_wildcards,
                             check_return_type=check_string_type,
                             ruleio=None,
                             no_flattening=False):
            for name, item in olditems.allitems():
                start = len(newitems)
                is_iterable = True

                if callable(item):
                    try:
                        item = item(wildcards_obj)
                    except (Exception, BaseException) as e:
                        raise InputFunctionException(e, rule=self, wildcards=wildcards)

                if not_iterable(item) or no_flattening:
                    item = [item]
                    is_iterable = False
                for item_ in item:
                    check_return_type(item_)
                    concrete = concretize(item_, wildcards)
                    newitems.append(concrete)
                    if ruleio is not None:
                        ruleio[concrete] = item_

                if name:
                    newitems.set_name(
                        name, start,
                        end=len(newitems) if is_iterable else None)
Exemplo n.º 3
0
 def target(self, paths):
     if not_iterable(paths):
         return flag(os.path.join(self.workdir, paths), "subworkflow", self)
     return [self.target(path) for path in paths]