Skip to content
Snippets Groups Projects
Commit 35127490 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Pass project info through to context

parent 436c77f2
Branches
Tags
No related merge requests found
Pipeline #59491 passed
from typing import Generator, Sequence
from typing import Generator, Sequence, Any
from .configuration import SfgCodeStyle
from .source_components import (
......@@ -48,15 +48,19 @@ class SfgContext:
outer_namespace: str | None = None,
codestyle: SfgCodeStyle = SfgCodeStyle(),
argv: Sequence[str] | None = None,
project_info: Any = None,
):
"""
Args:
outer_namespace: Qualified name of the outer code namespace
codestyle: Code style that should be used by the code emitter
argv: The generator script's command line arguments;
reserved for internal use by the [SourceFileGenerator][pystencilssfg.SourceFileGenerator].
argv: The generator script's command line arguments.
Reserved for internal use by the [SourceFileGenerator][pystencilssfg.SourceFileGenerator].
project_info: Project-specific information provided by a build system.
Reserved for internal use by the [SourceFileGenerator][pystencilssfg.SourceFileGenerator].
"""
self._argv = argv
self._project_info = project_info
self._default_kernel_namespace = SfgKernelNamespace(self, "kernels")
self._outer_namespace = outer_namespace
......@@ -91,6 +95,11 @@ class SfgContext:
raise SfgException("This context provides no command-line arguments.")
return self._argv
@property
def project_info(self) -> Any:
"""Project-specific information provided by a build system."""
return self._project_info
@property
def outer_namespace(self) -> str | None:
"""Outer code namespace. Set by constructor argument `outer_namespace`."""
......
......@@ -14,8 +14,7 @@ from .context import SfgContext
class SourceFileGenerator:
"""Context manager that controls the code generation process in generator scripts.
"""
"""Context manager that controls the code generation process in generator scripts."""
def __init__(self, sfg_config: SfgConfiguration | None = None):
if sfg_config and not isinstance(sfg_config, SfgConfiguration):
......@@ -31,8 +30,13 @@ class SourceFileGenerator:
config = merge_configurations(project_config, cmdline_config, sfg_config)
assert config.codestyle is not None
self._context = SfgContext(
config.outer_namespace, config.codestyle, argv=script_args
config.outer_namespace,
config.codestyle,
argv=script_args,
project_info=config.project_info,
)
from .emission import HeaderImplPairEmitter
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment