schema_salad.codegen_base

Base class for the generation of loaders from schema-salad definitions.

Classes

TypeDef

Schema Salad type description.

LazyInitDef

Lazy initialization logic.

CodeGenBase

Abstract base class for schema salad code generators.

Module Contents

class schema_salad.codegen_base.TypeDef

Bases: NamedTuple

Inheritance diagram of schema_salad.codegen_base.TypeDef

Schema Salad type description.

name: str
init: str
is_uri: bool = False
scoped_id: bool = False
ref_scope: int | None = 0
loader_type: str | None = None
instance_type: str | None = None
abstract: bool = False
class schema_salad.codegen_base.LazyInitDef

Bases: NamedTuple

Inheritance diagram of schema_salad.codegen_base.LazyInitDef

Lazy initialization logic.

name: str
init: str
class schema_salad.codegen_base.CodeGenBase

Abstract base class for schema salad code generators.

collected_types: collections.OrderedDict[str, TypeDef]
lazy_inits: collections.OrderedDict[str, LazyInitDef]
vocab: dict[str, str]
declare_type(declared_type)

Add this type to our collection, if needed.

Parameters:

declared_type (TypeDef)

Return type:

TypeDef

add_lazy_init(lazy_init)

Add lazy initialization logic for a given type.

Parameters:

lazy_init (LazyInitDef)

Return type:

None

add_vocab(name, uri)

Add the given name as an abbreviation for the given URI.

Parameters:
Return type:

None

abstractmethod prologue()

Trigger to generate the prolouge code.

Return type:

None

static safe_name(name)
Abstractmethod:

Parameters:

name (str)

Return type:

str

Generate a safe version of the given name.

abstractmethod begin_class(classname, extends, doc, abstract, field_names, idfield, optional_fields)

Produce the header for the given class.

Parameters:
Return type:

None

abstractmethod end_class(classname, field_names)

Signal that we are done with this class.

Parameters:
Return type:

None

abstractmethod type_loader(type_declaration, container=None, no_link_check=None)

Parse the given type declaration and declare its components.

Parameters:
  • type_declaration (list[Any] | dict[str, Any])

  • container (str | None)

  • no_link_check (bool | None)

Return type:

TypeDef

abstractmethod declare_field(name, fieldtype, doc, optional, subscope)

Output the code to load the given field.

Parameters:
Return type:

None

abstractmethod declare_id_field(name, fieldtype, doc, optional)

Output the code to handle the given ID field.

Parameters:
Return type:

None

abstractmethod uri_loader(inner, scoped_id, vocab_term, ref_scope, no_link_check=None)

Construct the TypeDef for the given URI loader.

Parameters:
Return type:

TypeDef

abstractmethod idmap_loader(field, inner, map_subject, map_predicate)

Construct the TypeDef for the given mapped ID loader.

Parameters:
Return type:

TypeDef

abstractmethod typedsl_loader(inner, ref_scope)

Construct the TypeDef for the given DSL loader.

Parameters:
Return type:

TypeDef

abstractmethod epilogue(root_loader)

Trigger to generate the epilouge code.

Parameters:

root_loader (TypeDef)

Return type:

None

abstractmethod secondaryfilesdsl_loader(inner)

Construct the TypeDef for secondary files.

Parameters:

inner (TypeDef)

Return type:

TypeDef