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
No related branches found
No related tags found
No related merge requests found
Pipeline #59491 passed
from typing import Generator, Sequence from typing import Generator, Sequence, Any
from .configuration import SfgCodeStyle from .configuration import SfgCodeStyle
from .source_components import ( from .source_components import (
...@@ -48,15 +48,19 @@ class SfgContext: ...@@ -48,15 +48,19 @@ class SfgContext:
outer_namespace: str | None = None, outer_namespace: str | None = None,
codestyle: SfgCodeStyle = SfgCodeStyle(), codestyle: SfgCodeStyle = SfgCodeStyle(),
argv: Sequence[str] | None = None, argv: Sequence[str] | None = None,
project_info: Any = None,
): ):
""" """
Args: Args:
outer_namespace: Qualified name of the outer code namespace outer_namespace: Qualified name of the outer code namespace
codestyle: Code style that should be used by the code emitter codestyle: Code style that should be used by the code emitter
argv: The generator script's command line arguments; argv: The generator script's command line arguments.
reserved for internal use by the [SourceFileGenerator][pystencilssfg.SourceFileGenerator]. 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._argv = argv
self._project_info = project_info
self._default_kernel_namespace = SfgKernelNamespace(self, "kernels") self._default_kernel_namespace = SfgKernelNamespace(self, "kernels")
self._outer_namespace = outer_namespace self._outer_namespace = outer_namespace
...@@ -91,6 +95,11 @@ class SfgContext: ...@@ -91,6 +95,11 @@ class SfgContext:
raise SfgException("This context provides no command-line arguments.") raise SfgException("This context provides no command-line arguments.")
return self._argv return self._argv
@property
def project_info(self) -> Any:
"""Project-specific information provided by a build system."""
return self._project_info
@property @property
def outer_namespace(self) -> str | None: def outer_namespace(self) -> str | None:
"""Outer code namespace. Set by constructor argument `outer_namespace`.""" """Outer code namespace. Set by constructor argument `outer_namespace`."""
......
...@@ -14,8 +14,7 @@ from .context import SfgContext ...@@ -14,8 +14,7 @@ from .context import SfgContext
class SourceFileGenerator: 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): def __init__(self, sfg_config: SfgConfiguration | None = None):
if sfg_config and not isinstance(sfg_config, SfgConfiguration): if sfg_config and not isinstance(sfg_config, SfgConfiguration):
...@@ -31,8 +30,13 @@ class SourceFileGenerator: ...@@ -31,8 +30,13 @@ class SourceFileGenerator:
config = merge_configurations(project_config, cmdline_config, sfg_config) config = merge_configurations(project_config, cmdline_config, sfg_config)
assert config.codestyle is not None
self._context = SfgContext( 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 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