schema_salad.python_codegen_support

Template code used by python_codegen.py.

Module Contents

Classes

LoadingOptions

Saveable

Mark classes than have a save() and fromDoc() function.

Functions

load_field(val, fieldtype, baseuri, loadingOptions[, lc])

Load field.

extract_type(val_type)

Take a type of value, and extracts the value as a string.

convert_typing(val_type)

Normalize type names to schema-salad types.

parse_errors(error_message)

Parse error messages from several loaders into one error message.

save(val[, top, base_url, relative_uris])

save_with_metadata(val, valLoadingOpts[, top, ...])

Save and set $namespaces, $schemas, $base and any other metadata fields at the top level.

expand_url(url, base_url, loadingOptions[, scoped_id, ...])

file_uri(path[, split_frag])

Transform a file path into a URL with file scheme.

prefix_url(url, namespaces)

Expand short forms into full URLs using the given namespace dictionary.

save_relative_uri(uri, base_url, scoped_id, ref_scope, ...)

Convert any URI to a relative one, obeying the scoping rules.

shortname(inputid)

Compute the shortname of a fully qualified identifier.

Attributes

IdxType

save_type

schema_salad.python_codegen_support.IdxType
class schema_salad.python_codegen_support.LoadingOptions(fetcher=None, namespaces=None, schemas=None, fileuri=None, copyfrom=None, original_doc=None, addl_metadata=None, baseuri=None, idx=None, imports=None, includes=None, no_link_check=None, container=None)
Parameters:
  • fetcher (Optional[schema_salad.fetcher.Fetcher]) –

  • namespaces (Optional[Dict[str, str]]) –

  • schemas (Optional[List[str]]) –

  • fileuri (Optional[str]) –

  • copyfrom (Optional[LoadingOptions]) –

  • original_doc (Optional[Any]) –

  • addl_metadata (Optional[Dict[str, str]]) –

  • baseuri (Optional[str]) –

  • idx (Optional[IdxType]) –

  • imports (Optional[List[str]]) –

  • includes (Optional[List[str]]) –

  • no_link_check (Optional[bool]) –

  • container (Optional[str]) –

property graph: rdflib.Graph

Generate a merged rdflib.Graph from all entries in self.schemas.

Return type:

rdflib.Graph

idx: IdxType
fileuri: str | None
baseuri: str
namespaces: MutableMapping[str, str]
schemas: MutableSequence[str]
original_doc: Any | None
addl_metadata: MutableMapping[str, Any]
fetcher: schema_salad.fetcher.Fetcher
vocab: Dict[str, str]
rvocab: Dict[str, str]
cache: schema_salad.utils.CacheType
imports: List[str]
includes: List[str]
container: str | None
class schema_salad.python_codegen_support.Saveable

Bases: abc.ABC

digraph inheritance09618532e3 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "ABC" [URL="https://docs.python.org/3/library/abc.html#abc.ABC",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Helper class that provides a standard way to create an ABC using"]; "Saveable" [URL="#schema_salad.python_codegen_support.Saveable",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Mark classes than have a save() and fromDoc() function."]; "ABC" -> "Saveable" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

Mark classes than have a save() and fromDoc() function.

abstract classmethod fromDoc(_doc, baseuri, loadingOptions, docRoot=None)

Construct this object from the result of yaml.load().

Parameters:
Return type:

Saveable

abstract save(top=False, base_url='', relative_uris=True)

Convert this object to a JSON/YAML friendly dictionary.

Parameters:
  • top (bool) –

  • base_url (str) –

  • relative_uris (bool) –

Return type:

Dict[str, Any]

schema_salad.python_codegen_support.load_field(val, fieldtype, baseuri, loadingOptions, lc=None)

Load field.

Parameters:
  • val (Union[str, Dict[str, str]]) –

  • fieldtype (_Loader) –

  • baseuri (str) –

  • loadingOptions (LoadingOptions) –

  • lc (Optional[List[Any]]) –

Return type:

Any

schema_salad.python_codegen_support.save_type
schema_salad.python_codegen_support.extract_type(val_type)

Take a type of value, and extracts the value as a string.

Parameters:

val_type (Type[Any]) –

Return type:

str

schema_salad.python_codegen_support.convert_typing(val_type)

Normalize type names to schema-salad types.

Parameters:

val_type (str) –

Return type:

str

schema_salad.python_codegen_support.parse_errors(error_message)

Parse error messages from several loaders into one error message.

Parameters:

error_message (str) –

Return type:

Tuple[str, str, str]

schema_salad.python_codegen_support.save(val, top=True, base_url='', relative_uris=True)
Parameters:
  • val (Any) –

  • top (bool) –

  • base_url (str) –

  • relative_uris (bool) –

Return type:

save_type

schema_salad.python_codegen_support.save_with_metadata(val, valLoadingOpts, top=True, base_url='', relative_uris=True)

Save and set $namespaces, $schemas, $base and any other metadata fields at the top level.

Parameters:
Return type:

save_type

schema_salad.python_codegen_support.expand_url(url, base_url, loadingOptions, scoped_id=False, vocab_term=False, scoped_ref=None)
Parameters:
Return type:

str

schema_salad.python_codegen_support.file_uri(path, split_frag=False)

Transform a file path into a URL with file scheme.

Parameters:
  • path (str) –

  • split_frag (bool) –

Return type:

str

schema_salad.python_codegen_support.prefix_url(url, namespaces)

Expand short forms into full URLs using the given namespace dictionary.

Parameters:
  • url (str) –

  • namespaces (Dict[str, str]) –

Return type:

str

schema_salad.python_codegen_support.save_relative_uri(uri, base_url, scoped_id, ref_scope, relative_uris)

Convert any URI to a relative one, obeying the scoping rules.

Parameters:
  • uri (Any) –

  • base_url (str) –

  • scoped_id (bool) –

  • ref_scope (Optional[int]) –

  • relative_uris (bool) –

Return type:

Any

schema_salad.python_codegen_support.shortname(inputid)

Compute the shortname of a fully qualified identifier.

See https://w3id.org/cwl/v1.2/SchemaSalad.html#Short_names.

Parameters:

inputid (str) –

Return type:

str