generator

The generator module contains the code generation logic.

The core of this work is around the Generator class, which divides up the processing of individual templates.

class gapic.generator.generator.Generator(opts: gapic.generator.options.Options)[source]

A protoc code generator for client libraries.

This class provides an interface for getting a CodeGeneratorResponse for an API schema object (which it does through rendering templates).

Parameters:
  • opts (Options) – An options instance.
  • templates (str) – Optional. Path to the templates to be rendered. If this is not provided, the templates included with this application are used.
get_response(api_schema: gapic.schema.api.API, opts: gapic.generator.options.Options) → google.protobuf.compiler.plugin_pb2.CodeGeneratorResponse[source]

Return a CodeGeneratorResponse for this library.

This is a complete response to be written to (usually) stdout, and thus read by protoc.

Parameters:
  • api_schema (API) – An API schema object.
  • opts (Options) – An options instance.
Returns:

A response describing appropriate files and contents. See plugin.proto.

Return type:

CodeGeneratorResponse

class gapic.generator.options.Options(name: str = '', namespace: Tuple[str, ...] = (), retry: Optional[Dict[str, Any]] = None, sample_configs: Tuple[str, ...] = (), templates: Tuple[str, ...] = ('DEFAULT', ), lazy_import: bool = False, old_naming: bool = False, PYTHON_GAPIC_PREFIX: str = 'python-gapic-', OPT_FLAGS: FrozenSet[str] = frozenset({'old-naming', 'lazy-import', 'retry-config', 'samples'}))[source]

A representation of CLI options passed through protoc.

To maximize interoperability with other languages, we are permissive on unrecognized arguments (essentially, we throw them away, but we do warn if it looks like it was meant for us).

classmethod build(opt_string: str) → gapic.generator.options.Options[source]

Build an Options instance based on a protoc opt string.

Parameters:opt_string (str) – A string, as passed from the protoc interface (through --python_gapic_opt). If multiple options are passed, then protoc joins the values with ,. By convention, we use key=value strings for such options, with an absent value defaulting to True.
Returns:The Options instance.
Return type:Options
Raises:gapic.samplegen_utils.types.InvalidConfig – If paths to files or directories that should contain sample configs are passed and no valid sample config is found.