ifgen.generation package — docs

Skip to main content
`Ctrl`+`K`

# ifgen.generation package

## Subpackages

- ifgen.generation.python package
  - Module contents
    - `python_class()`
    - `python_docstring()`
    - `python_function()`
    - `python_imports()`
    - `write_imports()`

## Submodules

## ifgen.generation.interface module

A module defining generator interfaces.

class ifgen.generation.interface.GenerateTask(name: str, generator: Generator, language: Language, path: Path, test_path: Path, instance: dict[str, Any], env: IfgenEnvironment)

  Bases: `NamedTuple`

  A container for instance-generation tasks.

  boilerplate(includes: Iterable[str] = None, is_test: bool = False, use_namespace: bool = True, description: str | None = None, json: bool = False, parent_depth: int = 0) → Iterator[IndentedFileWriter]

    Create standard generation boilerplate and yield the file writer to use for writing the remaining content.

  check_custom_type(name: str) → TypeLookup | None

    Check if a name refers to a custom type.

  command(command: str, data: str = '', space: str = ' ') → str

    Get a doxygen command string.

  property config: dict[str, Any]

    Get the environment’s configuration data.

  cpp_namespace(data: str, header: bool = True, prefix: str = None) → str

    Namespace a string with this task’s name.

  custom_include(name: str) → Path | None

    Attempt to build a path to a custom include.

  enum() → RuntimeEnum

    Look up a runtime enumeration for this task.

  env: IfgenEnvironment

    Alias for field number 6

  generator: Generator

    Alias for field number 1

  handle_namespace(stack: ExitStack, writer: IndentedFileWriter) → None

    Write namespace boilerplate to a file.

  has_instances() → bool

    Determine whether or not this instance has concrete instances.

  instance: dict[str, Any]

    Alias for field number 5

  property is_cpp: bool

    Determine if this task’s language is set to C++.

  property is_python: bool

    Determine if this task’s language is set to Python.

  javadoc_header(writer: IndentedFileWriter, json: bool = False) → None

    Write a standard file header.

  language: Language

    Alias for field number 2

  method_suffix() → str

    Get a possible suffix for a method.

  name: str

    Alias for field number 0

  namespace(*names: str) → str

    Get this task’s namespace.

  path: Path

    Alias for field number 3

  protocol() → Protocol

    Loop up a protocol for this task.

  resolve_description(description: str | None = None) → str | None

    Attempt to resolve a config-driven description.

  source_boilerplate(includes: Iterable[str]) → Iterator[IndentedFileWriter]

    Create standard generation boilerplate for a source file.

  property source_path: Path

    Get a source file for this task.

  property stream_implementation: bool

    Determine if this instances should include a stream implementations.

  test_path: Path

    Alias for field number 4

  write_includes(writer: IndentedFileWriter, includes: Iterable[str] = None) → None

    Write sorted includes to a file.

class ifgen.generation.interface.TypeLookup(name: str, final: str, generator: Generator)

  Bases: `NamedTuple`

  A container for type-lookup results.

  final: str

    Alias for field number 1

  generator: Generator

    Alias for field number 2

  name: str

    Alias for field number 0

ifgen.generation.interface.apply_cpp_namespace(name: str, data: str, header: bool = True, prefix: str = None) → str

  Namespace a string with this task’s name.

ifgen.generation.interface.ifndef_guard(writer: IndentedFileWriter, text: str) → Iterator[None]

  Guard contents with header macro convention.

## ifgen.generation.json module

A module for generating methods that store JSON strings.

ifgen.generation.json.to_json_method(task: GenerateTask, writer: IndentedFileWriter, data: dict[str, Any], task_name: bool = True, static: bool = False, dumps_indent: int = None, definition: bool = False, inline: bool = False) → None

  Create a _json() method for a given task.

## ifgen.generation.test module

A module implementing unit-testing related generation utilities.

ifgen.generation.test.unit_test_boilerplate(task: GenerateTask, includes: list[str] = None, main: bool = True, declare_namespace: bool = False) → Iterator[IndentedFileWriter]

  Handle standard unit-test boilerplate.

ifgen.generation.test.unit_test_main(task: GenerateTask, writer: IndentedFileWriter, description: bool = True) → Iterator[None]

  A method for generating main-function boilerplate for unit tests.

ifgen.generation.test.unit_test_method(name: str, task: GenerateTask, writer: IndentedFileWriter) → Iterator[None]

  Generate unit-test method boilerplate.

ifgen.generation.test.unit_test_method_name(name: str, task: GenerateTask) → str

  Get the name of a unit test.

## Module contents

A module implementing interfaces to facilitate code generation.

ifgen.generation.generate(root: Path, config: Config) → None

  Generate struct files.

ifgen.generation.resolve_generators(env: IfgenEnvironment) → dict[Generator, list[Callable[[GenerateTask], None]]]

  Populate any custom generator interfaces defined in the configuration.