schema_salad.python_codegen

Python code generator for a given schema salad definition.

Attributes

black

prims

Classes

PythonCodeGen

Generation of Python code for a given Schema Salad definition.

Functions

fmt(text, indent)

Use black to format this snippet.

Module Contents

schema_salad.python_codegen.black = None
schema_salad.python_codegen.prims
schema_salad.python_codegen.fmt(text, indent)

Use black to format this snippet.

:param indent the indent level for the current context

Parameters:
Return type:

str

class schema_salad.python_codegen.PythonCodeGen(out, copyright, parser_info, salad_version)

Bases: schema_salad.codegen_base.CodeGenBase

Inheritance diagram of schema_salad.python_codegen.PythonCodeGen

Generation of Python code for a given Schema Salad definition.

Parameters:
  • out (IO[str])

  • copyright (Optional[str])

  • parser_info (str)

  • salad_version (str)

out
current_class_is_abstract = False
serializer
idfield = ''
copyright
parser_info
salad_version
static safe_name(name)

Generate a safe version of the given name.

Parameters:

name (str)

Return type:

str

prologue()

Trigger to generate the prolouge code.

Return type:

None

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

Produce the header for the given class.

Parameters:
Return type:

None

end_class(classname, field_names)

Signal that we are done with this class.

Parameters:
Return type:

None

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

Parse the given type declaration and declare its components.

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

  • container (Optional[str])

  • no_link_check (Optional[bool])

Return type:

schema_salad.codegen_base.TypeDef

declare_id_field(name, fieldtype, doc, optional)

Output the code to handle the given ID field.

Parameters:
Return type:

None

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

Output the code to load the given field.

Parameters:
Return type:

None

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

Construct the TypeDef for the given URI loader.

Parameters:
Return type:

schema_salad.codegen_base.TypeDef

idmap_loader(field, inner, map_subject, map_predicate)

Construct the TypeDef for the given mapped ID loader.

Parameters:
Return type:

schema_salad.codegen_base.TypeDef

typedsl_loader(inner, ref_scope)

Construct the TypeDef for the given DSL loader.

Parameters:
Return type:

schema_salad.codegen_base.TypeDef

secondaryfilesdsl_loader(inner)

Construct the TypeDef for secondary files.

Parameters:

inner (schema_salad.codegen_base.TypeDef)

Return type:

schema_salad.codegen_base.TypeDef

epilogue(root_loader)

Trigger to generate the epilouge code.

Parameters:

root_loader (schema_salad.codegen_base.TypeDef)

Return type:

None