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

minor fixes to documentation and clang-format integration

parent af0e3408
No related branches found
No related tags found
No related merge requests found
Pipeline #58403 passed
...@@ -18,19 +18,18 @@ The code generation process in a generator script is controlled by the ...@@ -18,19 +18,18 @@ The code generation process in a generator script is controlled by the
It configures the code generator by combining configuration options from the It configures the code generator by combining configuration options from the
environment (e.g. a CMake build system) with options specified in the script, environment (e.g. a CMake build system) with options specified in the script,
and infers the names of the output files from the script's name. and infers the names of the output files from the script's name.
It then prepares a code generation [context][pystencilssfg.SfgContext] and a It then prepares and returns a code generation [context][pystencilssfg.SfgContext].
[composer][pystencilssfg.SfgComposer]. This context may then be passed to a [composer][pystencilssfg.SfgComposer],
The latter is returned when entering the context manager, and provides a convenient which provides a convenient interface for constructing the source files.
interface to constructing the source files.
To start, place the following code in a Python script, e.g. `kernels.py`: To start, place the following code in a Python script, e.g. `kernels.py`:
```Python ```Python
from pystencilssfg import SourceFileGenerator, SfgConfiguration from pystencilssfg import SourceFileGenerator, SfgConfiguration, SfgComposer
sfg_config = SfgConfiguration() sfg_config = SfgConfiguration()
with SourceFileGenerator(sfg_config) as sfg: with SourceFileGenerator(sfg_config) as ctx:
pass sfg = SfgComposer(ctx)
``` ```
...@@ -56,9 +55,11 @@ A few notes on configuration: ...@@ -56,9 +55,11 @@ A few notes on configuration:
## Using the Composer ## Using the Composer
The object `sfg` returned by the context manager is an [SfgComposer](pystencilssfg.SfgComposer). The object `sfg` constructed in above snippet is an instance of [SfgComposer][pystencilssfg.SfgComposer].
It is a stateless builder object which provides a convenient interface to construct the source The composer is the central part of the user front-end of *pystencils-sfg*.
file's contents. Here's an overview: It provides an interface for constructing source files that attempts to closely mimic
C++ syntactic structures within Python.
Here is an overview of its various functions:
### Includes and Definitions ### Includes and Definitions
......
...@@ -85,15 +85,6 @@ class SfgCodeStyle: ...@@ -85,15 +85,6 @@ class SfgCodeStyle:
prefix = " " * self.indent_width prefix = " " * self.indent_width
return indent(s, prefix) return indent(s, prefix)
def __post__init__(self):
if self.force_clang_format:
import shutil
if not shutil.which(self.clang_format_binary):
raise SfgException(
"`force_clang_format` set to true in code style, but clang-format binary not found."
)
@dataclass @dataclass
class SfgOutputSpec: class SfgOutputSpec:
......
...@@ -9,7 +9,13 @@ def invoke_clang_format(code: str, codestyle: SfgCodeStyle) -> str: ...@@ -9,7 +9,13 @@ def invoke_clang_format(code: str, codestyle: SfgCodeStyle) -> str:
args = [codestyle.clang_format_binary, f"--style={codestyle.code_style}"] args = [codestyle.clang_format_binary, f"--style={codestyle.code_style}"]
if not shutil.which(codestyle.clang_format_binary): if not shutil.which(codestyle.clang_format_binary):
return code if codestyle.force_clang_format:
raise SfgException(
"`force_clang_format` was set to true in code style, "
"but clang-format binary could not be found."
)
else:
return code
result = subprocess.run(args, input=code, capture_output=True, text=True) result = subprocess.run(args, input=code, capture_output=True, text=True)
......
...@@ -4,7 +4,6 @@ from ..configuration import SfgOutputSpec ...@@ -4,7 +4,6 @@ from ..configuration import SfgOutputSpec
from ..context import SfgContext from ..context import SfgContext
from .prepare import prepare_context from .prepare import prepare_context
from .printers import SfgHeaderPrinter, SfgImplPrinter from .printers import SfgHeaderPrinter, SfgImplPrinter
from .clang_format import invoke_clang_format from .clang_format import invoke_clang_format
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment