diff --git a/src/pystencilssfg/context.py b/src/pystencilssfg/context.py index 968be89c488470ec86257339c5bd804da8c1f463..5dcf35e5b76d82f6e54928bd23dde3b0485cec5c 100644 --- a/src/pystencilssfg/context.py +++ b/src/pystencilssfg/context.py @@ -1,4 +1,4 @@ -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`.""" diff --git a/src/pystencilssfg/generator.py b/src/pystencilssfg/generator.py index afd79d9ed86dce515326fbc97c3a7ad8c3a2ced2..9e5f0fbbdb9a32d5e76818dddf30c81f46821464 100644 --- a/src/pystencilssfg/generator.py +++ b/src/pystencilssfg/generator.py @@ -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