gws.spec.generator¶
Spec generator: creates the specs from the Python sources.
The generator collects the source files of the application and its plugins,
parses the Python sources into Type records, normalizes them and extracts
the types the server needs. It also generates the TypeScript API for the
client, collects the documentation strings and renders the configuration
references.
Modules:
main: entry points (generate,generate_and_write) and JSON storage of the specs (to_path,from_path). Sets up the chunks and runs the pipeline.base: theGeneratorstate object shared by all steps, a simpleDataclass and the generator logger.manifest: readsMANIFEST.jsonfiles.parser: parses Python modules withastand creates types for classes, enums, properties, type aliases, constants,gws.extdeclarations and command methods.normalizer: resolves aliases, evaluates default expressions, synthesizes variant types andtypeproperties forgws.extclasses and collects the inherited properties of classes.extractor: selects the server types, starting from the applicationConfig, the applicationObjectand allgws.exttypes.typescript: generates the TypeScript API (gws.generated.ts) for the client from the request, response and props classes and the API commands.strings: collects documentation strings from docstrings andstrings.inifiles.configref: renders the configuration reference in Markdown, in English and German.util: file, JSON and ini helpers.
Pipeline¶
main creates a base.Generator and runs the steps in order:
Init: read
VERSIONand the manifest, create chunks for the system packages, the built-in plugins and the manifest plugins, and assign the source files of each chunk to file kinds.parser.parse: add a type for each spec’able source construct toGenerator.typeDict; imports become entries inGenerator.aliases.normalizer.normalize: resolve the aliases and finish the types.extractor.extract: fillGenerator.serverTypes.typescript.create,strings.collectandconfigref.create.
With debug, the generator state is dumped as JSON after each step.
generate_and_write writes specs.json, gws.generated.ts,
configref.en.md and configref.de.md to the output directory.
Example:
import gws.spec.generator.main as generator_main
specs = generator_main.generate(manifest_path='/data/MANIFEST.json')
generator_main.to_path('/tmp/specs.json', specs)
generator_main.generate_and_write(out_dir='/tmp/specs', manifest_path='/data/MANIFEST.json')
Source code: gws.spec.generator