gws.spec.runtime

Spec runtime: loads the specs and implements gws.SpecRuntime.

Source code: gws.spec.runtime

Module Contents

gws.spec.runtime.create(manifest_path: str = '', read_cache=False, write_cache=False) → Object

Create a spec runtime object by generating or loading the specs.

The cache file is stored in gws.c.SPEC_DIR, one file per manifest path.

Parameters:
  • manifest_path – Path to the application manifest. Without a manifest, only the built-in plugins are used.

  • read_cache – If True, load the specs from the cache file if it exists.

  • write_cache – If True, write the generated specs to the cache file.

Returns:

The spec runtime object.

Raises:

GeneratorError – If the specs cannot be generated.

gws.spec.runtime.Error
gws.spec.runtime.GeneratorError
gws.spec.runtime.LoadError
class gws.spec.runtime.Object(sd: gws.spec.core.SpecData)

Bases: gws.SpecRuntime

Spec runtime object.

appBundlePaths = []

Paths of the client bundles of all chunks.

chunks
manifest

Application manifest.

manifestPath
rawCommands
sd
serverTypes
serverTypesDict
strings
version

Application version.

cli_commands(lang='en')

List the CLI commands with their arguments and docs.

A command name like gws.ext.command.cli.serverStart is split into cmd1='server' and cmd2='start'.

Parameters:

lang – Language code for the docs, falls back to English.

Returns:

A list of gws.Data objects with cmd1, cmd2, doc and args, sorted by command name. Each argument has name, type, doc, defaultValue and hasDefault.

command_descriptor(command_category, command_name)

Get a command descriptor.

Parameters:
  • command_category – Command category.

  • command_name – Command name.

Returns:

A descriptor or None if the command is not found.

get_class(classref, ext_type=None)

Get a class object for a class reference.

The module defining the class is imported on demand.

Parameters:
  • classref – Class reference: a class, a class name or an extension name.

  • ext_type – Extension type, used when classref is an extension category name. Defaults to default.

Returns:

A class or None if the reference is not found.

Raises:

gws.spec.core.LoadError – If the module cannot be imported.

get_config_types(lang)

Get the configuration types as dictionaries.

Docstrings, titles and enum docs are taken from the strings in the given language.

Parameters:

lang – Language code.

Returns:

A list of type dictionaries.

get_type(key)

Get a type by uid or extension name.

Parameters:

key – Type uid or extension name.

Returns:

The type or None if not found.

object_descriptor(name)

Get an object descriptor.

Parameters:

type_name – Type uid or extension name.

Returns:

A descriptor or None if the type is not found.

parse_classref(classref: gws.ClassRef) → tuple[type | None, str, str]

Parse a class reference.

Parameters:

classref – Class reference.

Returns:

A tuple (class object, class name, extension name), where only one element is set.

Raises:

gws.spec.core.Error – If the class reference is invalid.

read(value, type_name, path='', options=None)

Read and validate a raw value according to a spec type.

Parameters:
  • value – Raw value from a config or a request.

  • type_name – Type uid or extension name.

  • path – Path of the config file, used to resolve relative paths and in error messages.

  • options – Read options.

Returns:

The parsed value. Objects are returned as gws.Data.

Raises:

gws.spec.core.ReadError – If the value does not match the type.

register_object(classref, ext_type, cls)

Register an extension class at run time.

The class gets the extName and extType attributes.

Parameters:
  • ext_name – Extension category, like gws.ext.object.layer.

  • obj_type – Extension type, like wms.

  • cls – Class to register.

Raises:

gws.spec.core.Error – If the class reference is invalid.

gws.spec.runtime.ReadError