Generator Script Interface#
- class pystencilssfg.SourceFileGenerator(sfg_config=None, keep_unknown_argv=False)#
Context manager that controls the code generation process in generator scripts.
The
SourceFileGeneratormust be used as a context manager by calling it within awithstatement in the top-level code of a generator script. Upon entry to its context, it creates anSfgComposerwhich can be used to populate the generated files. When the managed region finishes, the code files are generated and written to disk at the locations defined by the configuration. Existing copies of the target files are deleted on entry to the managed region, and if an exception occurs within the managed region, no files are exported.- Parameters:
sfg_config (
Optional[SfgConfig]) – Inline configuration for the code generatorkeep_unknown_argv (
bool) – IfTrue, any command line arguments given to the generator script that theSourceFileGeneratordoes not understand are stored insfg.context.argv.
Configuration#
- class pystencilssfg.config.SfgConfig(extensions=None, header_only=None, outer_namespace=None, codestyle=None, clang_format=None, output_directory=None)#
Configuration options for the
SourceFileGenerator.- Parameters:
extensions (Category[FileExtensions])
header_only (BasicOption[bool])
outer_namespace (BasicOption[str | _GlobalNamespace])
clang_format (Category[ClangFormatOptions])
-
extensions:
Category[FileExtensions] = None# File extensions of the generated files
- Options in this category:
File extension for generated header file.
File extension for generated implementation file.
-
header_only:
BasicOption[bool] = None# If set to
True, generate only a header file.This will cause all definitions to be generated
inline.
-
outer_namespace:
BasicOption[str|_GlobalNamespace] = None# The outermost namespace in the generated file. May be a valid C++ nested namespace qualifier (like
a::b::c) orGLOBAL_NAMESPACEif no outer namespace should be generated.Indicates the C++ global namespace.
-
codestyle:
Category[CodeStyle] = None# Options affecting the code style emitted by pystencils-sfg.
- Options in this category:
The number of spaces successively nested blocks should be indented with
-
clang_format:
Category[ClangFormatOptions] = None# Options governing the code style used by the code generator
- Options in this category:
Code style to be used by clang-format.
If set to
True, abort code generation ifclang-formatbinary cannot be found.If set to
True, skip formatting usingclang-format.Path to the clang-format executable
Categories, Parameter Types, and Special Values#
- class pystencilssfg.config._GlobalNamespace#
- pystencilssfg.config.GLOBAL_NAMESPACE = <pystencilssfg.config._GlobalNamespace object>#
Indicates the C++ global namespace.
- class pystencilssfg.config.FileExtensions(header=None, impl=None)#
BasicOption category containing output file extensions.
- Parameters:
header (BasicOption[str])
impl (BasicOption[str])
-
header:
BasicOption[str] = None# File extension for generated header file.
-
impl:
BasicOption[str] = None# File extension for generated implementation file.
- class pystencilssfg.config.CodeStyle(indent_width=None, includes_sorting_key=None)#
Options affecting the code style used by the source file generator.
- Parameters:
indent_width (BasicOption[int])
includes_sorting_key (BasicOption[Callable[[HeaderFile], Any]])
-
indent_width:
BasicOption[int] = None# The number of spaces successively nested blocks should be indented with
-
includes_sorting_key:
BasicOption[Callable[[HeaderFile],Any]] = None# Key function that will be used to sort
#includestatements in generated files.Pystencils-sfg will instruct clang-tidy to forego include sorting if this option is set.
- class pystencilssfg.config.ClangFormatOptions(code_style=None, force=None, skip=None, binary=None)#
Options affecting the invocation of
clang-formatfor automatic code formatting.- Parameters:
code_style (BasicOption[str])
force (BasicOption[bool])
skip (BasicOption[bool])
binary (BasicOption[str])
-
code_style:
BasicOption[str] = None# Code style to be used by clang-format. Passed verbatim to
--styleargument of the clang-format CLI.Similar to clang-format itself, the default value is
file, such that a.clang-formatfile found in the build tree will automatically be used.
-
force:
BasicOption[bool] = None# If set to
True, abort code generation ifclang-formatbinary cannot be found.
-
skip:
BasicOption[bool] = None# If set to
True, skip formatting usingclang-format.
-
binary:
BasicOption[str] = None# Path to the clang-format executable