def ctx_enter(cls, path, access): """ Function on context enter. :param cls: ``class`` object :param path: file path :param access: access permission ('r' - read, 'w' - write, 'rw' - edit) :return: an instance of ``cls`` """ obj = None if path and 'r' in access: cwl = from_file(path) if isinstance(cwl, dict): if "class" in cwl: if cwl['class'] == cls.__name__: obj = cls(**cwl) else: raise ValueError("Expected class={}, got class={}".format( cls.__name__, cwl['class'])) else: raise ValueError("Missing class key.") else: raise ValueError('Type Error, got: {}'.format(type(cwl))) if not obj: obj = cls() return obj
def load(cwl): """ Loads CWL document from file or JSON object and instantiate object of a class specified by key ``class`` inside a document. :param cwl: file (can be either in ``JSON`` or ``YAML`` format) :return: depending on ``class`` can be either an instance of ``CommandLineTool`` or ``ExpressionTool`` or ``Workflow`` """ if not isinstance(cwl, dict): cwl = from_file(cwl) if isinstance(cwl, dict): if "class" in cwl: if cwl['class'] == 'CommandLineTool': return CommandLineTool(**cwl) elif cwl['class'] == 'Workflow': return Workflow(**cwl) elif cwl['class'] == 'ExpressionTool': return ExpressionTool(**cwl) else: raise ValueError("Unsupported class: {}".format(cwl['class'])) else: raise ValueError("Missing class key.") else: raise ValueError('Type Error, got: {}'.format(type(cwl)))
def resolve_salad(self): x = dict() for k, v in self.items(): if k == "$mixin": d = from_file(self["$mixin"]) for k2, v2 in d.items(): if k2 not in self: x[k2] = v2 else: x[k] = v return x
def resolve_salad(self): return resolve(from_file(self["$import"]))