Source code for gxformat2.schema.native_v0_1
#
# This file was autogenerated using schema-salad-tool --codegen=python
# The code itself is released under the Apache 2.0 license and the help text is
# subject to the license of the original schema.
import copy
import logging
import os
import pathlib
import tempfile
import uuid as _uuid__ # pylint: disable=unused-import # noqa: F401
import xml.sax # nosec
from abc import ABC, abstractmethod
from collections.abc import MutableMapping, MutableSequence, Sequence
from io import StringIO
from itertools import chain
from typing import Any, Final, Optional, Union, cast
from urllib.parse import quote, urldefrag, urlparse, urlsplit, urlunsplit
from urllib.request import pathname2url
from rdflib import Graph
from rdflib.plugins.parsers.notation3 import BadSyntax
from ruamel.yaml.comments import CommentedMap
from schema_salad.exceptions import SchemaSaladException, ValidationException
from schema_salad.fetcher import DefaultFetcher, Fetcher, MemoryCachingFetcher
from schema_salad.sourceline import SourceLine, add_lc_filename
from schema_salad.utils import CacheType, yaml_no_ts # requires schema-salad v8.2+
_vocab: dict[str, str] = {}
_rvocab: dict[str, str] = {}
_logger: Final = logging.getLogger("salad")
IdxType = MutableMapping[str, tuple[Any, "LoadingOptions"]]
[docs]
class LoadingOptions:
idx: Final[IdxType]
fileuri: Final[Optional[str]]
baseuri: Final[str]
namespaces: Final[MutableMapping[str, str]]
schemas: Final[MutableSequence[str]]
original_doc: Final[Optional[Any]]
addl_metadata: Final[MutableMapping[str, Any]]
fetcher: Final[Fetcher]
vocab: Final[dict[str, str]]
rvocab: Final[dict[str, str]]
cache: Final[CacheType]
imports: Final[list[str]]
includes: Final[list[str]]
no_link_check: Final[Optional[bool]]
container: Final[Optional[str]]
def __init__(
self,
fetcher: Optional[Fetcher] = None,
namespaces: Optional[dict[str, str]] = None,
schemas: Optional[list[str]] = None,
fileuri: Optional[str] = None,
copyfrom: Optional["LoadingOptions"] = None,
original_doc: Optional[Any] = None,
addl_metadata: Optional[dict[str, str]] = None,
baseuri: Optional[str] = None,
idx: Optional[IdxType] = None,
imports: Optional[list[str]] = None,
includes: Optional[list[str]] = None,
no_link_check: Optional[bool] = None,
container: Optional[str] = None,
) -> None:
"""Create a LoadingOptions object."""
self.original_doc = original_doc
if idx is not None:
temp_idx = idx
else:
temp_idx = copyfrom.idx if copyfrom is not None else {}
self.idx = temp_idx
if fileuri is not None:
temp_fileuri: Optional[str] = fileuri
else:
temp_fileuri = copyfrom.fileuri if copyfrom is not None else None
self.fileuri = temp_fileuri
if baseuri is not None:
temp_baseuri = baseuri
else:
temp_baseuri = copyfrom.baseuri if copyfrom is not None else ""
self.baseuri = temp_baseuri
if namespaces is not None:
temp_namespaces: MutableMapping[str, str] = namespaces
else:
temp_namespaces = copyfrom.namespaces if copyfrom is not None else {}
self.namespaces = temp_namespaces
if schemas is not None:
temp_schemas: MutableSequence[str] = schemas
else:
temp_schemas = copyfrom.schemas if copyfrom is not None else []
self.schemas = temp_schemas
if addl_metadata is not None:
temp_addl_metadata: MutableMapping[str, Any] = addl_metadata
else:
temp_addl_metadata = copyfrom.addl_metadata if copyfrom is not None else {}
self.addl_metadata = temp_addl_metadata
if imports is not None:
temp_imports = imports
else:
temp_imports = copyfrom.imports if copyfrom is not None else []
self.imports = temp_imports
if includes is not None:
temp_includes = includes
else:
temp_includes = copyfrom.includes if copyfrom is not None else []
self.includes = temp_includes
if no_link_check is not None:
temp_no_link_check: Optional[bool] = no_link_check
else:
temp_no_link_check = copyfrom.no_link_check if copyfrom is not None else False
self.no_link_check = temp_no_link_check
if container is not None:
temp_container: Optional[str] = container
else:
temp_container = copyfrom.container if copyfrom is not None else None
self.container = temp_container
if fetcher is not None:
temp_fetcher = fetcher
elif copyfrom is not None:
temp_fetcher = copyfrom.fetcher
else:
import requests
from cachecontrol.caches import SeparateBodyFileCache
from cachecontrol.wrapper import CacheControl
root = pathlib.Path(os.environ.get("HOME", tempfile.gettempdir()))
session = CacheControl(
requests.Session(),
cache=SeparateBodyFileCache(root / ".cache" / "salad"),
)
temp_fetcher = DefaultFetcher({}, session)
self.fetcher = temp_fetcher
self.cache = self.fetcher.cache if isinstance(self.fetcher, MemoryCachingFetcher) else {}
if self.namespaces != {}:
temp_vocab = _vocab.copy()
temp_rvocab = _rvocab.copy()
for k, v in self.namespaces.items():
temp_vocab[k] = v
temp_rvocab[v] = k
else:
temp_vocab = _vocab
temp_rvocab = _rvocab
self.vocab = temp_vocab
self.rvocab = temp_rvocab
@property
def graph(self) -> Graph:
"""Generate a merged rdflib.Graph from all entries in self.schemas."""
graph = Graph()
if not self.schemas:
return graph
key: Final = str(hash(tuple(self.schemas)))
if key in self.cache:
return cast(Graph, self.cache[key])
for schema in self.schemas:
fetchurl = (
self.fetcher.urljoin(self.fileuri, schema)
if self.fileuri is not None
else pathlib.Path(schema).resolve().as_uri()
)
if fetchurl not in self.cache or self.cache[fetchurl] is True:
_logger.debug("Getting external schema %s", fetchurl)
try:
content = self.fetcher.fetch_text(fetchurl)
except Exception as e:
_logger.warning("Could not load extension schema %s: %s", fetchurl, str(e))
continue
newGraph = Graph()
err_msg = "unknown error"
for fmt in ["xml", "turtle"]:
try:
newGraph.parse(data=content, format=fmt, publicID=str(fetchurl))
self.cache[fetchurl] = newGraph
graph += newGraph
break
except (xml.sax.SAXParseException, TypeError, BadSyntax) as e:
err_msg = str(e)
else:
_logger.warning("Could not load extension schema %s: %s", fetchurl, err_msg)
self.cache[key] = graph
return graph
[docs]
class Saveable(ABC):
"""Mark classes than have a save() and fromDoc() function."""
[docs]
@classmethod
@abstractmethod
def fromDoc(
cls,
_doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
) -> "Saveable":
"""Construct this object from the result of yaml.load()."""
[docs]
@abstractmethod
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
"""Convert this object to a JSON/YAML friendly dictionary."""
[docs]
def load_field(
val: Union[str, dict[str, str]],
fieldtype: "_Loader",
baseuri: str,
loadingOptions: LoadingOptions,
lc: Optional[list[Any]] = None,
) -> Any:
"""Load field."""
if isinstance(val, MutableMapping):
if "$import" in val:
if loadingOptions.fileuri is None:
raise SchemaSaladException("Cannot load $import without fileuri")
url1: Final = loadingOptions.fetcher.urljoin(loadingOptions.fileuri, val["$import"])
result, metadata = _document_load_by_url(
fieldtype,
url1,
loadingOptions,
)
loadingOptions.imports.append(url1)
return result
if "$include" in val:
if loadingOptions.fileuri is None:
raise SchemaSaladException("Cannot load $import without fileuri")
url2: Final = loadingOptions.fetcher.urljoin(loadingOptions.fileuri, val["$include"])
val = loadingOptions.fetcher.fetch_text(url2)
loadingOptions.includes.append(url2)
return fieldtype.load(val, baseuri, loadingOptions, lc=lc)
save_type = Optional[Union[MutableMapping[str, Any], MutableSequence[Any], int, float, bool, str]]
[docs]
def extract_type(val_type: type[Any]) -> str:
"""Take a type of value, and extracts the value as a string."""
val_str: Final = str(val_type)
return val_str.split("'")[1]
[docs]
def convert_typing(val_type: str) -> str:
"""Normalize type names to schema-salad types."""
if "None" in val_type:
return "null"
if "CommentedSeq" in val_type or "list" in val_type:
return "array"
if "CommentedMap" in val_type or "dict" in val_type:
return "object"
if "False" in val_type or "True" in val_type:
return "boolean"
return val_type
[docs]
def parse_errors(error_message: str) -> tuple[str, str, str]:
"""Parse error messages from several loaders into one error message."""
if not error_message.startswith("Expected"):
return error_message, "", ""
vals: Final = error_message.split("\n")
if len(vals) == 1:
return error_message, "", ""
types1: Final = set()
for val in vals:
individual_vals = val.split(" ")
if val == "":
continue
if individual_vals[1] == "one":
individual_vals = val.split("(")[1].split(",")
for t in individual_vals:
types1.add(t.strip(" ").strip(")\n"))
elif individual_vals[2] == "<class":
types1.add(individual_vals[3].strip(">").replace("'", ""))
elif individual_vals[0] == "Value":
types1.add(individual_vals[-1].strip("."))
else:
types1.add(individual_vals[1].replace(",", ""))
types2: Final = {val for val in types1 if val != "NoneType"}
if "str" in types2:
types3 = {convert_typing(val) for val in types2 if "'" not in val}
else:
types3 = types2
to_print = ""
for val in types3:
if "'" in val:
to_print = "value" if len(types3) == 1 else "values"
if to_print == "":
to_print = "type" if len(types3) == 1 else "types"
verb_tensage: Final = "is" if len(types3) == 1 else "are"
return str(types3).replace("{", "(").replace("}", ")").replace("'", ""), to_print, verb_tensage
[docs]
def save(
val: Any,
top: bool = True,
base_url: str = "",
relative_uris: bool = True,
) -> save_type:
if isinstance(val, Saveable):
return val.save(top=top, base_url=base_url, relative_uris=relative_uris)
if isinstance(val, MutableSequence):
return [save(v, top=False, base_url=base_url, relative_uris=relative_uris) for v in val]
if isinstance(val, MutableMapping):
newdict: Final = {}
for key in val:
newdict[key] = save(val[key], top=False, base_url=base_url, relative_uris=relative_uris)
return newdict
if val is None or isinstance(val, (int, float, bool, str)):
return val
raise Exception("Not Saveable: %s" % type(val))
[docs]
def save_with_metadata(
val: Any,
valLoadingOpts: LoadingOptions,
top: bool = True,
base_url: str = "",
relative_uris: bool = True,
) -> save_type:
"""Save and set $namespaces, $schemas, $base and any other metadata fields at the top level."""
saved_val: Final = save(val, top, base_url, relative_uris)
newdict: MutableMapping[str, Any] = {}
if isinstance(saved_val, MutableSequence):
newdict = {"$graph": saved_val}
elif isinstance(saved_val, MutableMapping):
newdict = saved_val
if valLoadingOpts.namespaces:
newdict["$namespaces"] = valLoadingOpts.namespaces
if valLoadingOpts.schemas:
newdict["$schemas"] = valLoadingOpts.schemas
if valLoadingOpts.baseuri:
newdict["$base"] = valLoadingOpts.baseuri
for k, v in valLoadingOpts.addl_metadata.items():
if k not in newdict:
newdict[k] = v
return newdict
[docs]
def expand_url(
url: str,
base_url: str,
loadingOptions: LoadingOptions,
scoped_id: bool = False,
vocab_term: bool = False,
scoped_ref: Optional[int] = None,
) -> str:
if url in ("@id", "@type"):
return url
if vocab_term and url in loadingOptions.vocab:
return url
if bool(loadingOptions.vocab) and ":" in url:
prefix: Final = url.split(":")[0]
if prefix in loadingOptions.vocab:
url = loadingOptions.vocab[prefix] + url[len(prefix) + 1 :]
split1: Final = urlsplit(url)
if (
(bool(split1.scheme) and split1.scheme in loadingOptions.fetcher.supported_schemes())
or url.startswith("$(")
or url.startswith("${")
):
pass
elif scoped_id and not bool(split1.fragment):
splitbase1: Final = urlsplit(base_url)
frg: str
if bool(splitbase1.fragment):
frg = splitbase1.fragment + "/" + split1.path
else:
frg = split1.path
pt: Final = splitbase1.path if splitbase1.path != "" else "/"
url = urlunsplit((splitbase1.scheme, splitbase1.netloc, pt, splitbase1.query, frg))
elif scoped_ref is not None and not bool(split1.fragment):
splitbase2: Final = urlsplit(base_url)
sp = splitbase2.fragment.split("/")
n = scoped_ref
while n > 0 and len(sp) > 0:
sp.pop()
n -= 1
sp.append(url)
url = urlunsplit(
(
splitbase2.scheme,
splitbase2.netloc,
splitbase2.path,
splitbase2.query,
"/".join(sp),
)
)
else:
url = loadingOptions.fetcher.urljoin(base_url, url)
if vocab_term:
split2: Final = urlsplit(url)
if bool(split2.scheme):
if url in loadingOptions.rvocab:
return loadingOptions.rvocab[url]
else:
raise ValidationException(f"Term {url!r} not in vocabulary")
return url
class _Loader:
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
pass
class _AnyLoader(_Loader):
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
if doc is not None:
return doc
raise ValidationException("Expected non-null")
class _PrimitiveLoader(_Loader):
def __init__(self, tp: Union[type, tuple[type[str], type[str]]]) -> None:
self.tp: Final = tp
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
if not isinstance(doc, self.tp):
raise ValidationException(f"Expected a {self.tp} but got {doc.__class__.__name__}")
return doc
def __repr__(self) -> str:
return str(self.tp)
class _ArrayLoader(_Loader):
def __init__(self, items: _Loader) -> None:
self.items: Final = items
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
if not isinstance(doc, MutableSequence):
raise ValidationException(
f"Value is a {convert_typing(extract_type(type(doc)))}, "
f"but valid type for this field is an array."
)
r: Final[list[Any]] = []
errors: Final[list[SchemaSaladException]] = []
fields: Final[list[str]] = []
for i in range(0, len(doc)):
try:
lf = load_field(
doc[i], _UnionLoader([self, self.items]), baseuri, loadingOptions, lc=lc
)
flatten = loadingOptions.container != "@list"
if flatten and isinstance(lf, MutableSequence):
r.extend(lf)
else:
r.append(lf)
if isinstance(doc[i], CommentedMap):
if doc[i].get("id") is not None:
if doc[i].get("id") in fields:
errors.append(
ValidationException(
f"Duplicate field {doc[i].get('id')!r}",
SourceLine(doc[i], "id", str),
[],
)
)
else:
fields.append(doc[i].get("id"))
except ValidationException as e:
e = ValidationException(
"array item is invalid because", SourceLine(doc, i, str), [e]
)
errors.append(e)
if errors:
raise ValidationException("", None, errors)
return r
def __repr__(self) -> str:
return f"array<{self.items}>"
class _MapLoader(_Loader):
def __init__(
self,
values: _Loader,
name: Optional[str] = None,
container: Optional[str] = None,
no_link_check: Optional[bool] = None,
) -> None:
self.values: Final = values
self.name: Final = name
self.container: Final = container
self.no_link_check: Final = no_link_check
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
if not isinstance(doc, MutableMapping):
raise ValidationException(f"Expected a map, was {type(doc)}")
if self.container is not None or self.no_link_check is not None:
loadingOptions = LoadingOptions(
copyfrom=loadingOptions, container=self.container, no_link_check=self.no_link_check
)
r: Final[dict[str, Any]] = {}
errors: Final[list[SchemaSaladException]] = []
for k, v in doc.items():
try:
lf = load_field(v, self.values, baseuri, loadingOptions, lc)
r[k] = lf
except ValidationException as e:
errors.append(e.with_sourceline(SourceLine(doc, k, str)))
if errors:
raise ValidationException("", None, errors)
return r
def __repr__(self) -> str:
return self.name if self.name is not None else f"map<string, {self.values}>"
class _EnumLoader(_Loader):
def __init__(self, symbols: Sequence[str], name: str) -> None:
self.symbols: Final = symbols
self.name: Final = name
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
if doc in self.symbols:
return doc
raise ValidationException(f"Expected one of {self.symbols}")
def __repr__(self) -> str:
return self.name
class _SecondaryDSLLoader(_Loader):
def __init__(self, inner: _Loader) -> None:
self.inner: Final = inner
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
r: Final[list[dict[str, Any]]] = []
if isinstance(doc, MutableSequence):
for d in doc:
if isinstance(d, str):
if d.endswith("?"):
r.append({"pattern": d[:-1], "required": False})
else:
r.append({"pattern": d})
elif isinstance(d, dict):
new_dict1: dict[str, Any] = {}
dict_copy = copy.deepcopy(d)
if "pattern" in dict_copy:
new_dict1["pattern"] = dict_copy.pop("pattern")
else:
raise ValidationException(
f"Missing pattern in secondaryFiles specification entry: {d}"
)
new_dict1["required"] = (
dict_copy.pop("required") if "required" in dict_copy else None
)
if len(dict_copy):
raise ValidationException(
"Unallowed values in secondaryFiles specification entry: {}".format(
dict_copy
)
)
r.append(new_dict1)
else:
raise ValidationException(
"Expected a string or sequence of (strings or mappings)."
)
elif isinstance(doc, MutableMapping):
new_dict2: Final = {}
doc_copy: Final = copy.deepcopy(doc)
if "pattern" in doc_copy:
new_dict2["pattern"] = doc_copy.pop("pattern")
else:
raise ValidationException(
f"Missing pattern in secondaryFiles specification entry: {doc}"
)
new_dict2["required"] = doc_copy.pop("required") if "required" in doc_copy else None
if len(doc_copy):
raise ValidationException(
f"Unallowed values in secondaryFiles specification entry: {doc_copy}"
)
r.append(new_dict2)
elif isinstance(doc, str):
if doc.endswith("?"):
r.append({"pattern": doc[:-1], "required": False})
else:
r.append({"pattern": doc})
else:
raise ValidationException("Expected str or sequence of str")
return self.inner.load(r, baseuri, loadingOptions, docRoot, lc=lc)
class _RecordLoader(_Loader):
def __init__(
self,
classtype: type[Saveable],
container: Optional[str] = None,
no_link_check: Optional[bool] = None,
) -> None:
self.classtype: Final = classtype
self.container: Final = container
self.no_link_check: Final = no_link_check
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
if not isinstance(doc, MutableMapping):
raise ValidationException(
f"Value is a {convert_typing(extract_type(type(doc)))}, "
f"but valid type for this field is an object."
)
if self.container is not None or self.no_link_check is not None:
loadingOptions = LoadingOptions(
copyfrom=loadingOptions, container=self.container, no_link_check=self.no_link_check
)
return self.classtype.fromDoc(doc, baseuri, loadingOptions, docRoot=docRoot)
def __repr__(self) -> str:
return str(self.classtype.__name__)
class _ExpressionLoader(_Loader):
def __init__(self, items: type[str]) -> None:
self.items: Final = items
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
if not isinstance(doc, str):
raise ValidationException(
f"Value is a {convert_typing(extract_type(type(doc)))}, "
f"but valid type for this field is a str."
)
return doc
class _UnionLoader(_Loader):
def __init__(self, alternates: Sequence[_Loader], name: Optional[str] = None) -> None:
self.alternates = alternates
self.name: Final = name
def add_loaders(self, loaders: Sequence[_Loader]) -> None:
self.alternates = tuple(loader for loader in chain(self.alternates, loaders))
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
errors: Final = []
if lc is None:
lc = []
for t in self.alternates:
try:
return t.load(doc, baseuri, loadingOptions, docRoot=docRoot, lc=lc)
except ValidationException as e:
if isinstance(t, _ArrayLoader) and len(self.alternates) > 1:
continue
if isinstance(doc, (CommentedMap, dict)):
if "class" in doc:
if str(doc.get("class")) == str(t):
errors.append(
ValidationException(
f"Object `{baseuri.split('/')[-1]}` is not valid because:",
SourceLine(doc, next(iter(doc)), str),
[e],
)
)
else:
if "array" in str(t):
continue
else:
if "id" in doc:
id = baseuri.split("/")[-1] + "#" + str(doc.get("id"))
if "id" in lc:
errors.append(
ValidationException(
f"checking object `{id}` using `{t}`",
SourceLine(lc, "id", str),
[e],
)
)
else:
errors.append(
ValidationException(
f"checking object `{id}` using `{t}`",
SourceLine(lc, doc.get("id"), str),
[e],
)
)
else:
if not isinstance(
t, (_PrimitiveLoader)
): # avoids 'tried <class "NoneType"> was {x}' errors
errors.append(
ValidationException(f"tried `{t}` but", None, [e])
)
else:
# avoids "tried <class "CWLType"> but x" and instead returns the values for parsing
errors.append(ValidationException("", None, [e]))
if isinstance(doc, (CommentedMap, dict)) and "class" in doc:
if str(doc.get("class")) not in str(self.alternates):
errors.append(
ValidationException(
"Field `class` contains undefined reference to "
+ "`"
+ "/".join(baseuri.split("/")[0:-1])
+ "/"
+ str(doc.get("class"))
+ "`",
SourceLine(doc, "class", str),
[],
)
)
raise ValidationException("", None, errors, "*")
def __repr__(self) -> str:
return self.name if self.name is not None else " | ".join(str(a) for a in self.alternates)
class _URILoader(_Loader):
def __init__(
self,
inner: _Loader,
scoped_id: bool,
vocab_term: bool,
scoped_ref: Optional[int],
no_link_check: Optional[bool],
) -> None:
self.inner: Final = inner
self.scoped_id: Final = scoped_id
self.vocab_term: Final = vocab_term
self.scoped_ref: Final = scoped_ref
self.no_link_check: Final = no_link_check
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
if self.no_link_check is not None:
loadingOptions = LoadingOptions(
copyfrom=loadingOptions, no_link_check=self.no_link_check
)
if isinstance(doc, MutableSequence):
newdoc: Final = []
for i in doc:
if isinstance(i, str):
newdoc.append(
expand_url(
i,
baseuri,
loadingOptions,
self.scoped_id,
self.vocab_term,
self.scoped_ref,
)
)
else:
newdoc.append(i)
doc = newdoc
elif isinstance(doc, str):
doc = expand_url(
doc,
baseuri,
loadingOptions,
self.scoped_id,
self.vocab_term,
self.scoped_ref,
)
if isinstance(doc, str):
if not loadingOptions.no_link_check:
errors: Final = []
try:
if not loadingOptions.fetcher.check_exists(doc):
errors.append(
ValidationException(f"contains undefined reference to `{doc}`")
)
except ValidationException:
pass
if len(errors) > 0:
raise ValidationException("", None, errors)
return self.inner.load(doc, baseuri, loadingOptions, lc=lc)
class _TypeDSLLoader(_Loader):
def __init__(self, inner: _Loader, refScope: Optional[int], salad_version: str) -> None:
self.inner: Final = inner
self.refScope: Final = refScope
self.salad_version: Final = salad_version
def resolve(
self,
doc: str,
baseuri: str,
loadingOptions: LoadingOptions,
) -> Union[list[Union[dict[str, Any], str]], dict[str, Any], str]:
doc_ = doc
optional = False
if doc_.endswith("?"):
optional = True
doc_ = doc_[0:-1]
if doc_.endswith("[]"):
salad_versions: Final = [int(v) for v in self.salad_version[1:].split(".")]
items: Union[list[Union[dict[str, Any], str]], dict[str, Any], str] = ""
rest: Final = doc_[0:-2]
if salad_versions < [1, 3]:
if rest.endswith("[]"):
# To show the error message with the original type
return doc
else:
items = expand_url(rest, baseuri, loadingOptions, False, True, self.refScope)
else:
items = self.resolve(rest, baseuri, loadingOptions)
if isinstance(items, str):
items = expand_url(items, baseuri, loadingOptions, False, True, self.refScope)
expanded: Union[dict[str, Any], str] = {"type": "array", "items": items}
else:
expanded = expand_url(doc_, baseuri, loadingOptions, False, True, self.refScope)
if optional:
return ["null", expanded]
else:
return expanded
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
if isinstance(doc, MutableSequence):
r: Final[list[Any]] = []
for d in doc:
if isinstance(d, str):
resolved = self.resolve(d, baseuri, loadingOptions)
if isinstance(resolved, MutableSequence):
for i in resolved:
if i not in r:
r.append(i)
else:
if resolved not in r:
r.append(resolved)
else:
r.append(d)
doc = r
elif isinstance(doc, str):
doc = self.resolve(doc, baseuri, loadingOptions)
return self.inner.load(doc, baseuri, loadingOptions, lc=lc)
class _IdMapLoader(_Loader):
def __init__(self, inner: _Loader, mapSubject: str, mapPredicate: Optional[str]) -> None:
self.inner: Final = inner
self.mapSubject: Final = mapSubject
self.mapPredicate: Final = mapPredicate
def load(
self,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None,
lc: Optional[list[Any]] = None,
) -> Any:
if isinstance(doc, MutableMapping):
r: Final[list[Any]] = []
for k in doc.keys():
val = doc[k]
if isinstance(val, CommentedMap):
v = copy.copy(val)
v.lc.data = val.lc.data
v.lc.filename = val.lc.filename
v[self.mapSubject] = k
r.append(v)
elif isinstance(val, MutableMapping):
v2 = copy.copy(val)
v2[self.mapSubject] = k
r.append(v2)
else:
if self.mapPredicate:
v3 = {self.mapPredicate: val}
v3[self.mapSubject] = k
r.append(v3)
else:
raise ValidationException("No mapPredicate")
doc = r
return self.inner.load(doc, baseuri, loadingOptions, lc=lc)
def _document_load(
loader: _Loader,
doc: Union[str, MutableMapping[str, Any], MutableSequence[Any]],
baseuri: str,
loadingOptions: LoadingOptions,
addl_metadata_fields: Optional[MutableSequence[str]] = None,
) -> tuple[Any, LoadingOptions]:
if isinstance(doc, str):
return _document_load_by_url(
loader,
loadingOptions.fetcher.urljoin(baseuri, doc),
loadingOptions,
addl_metadata_fields=addl_metadata_fields,
)
if isinstance(doc, MutableMapping):
addl_metadata: Final = {}
if addl_metadata_fields is not None:
for mf in addl_metadata_fields:
if mf in doc:
addl_metadata[mf] = doc[mf]
docuri: Final = baseuri
if "$base" in doc:
baseuri = doc["$base"]
loadingOptions = LoadingOptions(
copyfrom=loadingOptions,
namespaces=doc.get("$namespaces", None),
schemas=doc.get("$schemas", None),
baseuri=doc.get("$base", None),
addl_metadata=addl_metadata,
)
doc2: Final = copy.copy(doc)
if "$namespaces" in doc2:
doc2.pop("$namespaces")
if "$schemas" in doc2:
doc2.pop("$schemas")
if "$base" in doc2:
doc2.pop("$base")
if "$graph" in doc2:
loadingOptions.idx[baseuri] = (
loader.load(doc2["$graph"], baseuri, loadingOptions),
loadingOptions,
)
else:
loadingOptions.idx[baseuri] = (
loader.load(doc2, baseuri, loadingOptions, docRoot=baseuri),
loadingOptions,
)
if docuri != baseuri:
loadingOptions.idx[docuri] = loadingOptions.idx[baseuri]
return loadingOptions.idx[baseuri]
if isinstance(doc, MutableSequence):
loadingOptions.idx[baseuri] = (
loader.load(doc, baseuri, loadingOptions),
loadingOptions,
)
return loadingOptions.idx[baseuri]
raise ValidationException(
"Expected URI string, MutableMapping or MutableSequence, got %s" % type(doc)
)
def _document_load_by_url(
loader: _Loader,
url: str,
loadingOptions: LoadingOptions,
addl_metadata_fields: Optional[MutableSequence[str]] = None,
) -> tuple[Any, LoadingOptions]:
if url in loadingOptions.idx:
return loadingOptions.idx[url]
doc_url, frg = urldefrag(url)
text: Final = loadingOptions.fetcher.fetch_text(doc_url)
textIO: Final = StringIO(text)
textIO.name = str(doc_url)
yaml: Final = yaml_no_ts()
result: Final = yaml.load(textIO)
add_lc_filename(result, doc_url)
loadingOptions = LoadingOptions(copyfrom=loadingOptions, fileuri=doc_url)
_document_load(
loader,
result,
doc_url,
loadingOptions,
addl_metadata_fields=addl_metadata_fields,
)
return loadingOptions.idx[url]
[docs]
def file_uri(path: str, split_frag: bool = False) -> str:
"""Transform a file path into a URL with file scheme."""
if path.startswith("file://"):
return path
if split_frag:
pathsp: Final = path.split("#", 2)
frag = "#" + quote(str(pathsp[1])) if len(pathsp) == 2 else ""
urlpath = pathname2url(str(pathsp[0]))
else:
urlpath = pathname2url(path)
frag = ""
if urlpath.startswith("//"):
return f"file:{urlpath}{frag}"
return f"file://{urlpath}{frag}"
[docs]
def prefix_url(url: str, namespaces: dict[str, str]) -> str:
"""Expand short forms into full URLs using the given namespace dictionary."""
for k, v in namespaces.items():
if url.startswith(v):
return k + ":" + url[len(v) :]
return url
[docs]
def save_relative_uri(
uri: Any,
base_url: str,
scoped_id: bool,
ref_scope: Optional[int],
relative_uris: bool,
) -> Any:
"""Convert any URI to a relative one, obeying the scoping rules."""
if isinstance(uri, MutableSequence):
return [save_relative_uri(u, base_url, scoped_id, ref_scope, relative_uris) for u in uri]
elif isinstance(uri, str):
if not relative_uris or uri == base_url:
return uri
urisplit: Final = urlsplit(uri)
basesplit: Final = urlsplit(base_url)
if urisplit.scheme == basesplit.scheme and urisplit.netloc == basesplit.netloc:
if urisplit.path != basesplit.path:
p = os.path.relpath(urisplit.path, os.path.dirname(basesplit.path))
if urisplit.fragment:
p = p + "#" + urisplit.fragment
return p
basefrag = basesplit.fragment + "/"
if ref_scope:
sp = basefrag.split("/")
i = 0
while i < ref_scope:
sp.pop()
i += 1
basefrag = "/".join(sp)
if urisplit.fragment.startswith(basefrag):
return urisplit.fragment[len(basefrag) :]
return urisplit.fragment
return uri
else:
return save(uri, top=False, base_url=base_url, relative_uris=relative_uris)
[docs]
def shortname(inputid: str) -> str:
"""
Compute the shortname of a fully qualified identifier.
See https://w3id.org/cwl/v1.2/SchemaSalad.html#Short_names.
"""
parsed_id: Final = urlparse(inputid)
if parsed_id.fragment:
return parsed_id.fragment.split("/")[-1]
return parsed_id.path.split("/")[-1]
[docs]
class RecordField(Documented):
"""
A field of a record.
"""
name: str
def __init__(
self,
name: Any,
type_: Any,
doc: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.doc = doc
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
self.type_ = type_
def __eq__(self, other: Any) -> bool:
if isinstance(other, RecordField):
return bool(
self.doc == other.doc
and self.name == other.name
and self.type_ == other.type_
)
return False
def __hash__(self) -> int:
return hash((self.doc, self.name, self.type_))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "RecordField":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
name = None
if "name" in _doc:
try:
name = load_field(
_doc.get("name"),
uri_strtype_True_False_None_None,
baseuri,
loadingOptions,
lc=_doc.get("name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[e],
detailed_message=f"the `name` field with value `{val}` "
"is not valid because:",
)
)
__original_name_is_none = name is None
if name is None:
if docRoot is not None:
name = docRoot
else:
_errors__.append(ValidationException("missing name"))
if not __original_name_is_none:
baseuri = cast(str, name)
doc = None
if "doc" in _doc:
try:
doc = load_field(
_doc.get("doc"),
union_of_None_type_or_strtype_or_array_of_strtype,
baseuri,
loadingOptions,
lc=_doc.get("doc")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `doc`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("doc")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `doc` field is not valid because:",
SourceLine(_doc, "doc", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `doc` field is not valid because:",
SourceLine(_doc, "doc", str),
[e],
detailed_message=f"the `doc` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("type") is None:
raise ValidationException("missing required field `type`", None, [])
type_ = load_field(
_doc.get("type"),
typedsl_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype_or_array_of_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype_2,
baseuri,
loadingOptions,
lc=_doc.get("type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[e],
detailed_message=f"the `type` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `doc`, `name`, `type`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
doc=doc,
name=name,
type_=type_,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
loadingOptions.idx[cast(str, name)] = (_constructed, loadingOptions)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.name is not None:
u = save_relative_uri(self.name, base_url, True, None, relative_uris)
r["name"] = u
if self.doc is not None:
r["doc"] = save(
self.doc, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.type_ is not None:
r["type"] = save(
self.type_, top=False, base_url=self.name, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["doc", "name", "type"])
[docs]
class RecordSchema(Saveable):
def __init__(
self,
type_: Any,
fields: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.fields = fields
self.type_ = type_
def __eq__(self, other: Any) -> bool:
if isinstance(other, RecordSchema):
return bool(self.fields == other.fields and self.type_ == other.type_)
return False
def __hash__(self) -> int:
return hash((self.fields, self.type_))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "RecordSchema":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
fields = None
if "fields" in _doc:
try:
fields = load_field(
_doc.get("fields"),
idmap_fields_union_of_None_type_or_array_of_RecordFieldLoader,
baseuri,
loadingOptions,
lc=_doc.get("fields")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `fields`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("fields")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `fields` field is not valid because:",
SourceLine(_doc, "fields", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `fields` field is not valid because:",
SourceLine(_doc, "fields", str),
[e],
detailed_message=f"the `fields` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("type") is None:
raise ValidationException("missing required field `type`", None, [])
type_ = load_field(
_doc.get("type"),
typedsl_enum_d9cba076fca539106791a4f46d198c7fcfbdb779Loader_2,
baseuri,
loadingOptions,
lc=_doc.get("type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[e],
detailed_message=f"the `type` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `fields`, `type`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
fields=fields,
type_=type_,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.fields is not None:
r["fields"] = save(
self.fields, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.type_ is not None:
r["type"] = save(
self.type_, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["fields", "type"])
[docs]
class EnumSchema(Saveable):
"""
Define an enumerated type.
"""
def __init__(
self,
symbols: Any,
type_: Any,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.symbols = symbols
self.type_ = type_
def __eq__(self, other: Any) -> bool:
if isinstance(other, EnumSchema):
return bool(self.symbols == other.symbols and self.type_ == other.type_)
return False
def __hash__(self) -> int:
return hash((self.symbols, self.type_))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "EnumSchema":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
try:
if _doc.get("symbols") is None:
raise ValidationException("missing required field `symbols`", None, [])
symbols = load_field(
_doc.get("symbols"),
uri_array_of_strtype_True_False_None_None,
baseuri,
loadingOptions,
lc=_doc.get("symbols")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `symbols`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("symbols")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `symbols` field is not valid because:",
SourceLine(_doc, "symbols", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `symbols` field is not valid because:",
SourceLine(_doc, "symbols", str),
[e],
detailed_message=f"the `symbols` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("type") is None:
raise ValidationException("missing required field `type`", None, [])
type_ = load_field(
_doc.get("type"),
typedsl_enum_d961d79c225752b9fadb617367615ab176b47d77Loader_2,
baseuri,
loadingOptions,
lc=_doc.get("type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[e],
detailed_message=f"the `type` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `symbols`, `type`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
symbols=symbols,
type_=type_,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.symbols is not None:
u = save_relative_uri(self.symbols, base_url, True, None, relative_uris)
r["symbols"] = u
if self.type_ is not None:
r["type"] = save(
self.type_, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["symbols", "type"])
[docs]
class ArraySchema(Saveable):
def __init__(
self,
items: Any,
type_: Any,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.items = items
self.type_ = type_
def __eq__(self, other: Any) -> bool:
if isinstance(other, ArraySchema):
return bool(self.items == other.items and self.type_ == other.type_)
return False
def __hash__(self) -> int:
return hash((self.items, self.type_))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "ArraySchema":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
try:
if _doc.get("items") is None:
raise ValidationException("missing required field `items`", None, [])
items = load_field(
_doc.get("items"),
uri_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype_or_array_of_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype_False_True_2_None,
baseuri,
loadingOptions,
lc=_doc.get("items")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `items`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("items")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `items` field is not valid because:",
SourceLine(_doc, "items", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `items` field is not valid because:",
SourceLine(_doc, "items", str),
[e],
detailed_message=f"the `items` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("type") is None:
raise ValidationException("missing required field `type`", None, [])
type_ = load_field(
_doc.get("type"),
typedsl_enum_d062602be0b4b8fd33e69e29a841317b6ab665bcLoader_2,
baseuri,
loadingOptions,
lc=_doc.get("type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[e],
detailed_message=f"the `type` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `items`, `type`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
items=items,
type_=type_,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.items is not None:
u = save_relative_uri(self.items, base_url, False, 2, relative_uris)
r["items"] = u
if self.type_ is not None:
r["type"] = save(
self.type_, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["items", "type"])
[docs]
class StepPosition(Saveable):
"""
This field specifies the location of the step's node when rendered in the workflow editor.
"""
def __init__(
self,
top: Any,
left: Any,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.top = top
self.left = left
def __eq__(self, other: Any) -> bool:
if isinstance(other, StepPosition):
return bool(self.top == other.top and self.left == other.left)
return False
def __hash__(self) -> int:
return hash((self.top, self.left))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "StepPosition":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
try:
if _doc.get("top") is None:
raise ValidationException("missing required field `top`", None, [])
top = load_field(
_doc.get("top"),
union_of_floattype_or_inttype,
baseuri,
loadingOptions,
lc=_doc.get("top")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `top`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("top")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `top` field is not valid because:",
SourceLine(_doc, "top", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `top` field is not valid because:",
SourceLine(_doc, "top", str),
[e],
detailed_message=f"the `top` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("left") is None:
raise ValidationException("missing required field `left`", None, [])
left = load_field(
_doc.get("left"),
union_of_floattype_or_inttype,
baseuri,
loadingOptions,
lc=_doc.get("left")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `left`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("left")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `left` field is not valid because:",
SourceLine(_doc, "left", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `left` field is not valid because:",
SourceLine(_doc, "left", str),
[e],
detailed_message=f"the `left` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `top`, `left`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
top=top,
left=left,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.top is not None:
r["top"] = save(
self.top, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.left is not None:
r["left"] = save(
self.left, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["top", "left"])
[docs]
class SampleSheetColumnDefinition(Saveable):
"""
Describes one column of a sample-sheet collection input.
Used in `column_definitions` on a `collection_type: sample_sheet[:<type>]`
workflow input.
"""
name: str
def __init__(
self,
name: Any,
type_: Any,
optional: Any,
description: Optional[Any] = None,
default_value: Optional[Any] = None,
validators: Optional[Any] = None,
restrictions: Optional[Any] = None,
suggestions: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
self.description = description
self.type_ = type_
self.optional = optional
self.default_value = default_value
self.validators = validators
self.restrictions = restrictions
self.suggestions = suggestions
def __eq__(self, other: Any) -> bool:
if isinstance(other, SampleSheetColumnDefinition):
return bool(
self.name == other.name
and self.description == other.description
and self.type_ == other.type_
and self.optional == other.optional
and self.default_value == other.default_value
and self.validators == other.validators
and self.restrictions == other.restrictions
and self.suggestions == other.suggestions
)
return False
def __hash__(self) -> int:
return hash(
(
self.name,
self.description,
self.type_,
self.optional,
self.default_value,
self.validators,
self.restrictions,
self.suggestions,
)
)
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "SampleSheetColumnDefinition":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
name = None
if "name" in _doc:
try:
name = load_field(
_doc.get("name"),
uri_strtype_True_False_None_None,
baseuri,
loadingOptions,
lc=_doc.get("name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[e],
detailed_message=f"the `name` field with value `{val}` "
"is not valid because:",
)
)
__original_name_is_none = name is None
if name is None:
if docRoot is not None:
name = docRoot
else:
_errors__.append(ValidationException("missing name"))
if not __original_name_is_none:
baseuri = cast(str, name)
description = None
if "description" in _doc:
try:
description = load_field(
_doc.get("description"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("description")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `description`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("description")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `description` field is not valid because:",
SourceLine(_doc, "description", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `description` field is not valid because:",
SourceLine(_doc, "description", str),
[e],
detailed_message=f"the `description` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("type") is None:
raise ValidationException("missing required field `type`", None, [])
type_ = load_field(
_doc.get("type"),
typedsl_strtype_2,
baseuri,
loadingOptions,
lc=_doc.get("type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[e],
detailed_message=f"the `type` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("optional") is None:
raise ValidationException("missing required field `optional`", None, [])
optional = load_field(
_doc.get("optional"),
booltype,
baseuri,
loadingOptions,
lc=_doc.get("optional")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `optional`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("optional")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `optional` field is not valid because:",
SourceLine(_doc, "optional", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `optional` field is not valid because:",
SourceLine(_doc, "optional", str),
[e],
detailed_message=f"the `optional` field with value `{val}` "
"is not valid because:",
)
)
default_value = None
if "default_value" in _doc:
try:
default_value = load_field(
_doc.get("default_value"),
union_of_None_type_or_strtype_or_inttype_or_floattype_or_booltype,
baseuri,
loadingOptions,
lc=_doc.get("default_value")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `default_value`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("default_value")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `default_value` field is not valid because:",
SourceLine(_doc, "default_value", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `default_value` field is not valid because:",
SourceLine(_doc, "default_value", str),
[e],
detailed_message=f"the `default_value` field with value `{val}` "
"is not valid because:",
)
)
validators = None
if "validators" in _doc:
try:
validators = load_field(
_doc.get("validators"),
union_of_None_type_or_array_of_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("validators")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `validators`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("validators")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `validators` field is not valid because:",
SourceLine(_doc, "validators", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `validators` field is not valid because:",
SourceLine(_doc, "validators", str),
[e],
detailed_message=f"the `validators` field with value `{val}` "
"is not valid because:",
)
)
restrictions = None
if "restrictions" in _doc:
try:
restrictions = load_field(
_doc.get("restrictions"),
union_of_None_type_or_array_of_union_of_strtype_or_inttype_or_floattype_or_booltype,
baseuri,
loadingOptions,
lc=_doc.get("restrictions")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `restrictions`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("restrictions")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `restrictions` field is not valid because:",
SourceLine(_doc, "restrictions", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `restrictions` field is not valid because:",
SourceLine(_doc, "restrictions", str),
[e],
detailed_message=f"the `restrictions` field with value `{val}` "
"is not valid because:",
)
)
suggestions = None
if "suggestions" in _doc:
try:
suggestions = load_field(
_doc.get("suggestions"),
union_of_None_type_or_array_of_union_of_strtype_or_inttype_or_floattype_or_booltype,
baseuri,
loadingOptions,
lc=_doc.get("suggestions")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `suggestions`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("suggestions")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `suggestions` field is not valid because:",
SourceLine(_doc, "suggestions", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `suggestions` field is not valid because:",
SourceLine(_doc, "suggestions", str),
[e],
detailed_message=f"the `suggestions` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `name`, `description`, `type`, `optional`, `default_value`, `validators`, `restrictions`, `suggestions`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
name=name,
description=description,
type_=type_,
optional=optional,
default_value=default_value,
validators=validators,
restrictions=restrictions,
suggestions=suggestions,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
loadingOptions.idx[cast(str, name)] = (_constructed, loadingOptions)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.name is not None:
u = save_relative_uri(self.name, base_url, True, None, relative_uris)
r["name"] = u
if self.description is not None:
r["description"] = save(
self.description,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.type_ is not None:
r["type"] = save(
self.type_, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.optional is not None:
r["optional"] = save(
self.optional,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.default_value is not None:
r["default_value"] = save(
self.default_value,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.validators is not None:
r["validators"] = save(
self.validators,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.restrictions is not None:
r["restrictions"] = save(
self.restrictions,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.suggestions is not None:
r["suggestions"] = save(
self.suggestions,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(
[
"name",
"description",
"type",
"optional",
"default_value",
"validators",
"restrictions",
"suggestions",
]
)
[docs]
class RecordFieldDefinition(Saveable):
"""
Describes one field of a `record` collection input.
Used in `fields` on a `collection_type` containing `record` (e.g.
`record`, `list:record`, `sample_sheet:record`). Mirrors a subset of
the CWL `InputRecordSchema` shape that Galaxy persists on
`DatasetCollection.fields`.
"""
name: str
def __init__(
self,
name: Any,
type_: Any,
format: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
self.type_ = type_
self.format = format
def __eq__(self, other: Any) -> bool:
if isinstance(other, RecordFieldDefinition):
return bool(
self.name == other.name
and self.type_ == other.type_
and self.format == other.format
)
return False
def __hash__(self) -> int:
return hash((self.name, self.type_, self.format))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "RecordFieldDefinition":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
name = None
if "name" in _doc:
try:
name = load_field(
_doc.get("name"),
uri_strtype_True_False_None_None,
baseuri,
loadingOptions,
lc=_doc.get("name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[e],
detailed_message=f"the `name` field with value `{val}` "
"is not valid because:",
)
)
__original_name_is_none = name is None
if name is None:
if docRoot is not None:
name = docRoot
else:
_errors__.append(ValidationException("missing name"))
if not __original_name_is_none:
baseuri = cast(str, name)
try:
if _doc.get("type") is None:
raise ValidationException("missing required field `type`", None, [])
type_ = load_field(
_doc.get("type"),
typedsl_union_of_strtype_or_array_of_strtype_2,
baseuri,
loadingOptions,
lc=_doc.get("type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[e],
detailed_message=f"the `type` field with value `{val}` "
"is not valid because:",
)
)
format = None
if "format" in _doc:
try:
format = load_field(
_doc.get("format"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("format")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `format`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("format")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `format` field is not valid because:",
SourceLine(_doc, "format", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `format` field is not valid because:",
SourceLine(_doc, "format", str),
[e],
detailed_message=f"the `format` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `name`, `type`, `format`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
name=name,
type_=type_,
format=format,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
loadingOptions.idx[cast(str, name)] = (_constructed, loadingOptions)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.name is not None:
u = save_relative_uri(self.name, base_url, True, None, relative_uris)
r["name"] = u
if self.type_ is not None:
r["type"] = save(
self.type_, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.format is not None:
r["format"] = save(
self.format, top=False, base_url=self.name, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["name", "type", "format"])
[docs]
class WorkflowTextOption(Saveable):
"""
A `{value, label}` option used in `restrictions` or `suggestions` on a
text workflow parameter. Plain strings are also accepted in those
arrays as shorthand for `{value: <str>, label: <str>}`.
"""
def __init__(
self,
value: Any,
label: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.value = value
self.label = label
def __eq__(self, other: Any) -> bool:
if isinstance(other, WorkflowTextOption):
return bool(self.value == other.value and self.label == other.label)
return False
def __hash__(self) -> int:
return hash((self.value, self.label))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "WorkflowTextOption":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
try:
if _doc.get("value") is None:
raise ValidationException("missing required field `value`", None, [])
value = load_field(
_doc.get("value"),
strtype,
baseuri,
loadingOptions,
lc=_doc.get("value")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `value`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("value")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `value` field is not valid because:",
SourceLine(_doc, "value", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `value` field is not valid because:",
SourceLine(_doc, "value", str),
[e],
detailed_message=f"the `value` field with value `{val}` "
"is not valid because:",
)
)
label = None
if "label" in _doc:
try:
label = load_field(
_doc.get("label"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("label")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `label`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("label")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `label` field is not valid because:",
SourceLine(_doc, "label", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `label` field is not valid because:",
SourceLine(_doc, "label", str),
[e],
detailed_message=f"the `label` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `value`, `label`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
value=value,
label=label,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.value is not None:
r["value"] = save(
self.value, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.label is not None:
r["label"] = save(
self.label, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["value", "label"])
[docs]
class ToolShedRepository(Saveable):
name: str
def __init__(
self,
changeset_revision: Any,
name: Any,
owner: Any,
tool_shed: Any,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.changeset_revision = changeset_revision
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
self.owner = owner
self.tool_shed = tool_shed
def __eq__(self, other: Any) -> bool:
if isinstance(other, ToolShedRepository):
return bool(
self.changeset_revision == other.changeset_revision
and self.name == other.name
and self.owner == other.owner
and self.tool_shed == other.tool_shed
)
return False
def __hash__(self) -> int:
return hash((self.changeset_revision, self.name, self.owner, self.tool_shed))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "ToolShedRepository":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
name = None
if "name" in _doc:
try:
name = load_field(
_doc.get("name"),
uri_strtype_True_False_None_None,
baseuri,
loadingOptions,
lc=_doc.get("name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[e],
detailed_message=f"the `name` field with value `{val}` "
"is not valid because:",
)
)
__original_name_is_none = name is None
if name is None:
if docRoot is not None:
name = docRoot
else:
_errors__.append(ValidationException("missing name"))
if not __original_name_is_none:
baseuri = cast(str, name)
try:
if _doc.get("changeset_revision") is None:
raise ValidationException("missing required field `changeset_revision`", None, [])
changeset_revision = load_field(
_doc.get("changeset_revision"),
strtype,
baseuri,
loadingOptions,
lc=_doc.get("changeset_revision")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `changeset_revision`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("changeset_revision")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `changeset_revision` field is not valid because:",
SourceLine(_doc, "changeset_revision", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `changeset_revision` field is not valid because:",
SourceLine(_doc, "changeset_revision", str),
[e],
detailed_message=f"the `changeset_revision` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("owner") is None:
raise ValidationException("missing required field `owner`", None, [])
owner = load_field(
_doc.get("owner"),
strtype,
baseuri,
loadingOptions,
lc=_doc.get("owner")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `owner`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("owner")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `owner` field is not valid because:",
SourceLine(_doc, "owner", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `owner` field is not valid because:",
SourceLine(_doc, "owner", str),
[e],
detailed_message=f"the `owner` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("tool_shed") is None:
raise ValidationException("missing required field `tool_shed`", None, [])
tool_shed = load_field(
_doc.get("tool_shed"),
strtype,
baseuri,
loadingOptions,
lc=_doc.get("tool_shed")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `tool_shed`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("tool_shed")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `tool_shed` field is not valid because:",
SourceLine(_doc, "tool_shed", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `tool_shed` field is not valid because:",
SourceLine(_doc, "tool_shed", str),
[e],
detailed_message=f"the `tool_shed` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `changeset_revision`, `name`, `owner`, `tool_shed`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
changeset_revision=changeset_revision,
name=name,
owner=owner,
tool_shed=tool_shed,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
loadingOptions.idx[cast(str, name)] = (_constructed, loadingOptions)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.name is not None:
u = save_relative_uri(self.name, base_url, True, None, relative_uris)
r["name"] = u
if self.changeset_revision is not None:
r["changeset_revision"] = save(
self.changeset_revision,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.owner is not None:
r["owner"] = save(
self.owner, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.tool_shed is not None:
r["tool_shed"] = save(
self.tool_shed,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["changeset_revision", "name", "owner", "tool_shed"])
[docs]
class NativeStepInput(Saveable):
"""
Describes an input parameter on a step. This is metadata about the input,
not the connection wiring (which is in ``input_connections``).
"""
name: str
def __init__(
self,
name: Any,
description: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
self.description = description
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeStepInput):
return bool(
self.name == other.name and self.description == other.description
)
return False
def __hash__(self) -> int:
return hash((self.name, self.description))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeStepInput":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
name = None
if "name" in _doc:
try:
name = load_field(
_doc.get("name"),
uri_strtype_True_False_None_None,
baseuri,
loadingOptions,
lc=_doc.get("name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[e],
detailed_message=f"the `name` field with value `{val}` "
"is not valid because:",
)
)
__original_name_is_none = name is None
if name is None:
if docRoot is not None:
name = docRoot
else:
_errors__.append(ValidationException("missing name"))
if not __original_name_is_none:
baseuri = cast(str, name)
description = None
if "description" in _doc:
try:
description = load_field(
_doc.get("description"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("description")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `description`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("description")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `description` field is not valid because:",
SourceLine(_doc, "description", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `description` field is not valid because:",
SourceLine(_doc, "description", str),
[e],
detailed_message=f"the `description` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `name`, `description`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
name=name,
description=description,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
loadingOptions.idx[cast(str, name)] = (_constructed, loadingOptions)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.name is not None:
u = save_relative_uri(self.name, base_url, True, None, relative_uris)
r["name"] = u
if self.description is not None:
r["description"] = save(
self.description,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["name", "description"])
[docs]
class NativeStepOutput(Saveable):
"""
Declares an output produced by a step, with its name and datatype.
"""
name: str
def __init__(
self,
name: Any,
type_: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
self.type_ = type_
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeStepOutput):
return bool(self.name == other.name and self.type_ == other.type_)
return False
def __hash__(self) -> int:
return hash((self.name, self.type_))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeStepOutput":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
name = None
if "name" in _doc:
try:
name = load_field(
_doc.get("name"),
uri_strtype_True_False_None_None,
baseuri,
loadingOptions,
lc=_doc.get("name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[e],
detailed_message=f"the `name` field with value `{val}` "
"is not valid because:",
)
)
__original_name_is_none = name is None
if name is None:
if docRoot is not None:
name = docRoot
else:
_errors__.append(ValidationException("missing name"))
if not __original_name_is_none:
baseuri = cast(str, name)
type_ = None
if "type" in _doc:
try:
type_ = load_field(
_doc.get("type"),
typedsl_union_of_None_type_or_strtype_2,
baseuri,
loadingOptions,
lc=_doc.get("type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[e],
detailed_message=f"the `type` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `name`, `type`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
name=name,
type_=type_,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
loadingOptions.idx[cast(str, name)] = (_constructed, loadingOptions)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.name is not None:
u = save_relative_uri(self.name, base_url, True, None, relative_uris)
r["name"] = u
if self.type_ is not None:
r["type"] = save(
self.type_, top=False, base_url=self.name, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["name", "type"])
[docs]
class NativeWorkflowOutput(Saveable):
"""
Designates a step output as a workflow-level output. These appear in the
``workflow_outputs`` array on each step.
"""
def __init__(
self,
output_name: Any,
label: Optional[Any] = None,
uuid: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.label = label
self.output_name = output_name
self.uuid = uuid
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeWorkflowOutput):
return bool(
self.label == other.label
and self.output_name == other.output_name
and self.uuid == other.uuid
)
return False
def __hash__(self) -> int:
return hash((self.label, self.output_name, self.uuid))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeWorkflowOutput":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
label = None
if "label" in _doc:
try:
label = load_field(
_doc.get("label"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("label")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `label`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("label")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `label` field is not valid because:",
SourceLine(_doc, "label", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `label` field is not valid because:",
SourceLine(_doc, "label", str),
[e],
detailed_message=f"the `label` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("output_name") is None:
raise ValidationException("missing required field `output_name`", None, [])
output_name = load_field(
_doc.get("output_name"),
strtype,
baseuri,
loadingOptions,
lc=_doc.get("output_name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `output_name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("output_name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `output_name` field is not valid because:",
SourceLine(_doc, "output_name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `output_name` field is not valid because:",
SourceLine(_doc, "output_name", str),
[e],
detailed_message=f"the `output_name` field with value `{val}` "
"is not valid because:",
)
)
uuid = None
if "uuid" in _doc:
try:
uuid = load_field(
_doc.get("uuid"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("uuid")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `uuid`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("uuid")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `uuid` field is not valid because:",
SourceLine(_doc, "uuid", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `uuid` field is not valid because:",
SourceLine(_doc, "uuid", str),
[e],
detailed_message=f"the `uuid` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `label`, `output_name`, `uuid`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
label=label,
output_name=output_name,
uuid=uuid,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.label is not None:
r["label"] = save(
self.label, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.output_name is not None:
r["output_name"] = save(
self.output_name,
top=False,
base_url=base_url,
relative_uris=relative_uris,
)
if self.uuid is not None:
r["uuid"] = save(
self.uuid, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["label", "output_name", "uuid"])
[docs]
class NativeInputConnection(Saveable):
"""
Describes a connection from one step's output to another step's input.
These objects appear as values in the ``input_connections`` dictionary.
For multi-valued inputs, the value is an array of these objects rather
than a single object.
"""
def __init__(
self,
id: Any,
output_name: Any,
input_subworkflow_step_id: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.id = id
self.output_name = output_name
self.input_subworkflow_step_id = input_subworkflow_step_id
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeInputConnection):
return bool(
self.id == other.id
and self.output_name == other.output_name
and self.input_subworkflow_step_id == other.input_subworkflow_step_id
)
return False
def __hash__(self) -> int:
return hash((self.id, self.output_name, self.input_subworkflow_step_id))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeInputConnection":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
try:
if _doc.get("id") is None:
raise ValidationException("missing required field `id`", None, [])
id = load_field(
_doc.get("id"),
inttype,
baseuri,
loadingOptions,
lc=_doc.get("id")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `id`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("id")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `id` field is not valid because:",
SourceLine(_doc, "id", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `id` field is not valid because:",
SourceLine(_doc, "id", str),
[e],
detailed_message=f"the `id` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("output_name") is None:
raise ValidationException("missing required field `output_name`", None, [])
output_name = load_field(
_doc.get("output_name"),
strtype,
baseuri,
loadingOptions,
lc=_doc.get("output_name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `output_name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("output_name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `output_name` field is not valid because:",
SourceLine(_doc, "output_name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `output_name` field is not valid because:",
SourceLine(_doc, "output_name", str),
[e],
detailed_message=f"the `output_name` field with value `{val}` "
"is not valid because:",
)
)
input_subworkflow_step_id = None
if "input_subworkflow_step_id" in _doc:
try:
input_subworkflow_step_id = load_field(
_doc.get("input_subworkflow_step_id"),
union_of_None_type_or_inttype,
baseuri,
loadingOptions,
lc=_doc.get("input_subworkflow_step_id")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `input_subworkflow_step_id`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("input_subworkflow_step_id")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `input_subworkflow_step_id` field is not valid because:",
SourceLine(_doc, "input_subworkflow_step_id", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `input_subworkflow_step_id` field is not valid because:",
SourceLine(_doc, "input_subworkflow_step_id", str),
[e],
detailed_message=f"the `input_subworkflow_step_id` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `id`, `output_name`, `input_subworkflow_step_id`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
id=id,
output_name=output_name,
input_subworkflow_step_id=input_subworkflow_step_id,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.id is not None:
r["id"] = save(
self.id, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.output_name is not None:
r["output_name"] = save(
self.output_name,
top=False,
base_url=base_url,
relative_uris=relative_uris,
)
if self.input_subworkflow_step_id is not None:
r["input_subworkflow_step_id"] = save(
self.input_subworkflow_step_id,
top=False,
base_url=base_url,
relative_uris=relative_uris,
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["id", "output_name", "input_subworkflow_step_id"])
[docs]
class NativePostJobAction(Saveable):
"""
An action applied to a step's output after tool execution. These objects
appear as values in the ``post_job_actions`` dictionary, keyed by
compound strings of the form ``{ActionType}{OutputName}``
(e.g. ``HideDatasetActionout_pairs``).
Common action types: ``HideDatasetAction``, ``RenameDatasetAction``,
``DeleteIntermediatesAction``, ``ChangeDatatypeAction``,
``TagDatasetAction``, ``ColumnSetAction``.
"""
def __init__(
self,
action_type: Any,
output_name: Any,
action_arguments: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.action_type = action_type
self.output_name = output_name
self.action_arguments = action_arguments
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativePostJobAction):
return bool(
self.action_type == other.action_type
and self.output_name == other.output_name
and self.action_arguments == other.action_arguments
)
return False
def __hash__(self) -> int:
return hash((self.action_type, self.output_name, self.action_arguments))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativePostJobAction":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
try:
if _doc.get("action_type") is None:
raise ValidationException("missing required field `action_type`", None, [])
action_type = load_field(
_doc.get("action_type"),
strtype,
baseuri,
loadingOptions,
lc=_doc.get("action_type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `action_type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("action_type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `action_type` field is not valid because:",
SourceLine(_doc, "action_type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `action_type` field is not valid because:",
SourceLine(_doc, "action_type", str),
[e],
detailed_message=f"the `action_type` field with value `{val}` "
"is not valid because:",
)
)
output_name = None
if "output_name" in _doc:
try:
output_name = load_field(
_doc.get("output_name"),
union_of_strtype_or_None_type,
baseuri,
loadingOptions,
lc=_doc.get("output_name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `output_name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("output_name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `output_name` field is not valid because:",
SourceLine(_doc, "output_name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `output_name` field is not valid because:",
SourceLine(_doc, "output_name", str),
[e],
detailed_message=f"the `output_name` field with value `{val}` "
"is not valid because:",
)
)
action_arguments = None
if "action_arguments" in _doc:
try:
action_arguments = load_field(
_doc.get("action_arguments"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("action_arguments")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `action_arguments`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("action_arguments")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `action_arguments` field is not valid because:",
SourceLine(_doc, "action_arguments", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `action_arguments` field is not valid because:",
SourceLine(_doc, "action_arguments", str),
[e],
detailed_message=f"the `action_arguments` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `action_type`, `output_name`, `action_arguments`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
action_type=action_type,
output_name=output_name,
action_arguments=action_arguments,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.action_type is not None:
r["action_type"] = save(
self.action_type,
top=False,
base_url=base_url,
relative_uris=relative_uris,
)
if self.output_name is not None:
r["output_name"] = save(
self.output_name,
top=False,
base_url=base_url,
relative_uris=relative_uris,
)
if self.action_arguments is not None:
r["action_arguments"] = save(
self.action_arguments,
top=False,
base_url=base_url,
relative_uris=relative_uris,
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["action_type", "output_name", "action_arguments"])
[docs]
class NativeTextCommentData(Saveable):
"""
Data payload for a text comment.
"""
def __init__(
self,
text: Optional[Any] = None,
bold: Optional[Any] = None,
italic: Optional[Any] = None,
size: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.text = text
self.bold = bold
self.italic = italic
self.size = size
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeTextCommentData):
return bool(
self.text == other.text
and self.bold == other.bold
and self.italic == other.italic
and self.size == other.size
)
return False
def __hash__(self) -> int:
return hash((self.text, self.bold, self.italic, self.size))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeTextCommentData":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
text = None
if "text" in _doc:
try:
text = load_field(
_doc.get("text"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("text")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `text`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("text")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `text` field is not valid because:",
SourceLine(_doc, "text", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `text` field is not valid because:",
SourceLine(_doc, "text", str),
[e],
detailed_message=f"the `text` field with value `{val}` "
"is not valid because:",
)
)
bold = None
if "bold" in _doc:
try:
bold = load_field(
_doc.get("bold"),
union_of_None_type_or_booltype,
baseuri,
loadingOptions,
lc=_doc.get("bold")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `bold`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("bold")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `bold` field is not valid because:",
SourceLine(_doc, "bold", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `bold` field is not valid because:",
SourceLine(_doc, "bold", str),
[e],
detailed_message=f"the `bold` field with value `{val}` "
"is not valid because:",
)
)
italic = None
if "italic" in _doc:
try:
italic = load_field(
_doc.get("italic"),
union_of_None_type_or_booltype,
baseuri,
loadingOptions,
lc=_doc.get("italic")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `italic`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("italic")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `italic` field is not valid because:",
SourceLine(_doc, "italic", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `italic` field is not valid because:",
SourceLine(_doc, "italic", str),
[e],
detailed_message=f"the `italic` field with value `{val}` "
"is not valid because:",
)
)
size = None
if "size" in _doc:
try:
size = load_field(
_doc.get("size"),
union_of_None_type_or_floattype_or_inttype,
baseuri,
loadingOptions,
lc=_doc.get("size")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `size`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("size")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `size` field is not valid because:",
SourceLine(_doc, "size", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `size` field is not valid because:",
SourceLine(_doc, "size", str),
[e],
detailed_message=f"the `size` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `text`, `bold`, `italic`, `size`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
text=text,
bold=bold,
italic=italic,
size=size,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.text is not None:
r["text"] = save(
self.text, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.bold is not None:
r["bold"] = save(
self.bold, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.italic is not None:
r["italic"] = save(
self.italic, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.size is not None:
r["size"] = save(
self.size, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["text", "bold", "italic", "size"])
[docs]
class NativeMarkdownCommentData(Saveable):
"""
Data payload for a markdown comment.
"""
def __init__(
self,
text: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.text = text
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeMarkdownCommentData):
return bool(self.text == other.text)
return False
def __hash__(self) -> int:
return hash((self.text))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeMarkdownCommentData":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
text = None
if "text" in _doc:
try:
text = load_field(
_doc.get("text"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("text")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `text`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("text")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `text` field is not valid because:",
SourceLine(_doc, "text", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `text` field is not valid because:",
SourceLine(_doc, "text", str),
[e],
detailed_message=f"the `text` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `text`".format(k),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
text=text,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.text is not None:
r["text"] = save(
self.text, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["text"])
[docs]
class NativeFrameCommentData(Saveable):
"""
Data payload for a frame comment.
"""
def __init__(
self,
title: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.title = title
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeFrameCommentData):
return bool(self.title == other.title)
return False
def __hash__(self) -> int:
return hash((self.title))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeFrameCommentData":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
title = None
if "title" in _doc:
try:
title = load_field(
_doc.get("title"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("title")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `title`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("title")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `title` field is not valid because:",
SourceLine(_doc, "title", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `title` field is not valid because:",
SourceLine(_doc, "title", str),
[e],
detailed_message=f"the `title` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `title`".format(k),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
title=title,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.title is not None:
r["title"] = save(
self.title, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["title"])
[docs]
class NativeFreehandCommentData(Saveable):
"""
Data payload for a freehand comment.
"""
def __init__(
self,
line: Optional[Any] = None,
thickness: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.line = line
self.thickness = thickness
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeFreehandCommentData):
return bool(self.line == other.line and self.thickness == other.thickness)
return False
def __hash__(self) -> int:
return hash((self.line, self.thickness))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeFreehandCommentData":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
line = None
if "line" in _doc:
try:
line = load_field(
_doc.get("line"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("line")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `line`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("line")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `line` field is not valid because:",
SourceLine(_doc, "line", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `line` field is not valid because:",
SourceLine(_doc, "line", str),
[e],
detailed_message=f"the `line` field with value `{val}` "
"is not valid because:",
)
)
thickness = None
if "thickness" in _doc:
try:
thickness = load_field(
_doc.get("thickness"),
union_of_None_type_or_floattype_or_inttype,
baseuri,
loadingOptions,
lc=_doc.get("thickness")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `thickness`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("thickness")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `thickness` field is not valid because:",
SourceLine(_doc, "thickness", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `thickness` field is not valid because:",
SourceLine(_doc, "thickness", str),
[e],
detailed_message=f"the `thickness` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `line`, `thickness`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
line=line,
thickness=thickness,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.line is not None:
r["line"] = save(
self.line, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.thickness is not None:
r["thickness"] = save(
self.thickness,
top=False,
base_url=base_url,
relative_uris=relative_uris,
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["line", "thickness"])
[docs]
class NativeTextComment(BaseNativeComment):
"""
A plain text annotation in the workflow editor.
"""
def __init__(
self,
id: Any,
type_: Any,
position: Optional[Any] = None,
size: Optional[Any] = None,
color: Optional[Any] = None,
data: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.id = id
self.position = position
self.size = size
self.color = color
self.type_ = type_
self.data = data
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeTextComment):
return bool(
self.id == other.id
and self.position == other.position
and self.size == other.size
and self.color == other.color
and self.type_ == other.type_
and self.data == other.data
)
return False
def __hash__(self) -> int:
return hash(
(self.id, self.position, self.size, self.color, self.type_, self.data)
)
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeTextComment":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
try:
if _doc.get("id") is None:
raise ValidationException("missing required field `id`", None, [])
id = load_field(
_doc.get("id"),
inttype,
baseuri,
loadingOptions,
lc=_doc.get("id")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `id`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("id")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `id` field is not valid because:",
SourceLine(_doc, "id", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `id` field is not valid because:",
SourceLine(_doc, "id", str),
[e],
detailed_message=f"the `id` field with value `{val}` "
"is not valid because:",
)
)
position = None
if "position" in _doc:
try:
position = load_field(
_doc.get("position"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("position")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `position`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("position")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `position` field is not valid because:",
SourceLine(_doc, "position", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `position` field is not valid because:",
SourceLine(_doc, "position", str),
[e],
detailed_message=f"the `position` field with value `{val}` "
"is not valid because:",
)
)
size = None
if "size" in _doc:
try:
size = load_field(
_doc.get("size"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("size")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `size`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("size")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `size` field is not valid because:",
SourceLine(_doc, "size", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `size` field is not valid because:",
SourceLine(_doc, "size", str),
[e],
detailed_message=f"the `size` field with value `{val}` "
"is not valid because:",
)
)
color = None
if "color" in _doc:
try:
color = load_field(
_doc.get("color"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("color")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `color`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("color")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `color` field is not valid because:",
SourceLine(_doc, "color", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `color` field is not valid because:",
SourceLine(_doc, "color", str),
[e],
detailed_message=f"the `color` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("type") is None:
raise ValidationException("missing required field `type`", None, [])
type_ = load_field(
_doc.get("type"),
typedsl_strtype_2,
baseuri,
loadingOptions,
lc=_doc.get("type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[e],
detailed_message=f"the `type` field with value `{val}` "
"is not valid because:",
)
)
data = None
if "data" in _doc:
try:
data = load_field(
_doc.get("data"),
union_of_None_type_or_NativeTextCommentDataLoader,
baseuri,
loadingOptions,
lc=_doc.get("data")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `data`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("data")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `data` field is not valid because:",
SourceLine(_doc, "data", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `data` field is not valid because:",
SourceLine(_doc, "data", str),
[e],
detailed_message=f"the `data` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `id`, `position`, `size`, `color`, `type`, `data`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
id=id,
position=position,
size=size,
color=color,
type_=type_,
data=data,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.id is not None:
r["id"] = save(
self.id, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.position is not None:
r["position"] = save(
self.position, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.size is not None:
r["size"] = save(
self.size, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.color is not None:
r["color"] = save(
self.color, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.type_ is not None:
r["type"] = save(
self.type_, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.data is not None:
r["data"] = save(
self.data, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["id", "position", "size", "color", "type", "data"])
[docs]
class NativeMarkdownComment(BaseNativeComment):
"""
A Markdown-rendered annotation in the workflow editor.
"""
def __init__(
self,
id: Any,
type_: Any,
position: Optional[Any] = None,
size: Optional[Any] = None,
color: Optional[Any] = None,
data: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.id = id
self.position = position
self.size = size
self.color = color
self.type_ = type_
self.data = data
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeMarkdownComment):
return bool(
self.id == other.id
and self.position == other.position
and self.size == other.size
and self.color == other.color
and self.type_ == other.type_
and self.data == other.data
)
return False
def __hash__(self) -> int:
return hash(
(self.id, self.position, self.size, self.color, self.type_, self.data)
)
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeMarkdownComment":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
try:
if _doc.get("id") is None:
raise ValidationException("missing required field `id`", None, [])
id = load_field(
_doc.get("id"),
inttype,
baseuri,
loadingOptions,
lc=_doc.get("id")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `id`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("id")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `id` field is not valid because:",
SourceLine(_doc, "id", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `id` field is not valid because:",
SourceLine(_doc, "id", str),
[e],
detailed_message=f"the `id` field with value `{val}` "
"is not valid because:",
)
)
position = None
if "position" in _doc:
try:
position = load_field(
_doc.get("position"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("position")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `position`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("position")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `position` field is not valid because:",
SourceLine(_doc, "position", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `position` field is not valid because:",
SourceLine(_doc, "position", str),
[e],
detailed_message=f"the `position` field with value `{val}` "
"is not valid because:",
)
)
size = None
if "size" in _doc:
try:
size = load_field(
_doc.get("size"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("size")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `size`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("size")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `size` field is not valid because:",
SourceLine(_doc, "size", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `size` field is not valid because:",
SourceLine(_doc, "size", str),
[e],
detailed_message=f"the `size` field with value `{val}` "
"is not valid because:",
)
)
color = None
if "color" in _doc:
try:
color = load_field(
_doc.get("color"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("color")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `color`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("color")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `color` field is not valid because:",
SourceLine(_doc, "color", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `color` field is not valid because:",
SourceLine(_doc, "color", str),
[e],
detailed_message=f"the `color` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("type") is None:
raise ValidationException("missing required field `type`", None, [])
type_ = load_field(
_doc.get("type"),
typedsl_strtype_2,
baseuri,
loadingOptions,
lc=_doc.get("type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[e],
detailed_message=f"the `type` field with value `{val}` "
"is not valid because:",
)
)
data = None
if "data" in _doc:
try:
data = load_field(
_doc.get("data"),
union_of_None_type_or_NativeMarkdownCommentDataLoader,
baseuri,
loadingOptions,
lc=_doc.get("data")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `data`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("data")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `data` field is not valid because:",
SourceLine(_doc, "data", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `data` field is not valid because:",
SourceLine(_doc, "data", str),
[e],
detailed_message=f"the `data` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `id`, `position`, `size`, `color`, `type`, `data`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
id=id,
position=position,
size=size,
color=color,
type_=type_,
data=data,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.id is not None:
r["id"] = save(
self.id, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.position is not None:
r["position"] = save(
self.position, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.size is not None:
r["size"] = save(
self.size, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.color is not None:
r["color"] = save(
self.color, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.type_ is not None:
r["type"] = save(
self.type_, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.data is not None:
r["data"] = save(
self.data, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["id", "position", "size", "color", "type", "data"])
[docs]
class NativeFrameComment(BaseNativeComment):
"""
A rectangular grouping box that visually contains steps and other comments.
"""
def __init__(
self,
id: Any,
type_: Any,
position: Optional[Any] = None,
size: Optional[Any] = None,
color: Optional[Any] = None,
data: Optional[Any] = None,
child_steps: Optional[Any] = None,
child_comments: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.id = id
self.position = position
self.size = size
self.color = color
self.type_ = type_
self.data = data
self.child_steps = child_steps
self.child_comments = child_comments
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeFrameComment):
return bool(
self.id == other.id
and self.position == other.position
and self.size == other.size
and self.color == other.color
and self.type_ == other.type_
and self.data == other.data
and self.child_steps == other.child_steps
and self.child_comments == other.child_comments
)
return False
def __hash__(self) -> int:
return hash(
(
self.id,
self.position,
self.size,
self.color,
self.type_,
self.data,
self.child_steps,
self.child_comments,
)
)
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeFrameComment":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
try:
if _doc.get("id") is None:
raise ValidationException("missing required field `id`", None, [])
id = load_field(
_doc.get("id"),
inttype,
baseuri,
loadingOptions,
lc=_doc.get("id")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `id`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("id")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `id` field is not valid because:",
SourceLine(_doc, "id", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `id` field is not valid because:",
SourceLine(_doc, "id", str),
[e],
detailed_message=f"the `id` field with value `{val}` "
"is not valid because:",
)
)
position = None
if "position" in _doc:
try:
position = load_field(
_doc.get("position"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("position")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `position`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("position")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `position` field is not valid because:",
SourceLine(_doc, "position", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `position` field is not valid because:",
SourceLine(_doc, "position", str),
[e],
detailed_message=f"the `position` field with value `{val}` "
"is not valid because:",
)
)
size = None
if "size" in _doc:
try:
size = load_field(
_doc.get("size"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("size")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `size`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("size")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `size` field is not valid because:",
SourceLine(_doc, "size", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `size` field is not valid because:",
SourceLine(_doc, "size", str),
[e],
detailed_message=f"the `size` field with value `{val}` "
"is not valid because:",
)
)
color = None
if "color" in _doc:
try:
color = load_field(
_doc.get("color"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("color")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `color`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("color")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `color` field is not valid because:",
SourceLine(_doc, "color", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `color` field is not valid because:",
SourceLine(_doc, "color", str),
[e],
detailed_message=f"the `color` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("type") is None:
raise ValidationException("missing required field `type`", None, [])
type_ = load_field(
_doc.get("type"),
typedsl_strtype_2,
baseuri,
loadingOptions,
lc=_doc.get("type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[e],
detailed_message=f"the `type` field with value `{val}` "
"is not valid because:",
)
)
data = None
if "data" in _doc:
try:
data = load_field(
_doc.get("data"),
union_of_None_type_or_NativeFrameCommentDataLoader,
baseuri,
loadingOptions,
lc=_doc.get("data")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `data`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("data")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `data` field is not valid because:",
SourceLine(_doc, "data", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `data` field is not valid because:",
SourceLine(_doc, "data", str),
[e],
detailed_message=f"the `data` field with value `{val}` "
"is not valid because:",
)
)
child_steps = None
if "child_steps" in _doc:
try:
child_steps = load_field(
_doc.get("child_steps"),
union_of_None_type_or_array_of_inttype,
baseuri,
loadingOptions,
lc=_doc.get("child_steps")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `child_steps`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("child_steps")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `child_steps` field is not valid because:",
SourceLine(_doc, "child_steps", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `child_steps` field is not valid because:",
SourceLine(_doc, "child_steps", str),
[e],
detailed_message=f"the `child_steps` field with value `{val}` "
"is not valid because:",
)
)
child_comments = None
if "child_comments" in _doc:
try:
child_comments = load_field(
_doc.get("child_comments"),
union_of_None_type_or_array_of_inttype,
baseuri,
loadingOptions,
lc=_doc.get("child_comments")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `child_comments`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("child_comments")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `child_comments` field is not valid because:",
SourceLine(_doc, "child_comments", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `child_comments` field is not valid because:",
SourceLine(_doc, "child_comments", str),
[e],
detailed_message=f"the `child_comments` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `id`, `position`, `size`, `color`, `type`, `data`, `child_steps`, `child_comments`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
id=id,
position=position,
size=size,
color=color,
type_=type_,
data=data,
child_steps=child_steps,
child_comments=child_comments,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.id is not None:
r["id"] = save(
self.id, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.position is not None:
r["position"] = save(
self.position, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.size is not None:
r["size"] = save(
self.size, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.color is not None:
r["color"] = save(
self.color, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.type_ is not None:
r["type"] = save(
self.type_, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.data is not None:
r["data"] = save(
self.data, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.child_steps is not None:
r["child_steps"] = save(
self.child_steps,
top=False,
base_url=base_url,
relative_uris=relative_uris,
)
if self.child_comments is not None:
r["child_comments"] = save(
self.child_comments,
top=False,
base_url=base_url,
relative_uris=relative_uris,
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(
[
"id",
"position",
"size",
"color",
"type",
"data",
"child_steps",
"child_comments",
]
)
[docs]
class NativeFreehandComment(BaseNativeComment):
"""
A freehand drawn line on the editor canvas.
"""
def __init__(
self,
id: Any,
type_: Any,
position: Optional[Any] = None,
size: Optional[Any] = None,
color: Optional[Any] = None,
data: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.id = id
self.position = position
self.size = size
self.color = color
self.type_ = type_
self.data = data
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeFreehandComment):
return bool(
self.id == other.id
and self.position == other.position
and self.size == other.size
and self.color == other.color
and self.type_ == other.type_
and self.data == other.data
)
return False
def __hash__(self) -> int:
return hash(
(self.id, self.position, self.size, self.color, self.type_, self.data)
)
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeFreehandComment":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
try:
if _doc.get("id") is None:
raise ValidationException("missing required field `id`", None, [])
id = load_field(
_doc.get("id"),
inttype,
baseuri,
loadingOptions,
lc=_doc.get("id")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `id`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("id")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `id` field is not valid because:",
SourceLine(_doc, "id", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `id` field is not valid because:",
SourceLine(_doc, "id", str),
[e],
detailed_message=f"the `id` field with value `{val}` "
"is not valid because:",
)
)
position = None
if "position" in _doc:
try:
position = load_field(
_doc.get("position"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("position")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `position`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("position")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `position` field is not valid because:",
SourceLine(_doc, "position", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `position` field is not valid because:",
SourceLine(_doc, "position", str),
[e],
detailed_message=f"the `position` field with value `{val}` "
"is not valid because:",
)
)
size = None
if "size" in _doc:
try:
size = load_field(
_doc.get("size"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("size")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `size`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("size")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `size` field is not valid because:",
SourceLine(_doc, "size", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `size` field is not valid because:",
SourceLine(_doc, "size", str),
[e],
detailed_message=f"the `size` field with value `{val}` "
"is not valid because:",
)
)
color = None
if "color" in _doc:
try:
color = load_field(
_doc.get("color"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("color")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `color`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("color")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `color` field is not valid because:",
SourceLine(_doc, "color", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `color` field is not valid because:",
SourceLine(_doc, "color", str),
[e],
detailed_message=f"the `color` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("type") is None:
raise ValidationException("missing required field `type`", None, [])
type_ = load_field(
_doc.get("type"),
typedsl_strtype_2,
baseuri,
loadingOptions,
lc=_doc.get("type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[e],
detailed_message=f"the `type` field with value `{val}` "
"is not valid because:",
)
)
data = None
if "data" in _doc:
try:
data = load_field(
_doc.get("data"),
union_of_None_type_or_NativeFreehandCommentDataLoader,
baseuri,
loadingOptions,
lc=_doc.get("data")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `data`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("data")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `data` field is not valid because:",
SourceLine(_doc, "data", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `data` field is not valid because:",
SourceLine(_doc, "data", str),
[e],
detailed_message=f"the `data` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `id`, `position`, `size`, `color`, `type`, `data`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
id=id,
position=position,
size=size,
color=color,
type_=type_,
data=data,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.id is not None:
r["id"] = save(
self.id, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.position is not None:
r["position"] = save(
self.position, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.size is not None:
r["size"] = save(
self.size, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.color is not None:
r["color"] = save(
self.color, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.type_ is not None:
r["type"] = save(
self.type_, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.data is not None:
r["data"] = save(
self.data, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["id", "position", "size", "color", "type", "data"])
[docs]
class NativeStep(HasStepErrors, HasStepPosition, HasUUID, ReferencesTool):
"""
A step in a native Galaxy workflow. Steps are keyed by string integers
(``"0"``, ``"1"``, ...) in the ``steps`` dictionary. The key serves as
an external ID for connection wiring.
The ``type`` field determines the step's behavior. All step types share
common fields; type-specific fields are optional and only relevant for
their respective type.
# Tool State
The ``tool_state`` field contains the tool's parameter configuration.
Traditionally this is a JSON-encoded string (double-encoded: each top-level
value is itself a JSON string), but it may also be a plain dictionary when
unencoded tool state is used. Connected parameters are represented as
``{"__class__": "ConnectedValue"}``, runtime parameters as
``{"__class__": "RuntimeValue"}``.
"""
name: str
def __init__(
self,
errors: Optional[Any] = None,
position: Optional[Any] = None,
uuid: Optional[Any] = None,
tool_id: Optional[Any] = None,
tool_shed_repository: Optional[Any] = None,
tool_version: Optional[Any] = None,
id: Optional[Any] = None,
type_: Optional[Any] = None,
name: Optional[Any] = None,
label: Optional[Any] = None,
annotation: Optional[Any] = None,
when: Optional[Any] = None,
content_id: Optional[Any] = None,
tool_state: Optional[Any] = None,
tool_uuid: Optional[Any] = None,
input_connections: Optional[Any] = None,
inputs: Optional[Any] = None,
outputs: Optional[Any] = None,
workflow_outputs: Optional[Any] = None,
post_job_actions: Optional[Any] = None,
subworkflow: Optional[Any] = None,
tool_representation: Optional[Any] = None,
in_: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.errors = errors
self.position = position
self.uuid = uuid
self.tool_id = tool_id
self.tool_shed_repository = tool_shed_repository
self.tool_version = tool_version
self.id = id
self.type_ = type_
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
self.label = label
self.annotation = annotation
self.when = when
self.content_id = content_id
self.tool_state = tool_state
self.tool_uuid = tool_uuid
self.input_connections = input_connections
self.inputs = inputs
self.outputs = outputs
self.workflow_outputs = workflow_outputs
self.post_job_actions = post_job_actions
self.subworkflow = subworkflow
self.tool_representation = tool_representation
self.in_ = in_
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeStep):
return bool(
self.errors == other.errors
and self.position == other.position
and self.uuid == other.uuid
and self.tool_id == other.tool_id
and self.tool_shed_repository == other.tool_shed_repository
and self.tool_version == other.tool_version
and self.id == other.id
and self.type_ == other.type_
and self.name == other.name
and self.label == other.label
and self.annotation == other.annotation
and self.when == other.when
and self.content_id == other.content_id
and self.tool_state == other.tool_state
and self.tool_uuid == other.tool_uuid
and self.input_connections == other.input_connections
and self.inputs == other.inputs
and self.outputs == other.outputs
and self.workflow_outputs == other.workflow_outputs
and self.post_job_actions == other.post_job_actions
and self.subworkflow == other.subworkflow
and self.tool_representation == other.tool_representation
and self.in_ == other.in_
)
return False
def __hash__(self) -> int:
return hash(
(
self.errors,
self.position,
self.uuid,
self.tool_id,
self.tool_shed_repository,
self.tool_version,
self.id,
self.type_,
self.name,
self.label,
self.annotation,
self.when,
self.content_id,
self.tool_state,
self.tool_uuid,
self.input_connections,
self.inputs,
self.outputs,
self.workflow_outputs,
self.post_job_actions,
self.subworkflow,
self.tool_representation,
self.in_,
)
)
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeStep":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
name = None
if "name" in _doc:
try:
name = load_field(
_doc.get("name"),
uri_union_of_None_type_or_strtype_True_False_None_None,
baseuri,
loadingOptions,
lc=_doc.get("name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[e],
detailed_message=f"the `name` field with value `{val}` "
"is not valid because:",
)
)
__original_name_is_none = name is None
if name is None:
if docRoot is not None:
name = docRoot
else:
name = "_:" + str(_uuid__.uuid4())
if not __original_name_is_none:
baseuri = cast(str, name)
id = None
if "id" in _doc:
try:
id = load_field(
_doc.get("id"),
union_of_None_type_or_inttype,
baseuri,
loadingOptions,
lc=_doc.get("id")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `id`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("id")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `id` field is not valid because:",
SourceLine(_doc, "id", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `id` field is not valid because:",
SourceLine(_doc, "id", str),
[e],
detailed_message=f"the `id` field with value `{val}` "
"is not valid because:",
)
)
errors = None
if "errors" in _doc:
try:
errors = load_field(
_doc.get("errors"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("errors")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `errors`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("errors")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `errors` field is not valid because:",
SourceLine(_doc, "errors", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `errors` field is not valid because:",
SourceLine(_doc, "errors", str),
[e],
detailed_message=f"the `errors` field with value `{val}` "
"is not valid because:",
)
)
position = None
if "position" in _doc:
try:
position = load_field(
_doc.get("position"),
union_of_None_type_or_StepPositionLoader,
baseuri,
loadingOptions,
lc=_doc.get("position")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `position`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("position")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `position` field is not valid because:",
SourceLine(_doc, "position", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `position` field is not valid because:",
SourceLine(_doc, "position", str),
[e],
detailed_message=f"the `position` field with value `{val}` "
"is not valid because:",
)
)
uuid = None
if "uuid" in _doc:
try:
uuid = load_field(
_doc.get("uuid"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("uuid")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `uuid`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("uuid")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `uuid` field is not valid because:",
SourceLine(_doc, "uuid", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `uuid` field is not valid because:",
SourceLine(_doc, "uuid", str),
[e],
detailed_message=f"the `uuid` field with value `{val}` "
"is not valid because:",
)
)
tool_id = None
if "tool_id" in _doc:
try:
tool_id = load_field(
_doc.get("tool_id"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("tool_id")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `tool_id`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("tool_id")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `tool_id` field is not valid because:",
SourceLine(_doc, "tool_id", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `tool_id` field is not valid because:",
SourceLine(_doc, "tool_id", str),
[e],
detailed_message=f"the `tool_id` field with value `{val}` "
"is not valid because:",
)
)
tool_shed_repository = None
if "tool_shed_repository" in _doc:
try:
tool_shed_repository = load_field(
_doc.get("tool_shed_repository"),
union_of_None_type_or_ToolShedRepositoryLoader,
baseuri,
loadingOptions,
lc=_doc.get("tool_shed_repository")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `tool_shed_repository`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("tool_shed_repository")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `tool_shed_repository` field is not valid because:",
SourceLine(_doc, "tool_shed_repository", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `tool_shed_repository` field is not valid because:",
SourceLine(_doc, "tool_shed_repository", str),
[e],
detailed_message=f"the `tool_shed_repository` field with value `{val}` "
"is not valid because:",
)
)
tool_version = None
if "tool_version" in _doc:
try:
tool_version = load_field(
_doc.get("tool_version"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("tool_version")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `tool_version`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("tool_version")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `tool_version` field is not valid because:",
SourceLine(_doc, "tool_version", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `tool_version` field is not valid because:",
SourceLine(_doc, "tool_version", str),
[e],
detailed_message=f"the `tool_version` field with value `{val}` "
"is not valid because:",
)
)
type_ = None
if "type" in _doc:
try:
type_ = load_field(
_doc.get("type"),
typedsl_union_of_None_type_or_NativeStepTypeLoader_2,
baseuri,
loadingOptions,
lc=_doc.get("type")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `type`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("type")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `type` field is not valid because:",
SourceLine(_doc, "type", str),
[e],
detailed_message=f"the `type` field with value `{val}` "
"is not valid because:",
)
)
label = None
if "label" in _doc:
try:
label = load_field(
_doc.get("label"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("label")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `label`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("label")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `label` field is not valid because:",
SourceLine(_doc, "label", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `label` field is not valid because:",
SourceLine(_doc, "label", str),
[e],
detailed_message=f"the `label` field with value `{val}` "
"is not valid because:",
)
)
annotation = None
if "annotation" in _doc:
try:
annotation = load_field(
_doc.get("annotation"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("annotation")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `annotation`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("annotation")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `annotation` field is not valid because:",
SourceLine(_doc, "annotation", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `annotation` field is not valid because:",
SourceLine(_doc, "annotation", str),
[e],
detailed_message=f"the `annotation` field with value `{val}` "
"is not valid because:",
)
)
when = None
if "when" in _doc:
try:
when = load_field(
_doc.get("when"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("when")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `when`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("when")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `when` field is not valid because:",
SourceLine(_doc, "when", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `when` field is not valid because:",
SourceLine(_doc, "when", str),
[e],
detailed_message=f"the `when` field with value `{val}` "
"is not valid because:",
)
)
content_id = None
if "content_id" in _doc:
try:
content_id = load_field(
_doc.get("content_id"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("content_id")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `content_id`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("content_id")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `content_id` field is not valid because:",
SourceLine(_doc, "content_id", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `content_id` field is not valid because:",
SourceLine(_doc, "content_id", str),
[e],
detailed_message=f"the `content_id` field with value `{val}` "
"is not valid because:",
)
)
tool_state = None
if "tool_state" in _doc:
try:
tool_state = load_field(
_doc.get("tool_state"),
union_of_None_type_or_strtype_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("tool_state")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `tool_state`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("tool_state")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `tool_state` field is not valid because:",
SourceLine(_doc, "tool_state", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `tool_state` field is not valid because:",
SourceLine(_doc, "tool_state", str),
[e],
detailed_message=f"the `tool_state` field with value `{val}` "
"is not valid because:",
)
)
tool_uuid = None
if "tool_uuid" in _doc:
try:
tool_uuid = load_field(
_doc.get("tool_uuid"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("tool_uuid")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `tool_uuid`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("tool_uuid")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `tool_uuid` field is not valid because:",
SourceLine(_doc, "tool_uuid", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `tool_uuid` field is not valid because:",
SourceLine(_doc, "tool_uuid", str),
[e],
detailed_message=f"the `tool_uuid` field with value `{val}` "
"is not valid because:",
)
)
input_connections = None
if "input_connections" in _doc:
try:
input_connections = load_field(
_doc.get("input_connections"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("input_connections")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `input_connections`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("input_connections")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `input_connections` field is not valid because:",
SourceLine(_doc, "input_connections", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `input_connections` field is not valid because:",
SourceLine(_doc, "input_connections", str),
[e],
detailed_message=f"the `input_connections` field with value `{val}` "
"is not valid because:",
)
)
inputs = None
if "inputs" in _doc:
try:
inputs = load_field(
_doc.get("inputs"),
union_of_None_type_or_array_of_NativeStepInputLoader,
baseuri,
loadingOptions,
lc=_doc.get("inputs")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `inputs`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("inputs")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `inputs` field is not valid because:",
SourceLine(_doc, "inputs", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `inputs` field is not valid because:",
SourceLine(_doc, "inputs", str),
[e],
detailed_message=f"the `inputs` field with value `{val}` "
"is not valid because:",
)
)
outputs = None
if "outputs" in _doc:
try:
outputs = load_field(
_doc.get("outputs"),
union_of_None_type_or_array_of_NativeStepOutputLoader,
baseuri,
loadingOptions,
lc=_doc.get("outputs")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `outputs`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("outputs")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `outputs` field is not valid because:",
SourceLine(_doc, "outputs", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `outputs` field is not valid because:",
SourceLine(_doc, "outputs", str),
[e],
detailed_message=f"the `outputs` field with value `{val}` "
"is not valid because:",
)
)
workflow_outputs = None
if "workflow_outputs" in _doc:
try:
workflow_outputs = load_field(
_doc.get("workflow_outputs"),
union_of_None_type_or_array_of_NativeWorkflowOutputLoader,
baseuri,
loadingOptions,
lc=_doc.get("workflow_outputs")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `workflow_outputs`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("workflow_outputs")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `workflow_outputs` field is not valid because:",
SourceLine(_doc, "workflow_outputs", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `workflow_outputs` field is not valid because:",
SourceLine(_doc, "workflow_outputs", str),
[e],
detailed_message=f"the `workflow_outputs` field with value `{val}` "
"is not valid because:",
)
)
post_job_actions = None
if "post_job_actions" in _doc:
try:
post_job_actions = load_field(
_doc.get("post_job_actions"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("post_job_actions")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `post_job_actions`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("post_job_actions")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `post_job_actions` field is not valid because:",
SourceLine(_doc, "post_job_actions", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `post_job_actions` field is not valid because:",
SourceLine(_doc, "post_job_actions", str),
[e],
detailed_message=f"the `post_job_actions` field with value `{val}` "
"is not valid because:",
)
)
subworkflow = None
if "subworkflow" in _doc:
try:
subworkflow = load_field(
_doc.get("subworkflow"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("subworkflow")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `subworkflow`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("subworkflow")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `subworkflow` field is not valid because:",
SourceLine(_doc, "subworkflow", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `subworkflow` field is not valid because:",
SourceLine(_doc, "subworkflow", str),
[e],
detailed_message=f"the `subworkflow` field with value `{val}` "
"is not valid because:",
)
)
tool_representation = None
if "tool_representation" in _doc:
try:
tool_representation = load_field(
_doc.get("tool_representation"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("tool_representation")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `tool_representation`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("tool_representation")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `tool_representation` field is not valid because:",
SourceLine(_doc, "tool_representation", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `tool_representation` field is not valid because:",
SourceLine(_doc, "tool_representation", str),
[e],
detailed_message=f"the `tool_representation` field with value `{val}` "
"is not valid because:",
)
)
in_ = None
if "in" in _doc:
try:
in_ = load_field(
_doc.get("in"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("in")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `in`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("in")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `in` field is not valid because:",
SourceLine(_doc, "in", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `in` field is not valid because:",
SourceLine(_doc, "in", str),
[e],
detailed_message=f"the `in` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `errors`, `position`, `uuid`, `tool_id`, `tool_shed_repository`, `tool_version`, `id`, `type`, `name`, `label`, `annotation`, `when`, `content_id`, `tool_state`, `tool_uuid`, `input_connections`, `inputs`, `outputs`, `workflow_outputs`, `post_job_actions`, `subworkflow`, `tool_representation`, `in`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
errors=errors,
position=position,
uuid=uuid,
tool_id=tool_id,
tool_shed_repository=tool_shed_repository,
tool_version=tool_version,
id=id,
type_=type_,
name=name,
label=label,
annotation=annotation,
when=when,
content_id=content_id,
tool_state=tool_state,
tool_uuid=tool_uuid,
input_connections=input_connections,
inputs=inputs,
outputs=outputs,
workflow_outputs=workflow_outputs,
post_job_actions=post_job_actions,
subworkflow=subworkflow,
tool_representation=tool_representation,
in_=in_,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
loadingOptions.idx[cast(str, name)] = (_constructed, loadingOptions)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.name is not None:
u = save_relative_uri(self.name, base_url, True, None, relative_uris)
r["name"] = u
if self.id is not None:
r["id"] = save(
self.id, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.errors is not None:
r["errors"] = save(
self.errors, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.position is not None:
r["position"] = save(
self.position,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.uuid is not None:
r["uuid"] = save(
self.uuid, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.tool_id is not None:
r["tool_id"] = save(
self.tool_id, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.tool_shed_repository is not None:
r["tool_shed_repository"] = save(
self.tool_shed_repository,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.tool_version is not None:
r["tool_version"] = save(
self.tool_version,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.type_ is not None:
r["type"] = save(
self.type_, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.label is not None:
r["label"] = save(
self.label, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.annotation is not None:
r["annotation"] = save(
self.annotation,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.when is not None:
r["when"] = save(
self.when, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.content_id is not None:
r["content_id"] = save(
self.content_id,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.tool_state is not None:
r["tool_state"] = save(
self.tool_state,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.tool_uuid is not None:
r["tool_uuid"] = save(
self.tool_uuid,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.input_connections is not None:
r["input_connections"] = save(
self.input_connections,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.inputs is not None:
r["inputs"] = save(
self.inputs, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.outputs is not None:
r["outputs"] = save(
self.outputs, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.workflow_outputs is not None:
r["workflow_outputs"] = save(
self.workflow_outputs,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.post_job_actions is not None:
r["post_job_actions"] = save(
self.post_job_actions,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.subworkflow is not None:
r["subworkflow"] = save(
self.subworkflow,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.tool_representation is not None:
r["tool_representation"] = save(
self.tool_representation,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.in_ is not None:
r["in"] = save(
self.in_, top=False, base_url=self.name, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(
[
"errors",
"position",
"uuid",
"tool_id",
"tool_shed_repository",
"tool_version",
"id",
"type",
"name",
"label",
"annotation",
"when",
"content_id",
"tool_state",
"tool_uuid",
"input_connections",
"inputs",
"outputs",
"workflow_outputs",
"post_job_actions",
"subworkflow",
"tool_representation",
"in",
]
)
[docs]
class NativeReport(Saveable):
"""
Workflow invocation report template.
"""
def __init__(
self,
markdown: Any,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.markdown = markdown
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeReport):
return bool(self.markdown == other.markdown)
return False
def __hash__(self) -> int:
return hash((self.markdown))
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeReport":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
try:
if _doc.get("markdown") is None:
raise ValidationException("missing required field `markdown`", None, [])
markdown = load_field(
_doc.get("markdown"),
strtype,
baseuri,
loadingOptions,
lc=_doc.get("markdown")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `markdown`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("markdown")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `markdown` field is not valid because:",
SourceLine(_doc, "markdown", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `markdown` field is not valid because:",
SourceLine(_doc, "markdown", str),
[e],
detailed_message=f"the `markdown` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `markdown`".format(k),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
markdown=markdown,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.markdown is not None:
r["markdown"] = save(
self.markdown, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["markdown"])
[docs]
class BaseNativeCreator(Saveable):
"""
Base fields shared by all creator types, corresponding to schema.org
Thing properties common to both Person and Organization.
"""
pass
[docs]
class NativeCreatorPerson(BaseNativeCreator):
"""
A person who created or contributed to the workflow.
Corresponds to a `schema.org Person <https://schema.org/Person>`_.
"""
name: str
def __init__(
self,
name: Optional[Any] = None,
identifier: Optional[Any] = None,
url: Optional[Any] = None,
email: Optional[Any] = None,
image: Optional[Any] = None,
address: Optional[Any] = None,
alternateName: Optional[Any] = None,
telephone: Optional[Any] = None,
faxNumber: Optional[Any] = None,
givenName: Optional[Any] = None,
familyName: Optional[Any] = None,
honorificPrefix: Optional[Any] = None,
honorificSuffix: Optional[Any] = None,
jobTitle: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
self.identifier = identifier
self.url = url
self.email = email
self.image = image
self.address = address
self.alternateName = alternateName
self.telephone = telephone
self.faxNumber = faxNumber
self.class_ = "NativeCreatorPerson"
self.givenName = givenName
self.familyName = familyName
self.honorificPrefix = honorificPrefix
self.honorificSuffix = honorificSuffix
self.jobTitle = jobTitle
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeCreatorPerson):
return bool(
self.name == other.name
and self.identifier == other.identifier
and self.url == other.url
and self.email == other.email
and self.image == other.image
and self.address == other.address
and self.alternateName == other.alternateName
and self.telephone == other.telephone
and self.faxNumber == other.faxNumber
and self.class_ == other.class_
and self.givenName == other.givenName
and self.familyName == other.familyName
and self.honorificPrefix == other.honorificPrefix
and self.honorificSuffix == other.honorificSuffix
and self.jobTitle == other.jobTitle
)
return False
def __hash__(self) -> int:
return hash(
(
self.name,
self.identifier,
self.url,
self.email,
self.image,
self.address,
self.alternateName,
self.telephone,
self.faxNumber,
self.class_,
self.givenName,
self.familyName,
self.honorificPrefix,
self.honorificSuffix,
self.jobTitle,
)
)
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeCreatorPerson":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
name = None
if "name" in _doc:
try:
name = load_field(
_doc.get("name"),
uri_union_of_None_type_or_strtype_True_False_None_None,
baseuri,
loadingOptions,
lc=_doc.get("name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[e],
detailed_message=f"the `name` field with value `{val}` "
"is not valid because:",
)
)
__original_name_is_none = name is None
if name is None:
if docRoot is not None:
name = docRoot
else:
name = "_:" + str(_uuid__.uuid4())
if not __original_name_is_none:
baseuri = cast(str, name)
try:
if _doc.get("class") is None:
raise ValidationException("missing required field `class`", None, [])
class_ = load_field(
_doc.get("class"),
uri_NativeCreatorPersonTypeLoader_False_True_None_None,
baseuri,
loadingOptions,
lc=_doc.get("class")
)
if class_ not in (cls.__name__, loadingOptions.vocab.get(cls.__name__)):
raise ValidationException(f"tried `{cls.__name__}` but")
except ValidationException as e:
raise e
identifier = None
if "identifier" in _doc:
try:
identifier = load_field(
_doc.get("identifier"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("identifier")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `identifier`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("identifier")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `identifier` field is not valid because:",
SourceLine(_doc, "identifier", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `identifier` field is not valid because:",
SourceLine(_doc, "identifier", str),
[e],
detailed_message=f"the `identifier` field with value `{val}` "
"is not valid because:",
)
)
url = None
if "url" in _doc:
try:
url = load_field(
_doc.get("url"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("url")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `url`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("url")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `url` field is not valid because:",
SourceLine(_doc, "url", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `url` field is not valid because:",
SourceLine(_doc, "url", str),
[e],
detailed_message=f"the `url` field with value `{val}` "
"is not valid because:",
)
)
email = None
if "email" in _doc:
try:
email = load_field(
_doc.get("email"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("email")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `email`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("email")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `email` field is not valid because:",
SourceLine(_doc, "email", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `email` field is not valid because:",
SourceLine(_doc, "email", str),
[e],
detailed_message=f"the `email` field with value `{val}` "
"is not valid because:",
)
)
image = None
if "image" in _doc:
try:
image = load_field(
_doc.get("image"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("image")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `image`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("image")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `image` field is not valid because:",
SourceLine(_doc, "image", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `image` field is not valid because:",
SourceLine(_doc, "image", str),
[e],
detailed_message=f"the `image` field with value `{val}` "
"is not valid because:",
)
)
address = None
if "address" in _doc:
try:
address = load_field(
_doc.get("address"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("address")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `address`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("address")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `address` field is not valid because:",
SourceLine(_doc, "address", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `address` field is not valid because:",
SourceLine(_doc, "address", str),
[e],
detailed_message=f"the `address` field with value `{val}` "
"is not valid because:",
)
)
alternateName = None
if "alternateName" in _doc:
try:
alternateName = load_field(
_doc.get("alternateName"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("alternateName")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `alternateName`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("alternateName")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `alternateName` field is not valid because:",
SourceLine(_doc, "alternateName", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `alternateName` field is not valid because:",
SourceLine(_doc, "alternateName", str),
[e],
detailed_message=f"the `alternateName` field with value `{val}` "
"is not valid because:",
)
)
telephone = None
if "telephone" in _doc:
try:
telephone = load_field(
_doc.get("telephone"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("telephone")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `telephone`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("telephone")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `telephone` field is not valid because:",
SourceLine(_doc, "telephone", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `telephone` field is not valid because:",
SourceLine(_doc, "telephone", str),
[e],
detailed_message=f"the `telephone` field with value `{val}` "
"is not valid because:",
)
)
faxNumber = None
if "faxNumber" in _doc:
try:
faxNumber = load_field(
_doc.get("faxNumber"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("faxNumber")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `faxNumber`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("faxNumber")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `faxNumber` field is not valid because:",
SourceLine(_doc, "faxNumber", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `faxNumber` field is not valid because:",
SourceLine(_doc, "faxNumber", str),
[e],
detailed_message=f"the `faxNumber` field with value `{val}` "
"is not valid because:",
)
)
givenName = None
if "givenName" in _doc:
try:
givenName = load_field(
_doc.get("givenName"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("givenName")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `givenName`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("givenName")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `givenName` field is not valid because:",
SourceLine(_doc, "givenName", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `givenName` field is not valid because:",
SourceLine(_doc, "givenName", str),
[e],
detailed_message=f"the `givenName` field with value `{val}` "
"is not valid because:",
)
)
familyName = None
if "familyName" in _doc:
try:
familyName = load_field(
_doc.get("familyName"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("familyName")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `familyName`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("familyName")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `familyName` field is not valid because:",
SourceLine(_doc, "familyName", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `familyName` field is not valid because:",
SourceLine(_doc, "familyName", str),
[e],
detailed_message=f"the `familyName` field with value `{val}` "
"is not valid because:",
)
)
honorificPrefix = None
if "honorificPrefix" in _doc:
try:
honorificPrefix = load_field(
_doc.get("honorificPrefix"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("honorificPrefix")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `honorificPrefix`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("honorificPrefix")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `honorificPrefix` field is not valid because:",
SourceLine(_doc, "honorificPrefix", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `honorificPrefix` field is not valid because:",
SourceLine(_doc, "honorificPrefix", str),
[e],
detailed_message=f"the `honorificPrefix` field with value `{val}` "
"is not valid because:",
)
)
honorificSuffix = None
if "honorificSuffix" in _doc:
try:
honorificSuffix = load_field(
_doc.get("honorificSuffix"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("honorificSuffix")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `honorificSuffix`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("honorificSuffix")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `honorificSuffix` field is not valid because:",
SourceLine(_doc, "honorificSuffix", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `honorificSuffix` field is not valid because:",
SourceLine(_doc, "honorificSuffix", str),
[e],
detailed_message=f"the `honorificSuffix` field with value `{val}` "
"is not valid because:",
)
)
jobTitle = None
if "jobTitle" in _doc:
try:
jobTitle = load_field(
_doc.get("jobTitle"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("jobTitle")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `jobTitle`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("jobTitle")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `jobTitle` field is not valid because:",
SourceLine(_doc, "jobTitle", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `jobTitle` field is not valid because:",
SourceLine(_doc, "jobTitle", str),
[e],
detailed_message=f"the `jobTitle` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `name`, `identifier`, `url`, `email`, `image`, `address`, `alternateName`, `telephone`, `faxNumber`, `class`, `givenName`, `familyName`, `honorificPrefix`, `honorificSuffix`, `jobTitle`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
name=name,
identifier=identifier,
url=url,
email=email,
image=image,
address=address,
alternateName=alternateName,
telephone=telephone,
faxNumber=faxNumber,
givenName=givenName,
familyName=familyName,
honorificPrefix=honorificPrefix,
honorificSuffix=honorificSuffix,
jobTitle=jobTitle,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
loadingOptions.idx[cast(str, name)] = (_constructed, loadingOptions)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.name is not None:
u = save_relative_uri(self.name, base_url, True, None, relative_uris)
r["name"] = u
if self.class_ is not None:
uri = self.loadingOptions.vocab[self.class_]
if p := self.loadingOptions.rvocab.get(uri[: -len(self.class_)]):
uri = f"{p}:{self.class_}"
else:
uri = self.class_
u = save_relative_uri(uri, self.name, False, None, relative_uris)
r["class"] = u
if self.identifier is not None:
r["identifier"] = save(
self.identifier,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.url is not None:
r["url"] = save(
self.url, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.email is not None:
r["email"] = save(
self.email, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.image is not None:
r["image"] = save(
self.image, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.address is not None:
r["address"] = save(
self.address, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.alternateName is not None:
r["alternateName"] = save(
self.alternateName,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.telephone is not None:
r["telephone"] = save(
self.telephone,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.faxNumber is not None:
r["faxNumber"] = save(
self.faxNumber,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.givenName is not None:
r["givenName"] = save(
self.givenName,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.familyName is not None:
r["familyName"] = save(
self.familyName,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.honorificPrefix is not None:
r["honorificPrefix"] = save(
self.honorificPrefix,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.honorificSuffix is not None:
r["honorificSuffix"] = save(
self.honorificSuffix,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.jobTitle is not None:
r["jobTitle"] = save(
self.jobTitle,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(
[
"name",
"identifier",
"url",
"email",
"image",
"address",
"alternateName",
"telephone",
"faxNumber",
"class",
"givenName",
"familyName",
"honorificPrefix",
"honorificSuffix",
"jobTitle",
]
)
[docs]
class NativeCreatorOrganization(BaseNativeCreator):
"""
An organization that created or contributed to the workflow.
Corresponds to a `schema.org Organization <https://schema.org/Organization>`_.
"""
name: str
def __init__(
self,
name: Optional[Any] = None,
identifier: Optional[Any] = None,
url: Optional[Any] = None,
email: Optional[Any] = None,
image: Optional[Any] = None,
address: Optional[Any] = None,
alternateName: Optional[Any] = None,
telephone: Optional[Any] = None,
faxNumber: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
self.identifier = identifier
self.url = url
self.email = email
self.image = image
self.address = address
self.alternateName = alternateName
self.telephone = telephone
self.faxNumber = faxNumber
self.class_ = "NativeCreatorOrganization"
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeCreatorOrganization):
return bool(
self.name == other.name
and self.identifier == other.identifier
and self.url == other.url
and self.email == other.email
and self.image == other.image
and self.address == other.address
and self.alternateName == other.alternateName
and self.telephone == other.telephone
and self.faxNumber == other.faxNumber
and self.class_ == other.class_
)
return False
def __hash__(self) -> int:
return hash(
(
self.name,
self.identifier,
self.url,
self.email,
self.image,
self.address,
self.alternateName,
self.telephone,
self.faxNumber,
self.class_,
)
)
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeCreatorOrganization":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
name = None
if "name" in _doc:
try:
name = load_field(
_doc.get("name"),
uri_union_of_None_type_or_strtype_True_False_None_None,
baseuri,
loadingOptions,
lc=_doc.get("name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[e],
detailed_message=f"the `name` field with value `{val}` "
"is not valid because:",
)
)
__original_name_is_none = name is None
if name is None:
if docRoot is not None:
name = docRoot
else:
name = "_:" + str(_uuid__.uuid4())
if not __original_name_is_none:
baseuri = cast(str, name)
try:
if _doc.get("class") is None:
raise ValidationException("missing required field `class`", None, [])
class_ = load_field(
_doc.get("class"),
uri_NativeCreatorOrganizationTypeLoader_False_True_None_None,
baseuri,
loadingOptions,
lc=_doc.get("class")
)
if class_ not in (cls.__name__, loadingOptions.vocab.get(cls.__name__)):
raise ValidationException(f"tried `{cls.__name__}` but")
except ValidationException as e:
raise e
identifier = None
if "identifier" in _doc:
try:
identifier = load_field(
_doc.get("identifier"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("identifier")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `identifier`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("identifier")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `identifier` field is not valid because:",
SourceLine(_doc, "identifier", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `identifier` field is not valid because:",
SourceLine(_doc, "identifier", str),
[e],
detailed_message=f"the `identifier` field with value `{val}` "
"is not valid because:",
)
)
url = None
if "url" in _doc:
try:
url = load_field(
_doc.get("url"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("url")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `url`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("url")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `url` field is not valid because:",
SourceLine(_doc, "url", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `url` field is not valid because:",
SourceLine(_doc, "url", str),
[e],
detailed_message=f"the `url` field with value `{val}` "
"is not valid because:",
)
)
email = None
if "email" in _doc:
try:
email = load_field(
_doc.get("email"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("email")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `email`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("email")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `email` field is not valid because:",
SourceLine(_doc, "email", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `email` field is not valid because:",
SourceLine(_doc, "email", str),
[e],
detailed_message=f"the `email` field with value `{val}` "
"is not valid because:",
)
)
image = None
if "image" in _doc:
try:
image = load_field(
_doc.get("image"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("image")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `image`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("image")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `image` field is not valid because:",
SourceLine(_doc, "image", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `image` field is not valid because:",
SourceLine(_doc, "image", str),
[e],
detailed_message=f"the `image` field with value `{val}` "
"is not valid because:",
)
)
address = None
if "address" in _doc:
try:
address = load_field(
_doc.get("address"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("address")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `address`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("address")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `address` field is not valid because:",
SourceLine(_doc, "address", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `address` field is not valid because:",
SourceLine(_doc, "address", str),
[e],
detailed_message=f"the `address` field with value `{val}` "
"is not valid because:",
)
)
alternateName = None
if "alternateName" in _doc:
try:
alternateName = load_field(
_doc.get("alternateName"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("alternateName")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `alternateName`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("alternateName")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `alternateName` field is not valid because:",
SourceLine(_doc, "alternateName", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `alternateName` field is not valid because:",
SourceLine(_doc, "alternateName", str),
[e],
detailed_message=f"the `alternateName` field with value `{val}` "
"is not valid because:",
)
)
telephone = None
if "telephone" in _doc:
try:
telephone = load_field(
_doc.get("telephone"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("telephone")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `telephone`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("telephone")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `telephone` field is not valid because:",
SourceLine(_doc, "telephone", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `telephone` field is not valid because:",
SourceLine(_doc, "telephone", str),
[e],
detailed_message=f"the `telephone` field with value `{val}` "
"is not valid because:",
)
)
faxNumber = None
if "faxNumber" in _doc:
try:
faxNumber = load_field(
_doc.get("faxNumber"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("faxNumber")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `faxNumber`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("faxNumber")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `faxNumber` field is not valid because:",
SourceLine(_doc, "faxNumber", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `faxNumber` field is not valid because:",
SourceLine(_doc, "faxNumber", str),
[e],
detailed_message=f"the `faxNumber` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `name`, `identifier`, `url`, `email`, `image`, `address`, `alternateName`, `telephone`, `faxNumber`, `class`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
name=name,
identifier=identifier,
url=url,
email=email,
image=image,
address=address,
alternateName=alternateName,
telephone=telephone,
faxNumber=faxNumber,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
loadingOptions.idx[cast(str, name)] = (_constructed, loadingOptions)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.name is not None:
u = save_relative_uri(self.name, base_url, True, None, relative_uris)
r["name"] = u
if self.class_ is not None:
uri = self.loadingOptions.vocab[self.class_]
if p := self.loadingOptions.rvocab.get(uri[: -len(self.class_)]):
uri = f"{p}:{self.class_}"
else:
uri = self.class_
u = save_relative_uri(uri, self.name, False, None, relative_uris)
r["class"] = u
if self.identifier is not None:
r["identifier"] = save(
self.identifier,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.url is not None:
r["url"] = save(
self.url, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.email is not None:
r["email"] = save(
self.email, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.image is not None:
r["image"] = save(
self.image, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.address is not None:
r["address"] = save(
self.address, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.alternateName is not None:
r["alternateName"] = save(
self.alternateName,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.telephone is not None:
r["telephone"] = save(
self.telephone,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.faxNumber is not None:
r["faxNumber"] = save(
self.faxNumber,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(
[
"name",
"identifier",
"url",
"email",
"image",
"address",
"alternateName",
"telephone",
"faxNumber",
"class",
]
)
[docs]
class NativeSourceMetadata(Saveable):
"""
Provenance tracking for workflows imported from external sources.
Contains either a direct URL or TRS (Tool Registry Service) metadata,
depending on how the workflow was imported.
For URL imports, only ``url`` is set. For TRS imports (Dockstore,
WorkflowHub), ``trs_tool_id``, ``trs_version_id``, and ``trs_url``
are set, with ``trs_server`` optionally identifying the server.
"""
def __init__(
self,
url: Optional[Any] = None,
trs_tool_id: Optional[Any] = None,
trs_version_id: Optional[Any] = None,
trs_server: Optional[Any] = None,
trs_url: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.url = url
self.trs_tool_id = trs_tool_id
self.trs_version_id = trs_version_id
self.trs_server = trs_server
self.trs_url = trs_url
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeSourceMetadata):
return bool(
self.url == other.url
and self.trs_tool_id == other.trs_tool_id
and self.trs_version_id == other.trs_version_id
and self.trs_server == other.trs_server
and self.trs_url == other.trs_url
)
return False
def __hash__(self) -> int:
return hash(
(
self.url,
self.trs_tool_id,
self.trs_version_id,
self.trs_server,
self.trs_url,
)
)
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeSourceMetadata":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
url = None
if "url" in _doc:
try:
url = load_field(
_doc.get("url"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("url")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `url`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("url")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `url` field is not valid because:",
SourceLine(_doc, "url", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `url` field is not valid because:",
SourceLine(_doc, "url", str),
[e],
detailed_message=f"the `url` field with value `{val}` "
"is not valid because:",
)
)
trs_tool_id = None
if "trs_tool_id" in _doc:
try:
trs_tool_id = load_field(
_doc.get("trs_tool_id"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("trs_tool_id")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `trs_tool_id`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("trs_tool_id")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `trs_tool_id` field is not valid because:",
SourceLine(_doc, "trs_tool_id", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `trs_tool_id` field is not valid because:",
SourceLine(_doc, "trs_tool_id", str),
[e],
detailed_message=f"the `trs_tool_id` field with value `{val}` "
"is not valid because:",
)
)
trs_version_id = None
if "trs_version_id" in _doc:
try:
trs_version_id = load_field(
_doc.get("trs_version_id"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("trs_version_id")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `trs_version_id`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("trs_version_id")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `trs_version_id` field is not valid because:",
SourceLine(_doc, "trs_version_id", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `trs_version_id` field is not valid because:",
SourceLine(_doc, "trs_version_id", str),
[e],
detailed_message=f"the `trs_version_id` field with value `{val}` "
"is not valid because:",
)
)
trs_server = None
if "trs_server" in _doc:
try:
trs_server = load_field(
_doc.get("trs_server"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("trs_server")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `trs_server`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("trs_server")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `trs_server` field is not valid because:",
SourceLine(_doc, "trs_server", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `trs_server` field is not valid because:",
SourceLine(_doc, "trs_server", str),
[e],
detailed_message=f"the `trs_server` field with value `{val}` "
"is not valid because:",
)
)
trs_url = None
if "trs_url" in _doc:
try:
trs_url = load_field(
_doc.get("trs_url"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("trs_url")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `trs_url`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("trs_url")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `trs_url` field is not valid because:",
SourceLine(_doc, "trs_url", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `trs_url` field is not valid because:",
SourceLine(_doc, "trs_url", str),
[e],
detailed_message=f"the `trs_url` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `url`, `trs_tool_id`, `trs_version_id`, `trs_server`, `trs_url`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
url=url,
trs_tool_id=trs_tool_id,
trs_version_id=trs_version_id,
trs_server=trs_server,
trs_url=trs_url,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.url is not None:
r["url"] = save(
self.url, top=False, base_url=base_url, relative_uris=relative_uris
)
if self.trs_tool_id is not None:
r["trs_tool_id"] = save(
self.trs_tool_id,
top=False,
base_url=base_url,
relative_uris=relative_uris,
)
if self.trs_version_id is not None:
r["trs_version_id"] = save(
self.trs_version_id,
top=False,
base_url=base_url,
relative_uris=relative_uris,
)
if self.trs_server is not None:
r["trs_server"] = save(
self.trs_server,
top=False,
base_url=base_url,
relative_uris=relative_uris,
)
if self.trs_url is not None:
r["trs_url"] = save(
self.trs_url, top=False, base_url=base_url, relative_uris=relative_uris
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(["url", "trs_tool_id", "trs_version_id", "trs_server", "trs_url"])
[docs]
class NativeGalaxyWorkflow(HasUUID):
"""
A Galaxy native workflow document (.ga format). This is the canonical
serialization format used internally by Galaxy.
The native format mirrors the database schema directly -- steps are keyed
by numeric IDs, connections reference step IDs, and tool state is stored
as double-encoded JSON strings.
The format version has been ``"0.1"`` since inception. New features are
added without version bumps.
"""
name: str
def __init__(
self,
a_galaxy_workflow: Any,
format_version: Any,
uuid: Optional[Any] = None,
name: Optional[Any] = None,
annotation: Optional[Any] = None,
tags: Optional[Any] = None,
version: Optional[Any] = None,
license: Optional[Any] = None,
release: Optional[Any] = None,
creator: Optional[Any] = None,
report: Optional[Any] = None,
readme: Optional[Any] = None,
help: Optional[Any] = None,
logo_url: Optional[Any] = None,
doi: Optional[Any] = None,
source_metadata: Optional[Any] = None,
comments: Optional[Any] = None,
steps: Optional[Any] = None,
subworkflows: Optional[Any] = None,
extension_fields: Optional[dict[str, Any]] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> None:
if extension_fields:
self.extension_fields = extension_fields
else:
self.extension_fields = CommentedMap()
if loadingOptions:
self.loadingOptions = loadingOptions
else:
self.loadingOptions = LoadingOptions()
self.uuid = uuid
self.class_ = "NativeGalaxyWorkflow"
self.a_galaxy_workflow = a_galaxy_workflow
self.format_version = format_version
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
self.annotation = annotation
self.tags = tags
self.version = version
self.license = license
self.release = release
self.creator = creator
self.report = report
self.readme = readme
self.help = help
self.logo_url = logo_url
self.doi = doi
self.source_metadata = source_metadata
self.comments = comments
self.steps = steps
self.subworkflows = subworkflows
def __eq__(self, other: Any) -> bool:
if isinstance(other, NativeGalaxyWorkflow):
return bool(
self.uuid == other.uuid
and self.class_ == other.class_
and self.a_galaxy_workflow == other.a_galaxy_workflow
and self.format_version == other.format_version
and self.name == other.name
and self.annotation == other.annotation
and self.tags == other.tags
and self.version == other.version
and self.license == other.license
and self.release == other.release
and self.creator == other.creator
and self.report == other.report
and self.readme == other.readme
and self.help == other.help
and self.logo_url == other.logo_url
and self.doi == other.doi
and self.source_metadata == other.source_metadata
and self.comments == other.comments
and self.steps == other.steps
and self.subworkflows == other.subworkflows
)
return False
def __hash__(self) -> int:
return hash(
(
self.uuid,
self.class_,
self.a_galaxy_workflow,
self.format_version,
self.name,
self.annotation,
self.tags,
self.version,
self.license,
self.release,
self.creator,
self.report,
self.readme,
self.help,
self.logo_url,
self.doi,
self.source_metadata,
self.comments,
self.steps,
self.subworkflows,
)
)
[docs]
@classmethod
def fromDoc(
cls,
doc: Any,
baseuri: str,
loadingOptions: LoadingOptions,
docRoot: Optional[str] = None
) -> "NativeGalaxyWorkflow":
_doc = copy.copy(doc)
if hasattr(doc, "lc"):
_doc.lc.data = doc.lc.data
_doc.lc.filename = doc.lc.filename
_errors__ = []
name = None
if "name" in _doc:
try:
name = load_field(
_doc.get("name"),
uri_union_of_None_type_or_strtype_True_False_None_None,
baseuri,
loadingOptions,
lc=_doc.get("name")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `name`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("name")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `name` field is not valid because:",
SourceLine(_doc, "name", str),
[e],
detailed_message=f"the `name` field with value `{val}` "
"is not valid because:",
)
)
__original_name_is_none = name is None
if name is None:
if docRoot is not None:
name = docRoot
else:
name = "_:" + str(_uuid__.uuid4())
if not __original_name_is_none:
baseuri = cast(str, name)
try:
if _doc.get("class") is None:
raise ValidationException("missing required field `class`", None, [])
class_ = load_field(
_doc.get("class"),
uri_NativeGalaxyWorkflow_classLoader_False_True_None_None,
baseuri,
loadingOptions,
lc=_doc.get("class")
)
if class_ not in (cls.__name__, loadingOptions.vocab.get(cls.__name__)):
raise ValidationException(f"tried `{cls.__name__}` but")
except ValidationException as e:
raise e
uuid = None
if "uuid" in _doc:
try:
uuid = load_field(
_doc.get("uuid"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("uuid")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `uuid`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("uuid")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `uuid` field is not valid because:",
SourceLine(_doc, "uuid", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `uuid` field is not valid because:",
SourceLine(_doc, "uuid", str),
[e],
detailed_message=f"the `uuid` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("a_galaxy_workflow") is None:
raise ValidationException("missing required field `a_galaxy_workflow`", None, [])
a_galaxy_workflow = load_field(
_doc.get("a_galaxy_workflow"),
strtype,
baseuri,
loadingOptions,
lc=_doc.get("a_galaxy_workflow")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `a_galaxy_workflow`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("a_galaxy_workflow")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `a_galaxy_workflow` field is not valid because:",
SourceLine(_doc, "a_galaxy_workflow", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `a_galaxy_workflow` field is not valid because:",
SourceLine(_doc, "a_galaxy_workflow", str),
[e],
detailed_message=f"the `a_galaxy_workflow` field with value `{val}` "
"is not valid because:",
)
)
try:
if _doc.get("format_version") is None:
raise ValidationException("missing required field `format_version`", None, [])
format_version = load_field(
_doc.get("format_version"),
strtype,
baseuri,
loadingOptions,
lc=_doc.get("format_version")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `format_version`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("format_version")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `format_version` field is not valid because:",
SourceLine(_doc, "format_version", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `format_version` field is not valid because:",
SourceLine(_doc, "format_version", str),
[e],
detailed_message=f"the `format_version` field with value `{val}` "
"is not valid because:",
)
)
annotation = None
if "annotation" in _doc:
try:
annotation = load_field(
_doc.get("annotation"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("annotation")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `annotation`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("annotation")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `annotation` field is not valid because:",
SourceLine(_doc, "annotation", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `annotation` field is not valid because:",
SourceLine(_doc, "annotation", str),
[e],
detailed_message=f"the `annotation` field with value `{val}` "
"is not valid because:",
)
)
tags = None
if "tags" in _doc:
try:
tags = load_field(
_doc.get("tags"),
union_of_None_type_or_array_of_strtype,
baseuri,
loadingOptions,
lc=_doc.get("tags")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `tags`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("tags")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `tags` field is not valid because:",
SourceLine(_doc, "tags", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `tags` field is not valid because:",
SourceLine(_doc, "tags", str),
[e],
detailed_message=f"the `tags` field with value `{val}` "
"is not valid because:",
)
)
version = None
if "version" in _doc:
try:
version = load_field(
_doc.get("version"),
union_of_None_type_or_inttype,
baseuri,
loadingOptions,
lc=_doc.get("version")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `version`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("version")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `version` field is not valid because:",
SourceLine(_doc, "version", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `version` field is not valid because:",
SourceLine(_doc, "version", str),
[e],
detailed_message=f"the `version` field with value `{val}` "
"is not valid because:",
)
)
license = None
if "license" in _doc:
try:
license = load_field(
_doc.get("license"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("license")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `license`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("license")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `license` field is not valid because:",
SourceLine(_doc, "license", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `license` field is not valid because:",
SourceLine(_doc, "license", str),
[e],
detailed_message=f"the `license` field with value `{val}` "
"is not valid because:",
)
)
release = None
if "release" in _doc:
try:
release = load_field(
_doc.get("release"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("release")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `release`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("release")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `release` field is not valid because:",
SourceLine(_doc, "release", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `release` field is not valid because:",
SourceLine(_doc, "release", str),
[e],
detailed_message=f"the `release` field with value `{val}` "
"is not valid because:",
)
)
creator = None
if "creator" in _doc:
try:
creator = load_field(
_doc.get("creator"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("creator")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `creator`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("creator")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `creator` field is not valid because:",
SourceLine(_doc, "creator", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `creator` field is not valid because:",
SourceLine(_doc, "creator", str),
[e],
detailed_message=f"the `creator` field with value `{val}` "
"is not valid because:",
)
)
report = None
if "report" in _doc:
try:
report = load_field(
_doc.get("report"),
union_of_None_type_or_NativeReportLoader,
baseuri,
loadingOptions,
lc=_doc.get("report")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `report`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("report")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `report` field is not valid because:",
SourceLine(_doc, "report", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `report` field is not valid because:",
SourceLine(_doc, "report", str),
[e],
detailed_message=f"the `report` field with value `{val}` "
"is not valid because:",
)
)
readme = None
if "readme" in _doc:
try:
readme = load_field(
_doc.get("readme"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("readme")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `readme`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("readme")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `readme` field is not valid because:",
SourceLine(_doc, "readme", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `readme` field is not valid because:",
SourceLine(_doc, "readme", str),
[e],
detailed_message=f"the `readme` field with value `{val}` "
"is not valid because:",
)
)
help = None
if "help" in _doc:
try:
help = load_field(
_doc.get("help"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("help")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `help`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("help")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `help` field is not valid because:",
SourceLine(_doc, "help", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `help` field is not valid because:",
SourceLine(_doc, "help", str),
[e],
detailed_message=f"the `help` field with value `{val}` "
"is not valid because:",
)
)
logo_url = None
if "logo_url" in _doc:
try:
logo_url = load_field(
_doc.get("logo_url"),
union_of_None_type_or_strtype,
baseuri,
loadingOptions,
lc=_doc.get("logo_url")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `logo_url`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("logo_url")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `logo_url` field is not valid because:",
SourceLine(_doc, "logo_url", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `logo_url` field is not valid because:",
SourceLine(_doc, "logo_url", str),
[e],
detailed_message=f"the `logo_url` field with value `{val}` "
"is not valid because:",
)
)
doi = None
if "doi" in _doc:
try:
doi = load_field(
_doc.get("doi"),
union_of_None_type_or_array_of_strtype,
baseuri,
loadingOptions,
lc=_doc.get("doi")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `doi`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("doi")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `doi` field is not valid because:",
SourceLine(_doc, "doi", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `doi` field is not valid because:",
SourceLine(_doc, "doi", str),
[e],
detailed_message=f"the `doi` field with value `{val}` "
"is not valid because:",
)
)
source_metadata = None
if "source_metadata" in _doc:
try:
source_metadata = load_field(
_doc.get("source_metadata"),
union_of_None_type_or_NativeSourceMetadataLoader,
baseuri,
loadingOptions,
lc=_doc.get("source_metadata")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `source_metadata`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("source_metadata")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `source_metadata` field is not valid because:",
SourceLine(_doc, "source_metadata", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `source_metadata` field is not valid because:",
SourceLine(_doc, "source_metadata", str),
[e],
detailed_message=f"the `source_metadata` field with value `{val}` "
"is not valid because:",
)
)
comments = None
if "comments" in _doc:
try:
comments = load_field(
_doc.get("comments"),
union_of_None_type_or_array_of_NativeCommentLoader,
baseuri,
loadingOptions,
lc=_doc.get("comments")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `comments`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("comments")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `comments` field is not valid because:",
SourceLine(_doc, "comments", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `comments` field is not valid because:",
SourceLine(_doc, "comments", str),
[e],
detailed_message=f"the `comments` field with value `{val}` "
"is not valid because:",
)
)
steps = None
if "steps" in _doc:
try:
steps = load_field(
_doc.get("steps"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("steps")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `steps`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("steps")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `steps` field is not valid because:",
SourceLine(_doc, "steps", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `steps` field is not valid because:",
SourceLine(_doc, "steps", str),
[e],
detailed_message=f"the `steps` field with value `{val}` "
"is not valid because:",
)
)
subworkflows = None
if "subworkflows" in _doc:
try:
subworkflows = load_field(
_doc.get("subworkflows"),
union_of_None_type_or_Any_type,
baseuri,
loadingOptions,
lc=_doc.get("subworkflows")
)
except ValidationException as e:
error_message, to_print, verb_tensage = parse_errors(str(e))
if str(e) == "missing required field `subworkflows`":
_errors__.append(
ValidationException(
str(e),
None
)
)
else:
val = _doc.get("subworkflows")
if error_message != str(e):
val_type = convert_typing(extract_type(type(val)))
_errors__.append(
ValidationException(
"the `subworkflows` field is not valid because:",
SourceLine(_doc, "subworkflows", str),
[ValidationException(f"Value is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}",
detailed_message=f"Value `{val}` is a {val_type}, "
f"but valid {to_print} for this field "
f"{verb_tensage} {error_message}")],
)
)
else:
_errors__.append(
ValidationException(
"the `subworkflows` field is not valid because:",
SourceLine(_doc, "subworkflows", str),
[e],
detailed_message=f"the `subworkflows` field with value `{val}` "
"is not valid because:",
)
)
extension_fields: dict[str, Any] = {}
for k in _doc.keys():
if k not in cls.attrs:
if not k:
_errors__.append(
ValidationException("mapping with implicit null key")
)
elif ":" in k:
ex = expand_url(
k, "", loadingOptions, scoped_id=False, vocab_term=False
)
extension_fields[ex] = _doc[k]
else:
_errors__.append(
ValidationException(
"invalid field `{}`, expected one of: `uuid`, `class`, `a_galaxy_workflow`, `format_version`, `name`, `annotation`, `tags`, `version`, `license`, `release`, `creator`, `report`, `readme`, `help`, `logo_url`, `doi`, `source_metadata`, `comments`, `steps`, `subworkflows`".format(
k
),
SourceLine(_doc, k, str),
)
)
if _errors__:
raise ValidationException("", None, _errors__, "*")
_constructed = cls(
uuid=uuid,
a_galaxy_workflow=a_galaxy_workflow,
format_version=format_version,
name=name,
annotation=annotation,
tags=tags,
version=version,
license=license,
release=release,
creator=creator,
report=report,
readme=readme,
help=help,
logo_url=logo_url,
doi=doi,
source_metadata=source_metadata,
comments=comments,
steps=steps,
subworkflows=subworkflows,
extension_fields=extension_fields,
loadingOptions=loadingOptions,
)
loadingOptions.idx[cast(str, name)] = (_constructed, loadingOptions)
return _constructed
[docs]
def save(
self, top: bool = False, base_url: str = "", relative_uris: bool = True
) -> dict[str, Any]:
r: dict[str, Any] = {}
if relative_uris:
for ef in self.extension_fields:
r[prefix_url(ef, self.loadingOptions.vocab)] = self.extension_fields[ef]
else:
for ef in self.extension_fields:
r[ef] = self.extension_fields[ef]
if self.name is not None:
u = save_relative_uri(self.name, base_url, True, None, relative_uris)
r["name"] = u
if self.class_ is not None:
uri = self.loadingOptions.vocab[self.class_]
if p := self.loadingOptions.rvocab.get(uri[: -len(self.class_)]):
uri = f"{p}:{self.class_}"
else:
uri = self.class_
u = save_relative_uri(uri, self.name, False, None, relative_uris)
r["class"] = u
if self.uuid is not None:
r["uuid"] = save(
self.uuid, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.a_galaxy_workflow is not None:
r["a_galaxy_workflow"] = save(
self.a_galaxy_workflow,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.format_version is not None:
r["format_version"] = save(
self.format_version,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.annotation is not None:
r["annotation"] = save(
self.annotation,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.tags is not None:
r["tags"] = save(
self.tags, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.version is not None:
r["version"] = save(
self.version, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.license is not None:
r["license"] = save(
self.license, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.release is not None:
r["release"] = save(
self.release, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.creator is not None:
r["creator"] = save(
self.creator, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.report is not None:
r["report"] = save(
self.report, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.readme is not None:
r["readme"] = save(
self.readme, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.help is not None:
r["help"] = save(
self.help, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.logo_url is not None:
r["logo_url"] = save(
self.logo_url,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.doi is not None:
r["doi"] = save(
self.doi, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.source_metadata is not None:
r["source_metadata"] = save(
self.source_metadata,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.comments is not None:
r["comments"] = save(
self.comments,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
if self.steps is not None:
r["steps"] = save(
self.steps, top=False, base_url=self.name, relative_uris=relative_uris
)
if self.subworkflows is not None:
r["subworkflows"] = save(
self.subworkflows,
top=False,
base_url=self.name,
relative_uris=relative_uris,
)
# top refers to the directory level
if top:
if self.loadingOptions.namespaces:
r["$namespaces"] = self.loadingOptions.namespaces
if self.loadingOptions.schemas:
r["$schemas"] = self.loadingOptions.schemas
return r
attrs = frozenset(
[
"uuid",
"class",
"a_galaxy_workflow",
"format_version",
"name",
"annotation",
"tags",
"version",
"license",
"release",
"creator",
"report",
"readme",
"help",
"logo_url",
"doi",
"source_metadata",
"comments",
"steps",
"subworkflows",
]
)
_vocab = {
"Any": "https://w3id.org/cwl/salad#Any",
"ArraySchema": "https://w3id.org/cwl/salad#ArraySchema",
"BaseNativeComment": "https://galaxyproject.org/gxformat2/native_v0_1#BaseNativeComment",
"BaseNativeCreator": "https://galaxyproject.org/gxformat2/native_v0_1#BaseNativeCreator",
"Documented": "https://w3id.org/cwl/salad#Documented",
"EnumSchema": "https://w3id.org/cwl/salad#EnumSchema",
"HasStepErrors": "https://galaxyproject.org/gxformat2/gxformat2common#HasStepErrors",
"HasStepPosition": "https://galaxyproject.org/gxformat2/gxformat2common#HasStepPosition",
"HasUUID": "https://galaxyproject.org/gxformat2/gxformat2common#HasUUID",
"NativeComment": "https://galaxyproject.org/gxformat2/native_v0_1#NativeComment",
"NativeCreator": "https://galaxyproject.org/gxformat2/native_v0_1#NativeCreator",
"NativeCreatorOrganization": "https://galaxyproject.org/gxformat2/native_v0_1#NativeCreatorOrganization",
"NativeCreatorOrganizationType": "https://galaxyproject.org/gxformat2/native_v0_1#NativeCreatorOrganizationType",
"NativeCreatorPerson": "https://galaxyproject.org/gxformat2/native_v0_1#NativeCreatorPerson",
"NativeCreatorPersonType": "https://galaxyproject.org/gxformat2/native_v0_1#NativeCreatorPersonType",
"NativeFrameComment": "https://galaxyproject.org/gxformat2/native_v0_1#NativeFrameComment",
"NativeFrameCommentData": "https://galaxyproject.org/gxformat2/native_v0_1#NativeFrameCommentData",
"NativeFreehandComment": "https://galaxyproject.org/gxformat2/native_v0_1#NativeFreehandComment",
"NativeFreehandCommentData": "https://galaxyproject.org/gxformat2/native_v0_1#NativeFreehandCommentData",
"NativeGalaxyWorkflow": "https://galaxyproject.org/gxformat2/native_v0_1#NativeGalaxyWorkflow",
"NativeInputConnection": "https://galaxyproject.org/gxformat2/native_v0_1#NativeInputConnection",
"NativeMarkdownComment": "https://galaxyproject.org/gxformat2/native_v0_1#NativeMarkdownComment",
"NativeMarkdownCommentData": "https://galaxyproject.org/gxformat2/native_v0_1#NativeMarkdownCommentData",
"NativePostJobAction": "https://galaxyproject.org/gxformat2/native_v0_1#NativePostJobAction",
"NativeReport": "https://galaxyproject.org/gxformat2/native_v0_1#NativeReport",
"NativeSourceMetadata": "https://galaxyproject.org/gxformat2/native_v0_1#NativeSourceMetadata",
"NativeStep": "https://galaxyproject.org/gxformat2/native_v0_1#NativeStep",
"NativeStepInput": "https://galaxyproject.org/gxformat2/native_v0_1#NativeStepInput",
"NativeStepOutput": "https://galaxyproject.org/gxformat2/native_v0_1#NativeStepOutput",
"NativeStepType": "https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType",
"NativeTextComment": "https://galaxyproject.org/gxformat2/native_v0_1#NativeTextComment",
"NativeTextCommentData": "https://galaxyproject.org/gxformat2/native_v0_1#NativeTextCommentData",
"NativeWorkflowOutput": "https://galaxyproject.org/gxformat2/native_v0_1#NativeWorkflowOutput",
"Organization": "https://galaxyproject.org/gxformat2/native_v0_1#NativeCreatorOrganizationType/Organization",
"Person": "https://galaxyproject.org/gxformat2/native_v0_1#NativeCreatorPersonType/Person",
"PrimitiveType": "https://w3id.org/cwl/salad#PrimitiveType",
"RecordField": "https://w3id.org/cwl/salad#RecordField",
"RecordFieldDefinition": "https://galaxyproject.org/gxformat2/gxformat2common#RecordFieldDefinition",
"RecordSchema": "https://w3id.org/cwl/salad#RecordSchema",
"ReferencesTool": "https://galaxyproject.org/gxformat2/gxformat2common#ReferencesTool",
"SampleSheetColumnDefinition": "https://galaxyproject.org/gxformat2/gxformat2common#SampleSheetColumnDefinition",
"StepPosition": "https://galaxyproject.org/gxformat2/gxformat2common#StepPosition",
"ToolShedRepository": "https://galaxyproject.org/gxformat2/gxformat2common#ToolShedRepository",
"WorkflowTextOption": "https://galaxyproject.org/gxformat2/gxformat2common#WorkflowTextOption",
"array": "https://w3id.org/cwl/salad#array",
"boolean": "http://www.w3.org/2001/XMLSchema#boolean",
"data_collection_input": "https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/data_collection_input",
"data_input": "https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/data_input",
"double": "http://www.w3.org/2001/XMLSchema#double",
"enum": "https://w3id.org/cwl/salad#enum",
"float": "http://www.w3.org/2001/XMLSchema#float",
"int": "http://www.w3.org/2001/XMLSchema#int",
"long": "http://www.w3.org/2001/XMLSchema#long",
"null": "https://w3id.org/cwl/salad#null",
"parameter_input": "https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/parameter_input",
"pause": "https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/pause",
"pick_value": "https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/pick_value",
"record": "https://w3id.org/cwl/salad#record",
"string": "http://www.w3.org/2001/XMLSchema#string",
"subworkflow": "https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/subworkflow",
"tool": "https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/tool",
}
_rvocab = {
"https://w3id.org/cwl/salad#Any": "Any",
"https://w3id.org/cwl/salad#ArraySchema": "ArraySchema",
"https://galaxyproject.org/gxformat2/native_v0_1#BaseNativeComment": "BaseNativeComment",
"https://galaxyproject.org/gxformat2/native_v0_1#BaseNativeCreator": "BaseNativeCreator",
"https://w3id.org/cwl/salad#Documented": "Documented",
"https://w3id.org/cwl/salad#EnumSchema": "EnumSchema",
"https://galaxyproject.org/gxformat2/gxformat2common#HasStepErrors": "HasStepErrors",
"https://galaxyproject.org/gxformat2/gxformat2common#HasStepPosition": "HasStepPosition",
"https://galaxyproject.org/gxformat2/gxformat2common#HasUUID": "HasUUID",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeComment": "NativeComment",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeCreator": "NativeCreator",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeCreatorOrganization": "NativeCreatorOrganization",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeCreatorOrganizationType": "NativeCreatorOrganizationType",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeCreatorPerson": "NativeCreatorPerson",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeCreatorPersonType": "NativeCreatorPersonType",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeFrameComment": "NativeFrameComment",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeFrameCommentData": "NativeFrameCommentData",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeFreehandComment": "NativeFreehandComment",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeFreehandCommentData": "NativeFreehandCommentData",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeGalaxyWorkflow": "NativeGalaxyWorkflow",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeInputConnection": "NativeInputConnection",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeMarkdownComment": "NativeMarkdownComment",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeMarkdownCommentData": "NativeMarkdownCommentData",
"https://galaxyproject.org/gxformat2/native_v0_1#NativePostJobAction": "NativePostJobAction",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeReport": "NativeReport",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeSourceMetadata": "NativeSourceMetadata",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeStep": "NativeStep",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeStepInput": "NativeStepInput",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeStepOutput": "NativeStepOutput",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType": "NativeStepType",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeTextComment": "NativeTextComment",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeTextCommentData": "NativeTextCommentData",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeWorkflowOutput": "NativeWorkflowOutput",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeCreatorOrganizationType/Organization": "Organization",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeCreatorPersonType/Person": "Person",
"https://w3id.org/cwl/salad#PrimitiveType": "PrimitiveType",
"https://w3id.org/cwl/salad#RecordField": "RecordField",
"https://galaxyproject.org/gxformat2/gxformat2common#RecordFieldDefinition": "RecordFieldDefinition",
"https://w3id.org/cwl/salad#RecordSchema": "RecordSchema",
"https://galaxyproject.org/gxformat2/gxformat2common#ReferencesTool": "ReferencesTool",
"https://galaxyproject.org/gxformat2/gxformat2common#SampleSheetColumnDefinition": "SampleSheetColumnDefinition",
"https://galaxyproject.org/gxformat2/gxformat2common#StepPosition": "StepPosition",
"https://galaxyproject.org/gxformat2/gxformat2common#ToolShedRepository": "ToolShedRepository",
"https://galaxyproject.org/gxformat2/gxformat2common#WorkflowTextOption": "WorkflowTextOption",
"https://w3id.org/cwl/salad#array": "array",
"http://www.w3.org/2001/XMLSchema#boolean": "boolean",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/data_collection_input": "data_collection_input",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/data_input": "data_input",
"http://www.w3.org/2001/XMLSchema#double": "double",
"https://w3id.org/cwl/salad#enum": "enum",
"http://www.w3.org/2001/XMLSchema#float": "float",
"http://www.w3.org/2001/XMLSchema#int": "int",
"http://www.w3.org/2001/XMLSchema#long": "long",
"https://w3id.org/cwl/salad#null": "null",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/parameter_input": "parameter_input",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/pause": "pause",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/pick_value": "pick_value",
"https://w3id.org/cwl/salad#record": "record",
"http://www.w3.org/2001/XMLSchema#string": "string",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/subworkflow": "subworkflow",
"https://galaxyproject.org/gxformat2/native_v0_1#NativeStepType/tool": "tool",
}
strtype = _PrimitiveLoader(str)
inttype = _PrimitiveLoader(int)
floattype = _PrimitiveLoader(float)
booltype = _PrimitiveLoader(bool)
None_type = _PrimitiveLoader(type(None))
Any_type = _AnyLoader()
PrimitiveTypeLoader = _EnumLoader(
(
"null",
"boolean",
"int",
"long",
"float",
"double",
"string",
),
"PrimitiveType",
)
"""
Salad data types are based on Avro schema declarations. Refer to the
[Avro schema declaration documentation](https://avro.apache.org/docs/current/spec.html#schemas) for
detailed information.
null: no value
boolean: a binary value
int: 32-bit signed integer
long: 64-bit signed integer
float: single precision (32-bit) IEEE 754 floating-point number
double: double precision (64-bit) IEEE 754 floating-point number
string: Unicode character sequence
"""
AnyLoader = _EnumLoader(("Any",), "Any")
"""
The **Any** type validates for any non-null value.
"""
RecordFieldLoader = _RecordLoader(RecordField, None, None)
RecordSchemaLoader = _RecordLoader(RecordSchema, None, None)
EnumSchemaLoader = _RecordLoader(EnumSchema, None, None)
ArraySchemaLoader = _RecordLoader(ArraySchema, None, None)
StepPositionLoader = _RecordLoader(StepPosition, None, None)
SampleSheetColumnDefinitionLoader = _RecordLoader(
SampleSheetColumnDefinition, None, None
)
RecordFieldDefinitionLoader = _RecordLoader(RecordFieldDefinition, None, None)
WorkflowTextOptionLoader = _RecordLoader(WorkflowTextOption, None, None)
ToolShedRepositoryLoader = _RecordLoader(ToolShedRepository, None, None)
NativeStepTypeLoader = _EnumLoader(
(
"data_input",
"data_collection_input",
"parameter_input",
"tool",
"subworkflow",
"pause",
"pick_value",
),
"NativeStepType",
)
"""
Step module types in the native Galaxy workflow format.
data_input: A single dataset input to the workflow.
data_collection_input: A dataset collection input to the workflow.
parameter_input: A typed parameter input (text, integer, float, boolean, color).
tool: A Galaxy tool execution step.
subworkflow: An embedded or referenced sub-workflow.
pause: A manual pause point that halts execution until user intervention.
pick_value: Select the first non-null value from multiple inputs.
"""
NativeStepInputLoader = _RecordLoader(NativeStepInput, None, None)
NativeStepOutputLoader = _RecordLoader(NativeStepOutput, None, None)
NativeWorkflowOutputLoader = _RecordLoader(NativeWorkflowOutput, None, None)
NativeInputConnectionLoader = _RecordLoader(NativeInputConnection, None, None)
NativePostJobActionLoader = _RecordLoader(NativePostJobAction, None, None)
NativeTextCommentDataLoader = _RecordLoader(NativeTextCommentData, None, None)
NativeMarkdownCommentDataLoader = _RecordLoader(NativeMarkdownCommentData, None, None)
NativeFrameCommentDataLoader = _RecordLoader(NativeFrameCommentData, None, None)
NativeFreehandCommentDataLoader = _RecordLoader(NativeFreehandCommentData, None, None)
NativeTextCommentLoader = _RecordLoader(NativeTextComment, None, None)
NativeMarkdownCommentLoader = _RecordLoader(NativeMarkdownComment, None, None)
NativeFrameCommentLoader = _RecordLoader(NativeFrameComment, None, None)
NativeFreehandCommentLoader = _RecordLoader(NativeFreehandComment, None, None)
NativeCommentLoader = _UnionLoader((), "NativeCommentLoader")
NativeStepLoader = _RecordLoader(NativeStep, None, None)
NativeReportLoader = _RecordLoader(NativeReport, None, None)
NativeCreatorPersonTypeLoader = _EnumLoader(("Person",), "NativeCreatorPersonType")
"""
Discriminator for schema.org Person creators.
"""
NativeCreatorOrganizationTypeLoader = _EnumLoader(
("Organization",), "NativeCreatorOrganizationType"
)
"""
Discriminator for schema.org Organization creators.
"""
NativeCreatorPersonLoader = _RecordLoader(NativeCreatorPerson, None, None)
NativeCreatorOrganizationLoader = _RecordLoader(NativeCreatorOrganization, None, None)
NativeCreatorLoader = _UnionLoader((), "NativeCreatorLoader")
NativeSourceMetadataLoader = _RecordLoader(NativeSourceMetadata, None, None)
NativeGalaxyWorkflowLoader = _RecordLoader(NativeGalaxyWorkflow, None, None)
array_of_strtype = _ArrayLoader(strtype)
union_of_None_type_or_strtype_or_array_of_strtype = _UnionLoader(
(
None_type,
strtype,
array_of_strtype,
)
)
uri_strtype_True_False_None_None = _URILoader(strtype, True, False, None, None)
union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype = _UnionLoader(
(
PrimitiveTypeLoader,
RecordSchemaLoader,
EnumSchemaLoader,
ArraySchemaLoader,
strtype,
)
)
array_of_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype = _ArrayLoader(
union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype
)
union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype_or_array_of_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype = _UnionLoader(
(
PrimitiveTypeLoader,
RecordSchemaLoader,
EnumSchemaLoader,
ArraySchemaLoader,
strtype,
array_of_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype,
)
)
typedsl_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype_or_array_of_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype_2 = _TypeDSLLoader(
union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype_or_array_of_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype,
2,
"v1.1",
)
array_of_RecordFieldLoader = _ArrayLoader(RecordFieldLoader)
union_of_None_type_or_array_of_RecordFieldLoader = _UnionLoader(
(
None_type,
array_of_RecordFieldLoader,
)
)
idmap_fields_union_of_None_type_or_array_of_RecordFieldLoader = _IdMapLoader(
union_of_None_type_or_array_of_RecordFieldLoader, "name", "type"
)
enum_d9cba076fca539106791a4f46d198c7fcfbdb779Loader = _EnumLoader(
("record",), "enum_d9cba076fca539106791a4f46d198c7fcfbdb779"
)
typedsl_enum_d9cba076fca539106791a4f46d198c7fcfbdb779Loader_2 = _TypeDSLLoader(
enum_d9cba076fca539106791a4f46d198c7fcfbdb779Loader, 2, "v1.1"
)
uri_array_of_strtype_True_False_None_None = _URILoader(
array_of_strtype, True, False, None, None
)
enum_d961d79c225752b9fadb617367615ab176b47d77Loader = _EnumLoader(
("enum",), "enum_d961d79c225752b9fadb617367615ab176b47d77"
)
typedsl_enum_d961d79c225752b9fadb617367615ab176b47d77Loader_2 = _TypeDSLLoader(
enum_d961d79c225752b9fadb617367615ab176b47d77Loader, 2, "v1.1"
)
uri_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype_or_array_of_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype_False_True_2_None = _URILoader(
union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype_or_array_of_union_of_PrimitiveTypeLoader_or_RecordSchemaLoader_or_EnumSchemaLoader_or_ArraySchemaLoader_or_strtype,
False,
True,
2,
None,
)
enum_d062602be0b4b8fd33e69e29a841317b6ab665bcLoader = _EnumLoader(
("array",), "enum_d062602be0b4b8fd33e69e29a841317b6ab665bc"
)
typedsl_enum_d062602be0b4b8fd33e69e29a841317b6ab665bcLoader_2 = _TypeDSLLoader(
enum_d062602be0b4b8fd33e69e29a841317b6ab665bcLoader, 2, "v1.1"
)
union_of_None_type_or_strtype = _UnionLoader(
(
None_type,
strtype,
)
)
union_of_None_type_or_StepPositionLoader = _UnionLoader(
(
None_type,
StepPositionLoader,
)
)
union_of_floattype_or_inttype = _UnionLoader(
(
floattype,
inttype,
)
)
union_of_None_type_or_ToolShedRepositoryLoader = _UnionLoader(
(
None_type,
ToolShedRepositoryLoader,
)
)
typedsl_strtype_2 = _TypeDSLLoader(strtype, 2, "v1.1")
union_of_None_type_or_strtype_or_inttype_or_floattype_or_booltype = _UnionLoader(
(
None_type,
strtype,
inttype,
floattype,
booltype,
)
)
array_of_Any_type = _ArrayLoader(Any_type)
union_of_None_type_or_array_of_Any_type = _UnionLoader(
(
None_type,
array_of_Any_type,
)
)
union_of_strtype_or_inttype_or_floattype_or_booltype = _UnionLoader(
(
strtype,
inttype,
floattype,
booltype,
)
)
array_of_union_of_strtype_or_inttype_or_floattype_or_booltype = _ArrayLoader(
union_of_strtype_or_inttype_or_floattype_or_booltype
)
union_of_None_type_or_array_of_union_of_strtype_or_inttype_or_floattype_or_booltype = (
_UnionLoader(
(
None_type,
array_of_union_of_strtype_or_inttype_or_floattype_or_booltype,
)
)
)
union_of_strtype_or_array_of_strtype = _UnionLoader(
(
strtype,
array_of_strtype,
)
)
typedsl_union_of_strtype_or_array_of_strtype_2 = _TypeDSLLoader(
union_of_strtype_or_array_of_strtype, 2, "v1.1"
)
typedsl_union_of_None_type_or_strtype_2 = _TypeDSLLoader(
union_of_None_type_or_strtype, 2, "v1.1"
)
union_of_None_type_or_inttype = _UnionLoader(
(
None_type,
inttype,
)
)
union_of_strtype_or_None_type = _UnionLoader(
(
strtype,
None_type,
)
)
union_of_None_type_or_Any_type = _UnionLoader(
(
None_type,
Any_type,
)
)
union_of_None_type_or_booltype = _UnionLoader(
(
None_type,
booltype,
)
)
union_of_None_type_or_floattype_or_inttype = _UnionLoader(
(
None_type,
floattype,
inttype,
)
)
union_of_None_type_or_NativeTextCommentDataLoader = _UnionLoader(
(
None_type,
NativeTextCommentDataLoader,
)
)
union_of_None_type_or_NativeMarkdownCommentDataLoader = _UnionLoader(
(
None_type,
NativeMarkdownCommentDataLoader,
)
)
union_of_None_type_or_NativeFrameCommentDataLoader = _UnionLoader(
(
None_type,
NativeFrameCommentDataLoader,
)
)
array_of_inttype = _ArrayLoader(inttype)
union_of_None_type_or_array_of_inttype = _UnionLoader(
(
None_type,
array_of_inttype,
)
)
union_of_None_type_or_NativeFreehandCommentDataLoader = _UnionLoader(
(
None_type,
NativeFreehandCommentDataLoader,
)
)
uri_union_of_None_type_or_strtype_True_False_None_None = _URILoader(
union_of_None_type_or_strtype, True, False, None, None
)
union_of_None_type_or_NativeStepTypeLoader = _UnionLoader(
(
None_type,
NativeStepTypeLoader,
)
)
typedsl_union_of_None_type_or_NativeStepTypeLoader_2 = _TypeDSLLoader(
union_of_None_type_or_NativeStepTypeLoader, 2, "v1.1"
)
union_of_None_type_or_strtype_or_Any_type = _UnionLoader(
(
None_type,
strtype,
Any_type,
)
)
array_of_NativeStepInputLoader = _ArrayLoader(NativeStepInputLoader)
union_of_None_type_or_array_of_NativeStepInputLoader = _UnionLoader(
(
None_type,
array_of_NativeStepInputLoader,
)
)
array_of_NativeStepOutputLoader = _ArrayLoader(NativeStepOutputLoader)
union_of_None_type_or_array_of_NativeStepOutputLoader = _UnionLoader(
(
None_type,
array_of_NativeStepOutputLoader,
)
)
array_of_NativeWorkflowOutputLoader = _ArrayLoader(NativeWorkflowOutputLoader)
union_of_None_type_or_array_of_NativeWorkflowOutputLoader = _UnionLoader(
(
None_type,
array_of_NativeWorkflowOutputLoader,
)
)
uri_NativeCreatorPersonTypeLoader_False_True_None_None = _URILoader(
NativeCreatorPersonTypeLoader, False, True, None, None
)
uri_NativeCreatorOrganizationTypeLoader_False_True_None_None = _URILoader(
NativeCreatorOrganizationTypeLoader, False, True, None, None
)
NativeGalaxyWorkflow_classLoader = _EnumLoader(
("NativeGalaxyWorkflow",), "NativeGalaxyWorkflow_class"
)
uri_NativeGalaxyWorkflow_classLoader_False_True_None_None = _URILoader(
NativeGalaxyWorkflow_classLoader, False, True, None, None
)
union_of_None_type_or_array_of_strtype = _UnionLoader(
(
None_type,
array_of_strtype,
)
)
union_of_None_type_or_NativeReportLoader = _UnionLoader(
(
None_type,
NativeReportLoader,
)
)
union_of_None_type_or_NativeSourceMetadataLoader = _UnionLoader(
(
None_type,
NativeSourceMetadataLoader,
)
)
array_of_NativeCommentLoader = _ArrayLoader(NativeCommentLoader)
union_of_None_type_or_array_of_NativeCommentLoader = _UnionLoader(
(
None_type,
array_of_NativeCommentLoader,
)
)
union_of_NativeGalaxyWorkflowLoader = _UnionLoader((NativeGalaxyWorkflowLoader,))
array_of_union_of_NativeGalaxyWorkflowLoader = _ArrayLoader(
union_of_NativeGalaxyWorkflowLoader
)
union_of_NativeGalaxyWorkflowLoader_or_array_of_union_of_NativeGalaxyWorkflowLoader = (
_UnionLoader(
(
NativeGalaxyWorkflowLoader,
array_of_union_of_NativeGalaxyWorkflowLoader,
)
)
)
NativeCommentLoader.add_loaders(
(
NativeTextCommentLoader,
NativeMarkdownCommentLoader,
NativeFrameCommentLoader,
NativeFreehandCommentLoader,
)
)
NativeCreatorLoader.add_loaders(
(
NativeCreatorPersonLoader,
NativeCreatorOrganizationLoader,
)
)
[docs]
def load_document(
doc: Any,
baseuri: Optional[str] = None,
loadingOptions: Optional[LoadingOptions] = None,
) -> Any:
if baseuri is None:
baseuri = file_uri(os.getcwd()) + "/"
if loadingOptions is None:
loadingOptions = LoadingOptions()
result, metadata = _document_load(
union_of_NativeGalaxyWorkflowLoader_or_array_of_union_of_NativeGalaxyWorkflowLoader,
doc,
baseuri,
loadingOptions,
)
return result
[docs]
def load_document_with_metadata(
doc: Any,
baseuri: Optional[str] = None,
loadingOptions: Optional[LoadingOptions] = None,
addl_metadata_fields: Optional[MutableSequence[str]] = None,
) -> Any:
if baseuri is None:
baseuri = file_uri(os.getcwd()) + "/"
if loadingOptions is None:
loadingOptions = LoadingOptions(fileuri=baseuri)
return _document_load(
union_of_NativeGalaxyWorkflowLoader_or_array_of_union_of_NativeGalaxyWorkflowLoader,
doc,
baseuri,
loadingOptions,
addl_metadata_fields=addl_metadata_fields,
)
[docs]
def load_document_by_string(
string: Any,
uri: str,
loadingOptions: Optional[LoadingOptions] = None,
) -> Any:
yaml = yaml_no_ts()
result = yaml.load(string)
add_lc_filename(result, uri)
if loadingOptions is None:
loadingOptions = LoadingOptions(fileuri=uri)
result, metadata = _document_load(
union_of_NativeGalaxyWorkflowLoader_or_array_of_union_of_NativeGalaxyWorkflowLoader,
result,
uri,
loadingOptions,
)
return result
[docs]
def load_document_by_yaml(
yaml: Any,
uri: str,
loadingOptions: Optional[LoadingOptions] = None,
) -> Any:
"""
Shortcut to load via a YAML object.
yaml: must be from ruamel.yaml.main.YAML.load with preserve_quotes=True
"""
add_lc_filename(yaml, uri)
if loadingOptions is None:
loadingOptions = LoadingOptions(fileuri=uri)
result, metadata = _document_load(
union_of_NativeGalaxyWorkflowLoader_or_array_of_union_of_NativeGalaxyWorkflowLoader,
yaml,
uri,
loadingOptions,
)
return result