From f9519e0f127ff90326b075f45d5a24624e9f3700 Mon Sep 17 00:00:00 2001 From: Frederik Hennig <frederik.hennig@fau.de> Date: Mon, 10 Feb 2025 13:59:45 +0100 Subject: [PATCH] add doc comment to sfg.namespace --- docs/source/conf.py | 2 +- docs/source/usage/generator_scripts.md | 1 - src/pystencilssfg/composer/basic_composer.py | 33 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index da6f4d7..d6aab17 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -59,7 +59,7 @@ intersphinx_mapping = { "python": ("https://docs.python.org/3.8", None), "numpy": ("https://numpy.org/doc/stable/", None), "sympy": ("https://docs.sympy.org/latest/", None), - "pystencils": ("https://da15siwa.pages.i10git.cs.fau.de/dev-docs/pystencils-nbackend/", None), + "pystencils": ("https://pycodegen.pages.i10git.cs.fau.de/docs/pystencils/2.0dev/", None), } # References diff --git a/docs/source/usage/generator_scripts.md b/docs/source/usage/generator_scripts.md index 4a1f6aa..3141fee 100644 --- a/docs/source/usage/generator_scripts.md +++ b/docs/source/usage/generator_scripts.md @@ -64,7 +64,6 @@ Structure and Verbatim Code: SfgBasicComposer.include SfgBasicComposer.namespace SfgBasicComposer.code - SfgBasicComposer.define_once ``` Kernels and Kernel Namespaces: diff --git a/src/pystencilssfg/composer/basic_composer.py b/src/pystencilssfg/composer/basic_composer.py index 7c08b67..e75f0e2 100644 --- a/src/pystencilssfg/composer/basic_composer.py +++ b/src/pystencilssfg/composer/basic_composer.py @@ -204,6 +204,39 @@ class SfgBasicComposer(SfgIComposer): self.code(*definitions) def namespace(self, namespace: str): + """Enter a new namespace block. + + Calling `namespace` as a regular function will open a new namespace as a child of the + currently active namespace; this new namespace will then become active instead. + Using `namespace` as a context manager will instead activate the given namespace + only for the length of the ``with`` block. + + Args: + namespace: Qualified name of the namespace + + :Example: + + The following calls will set the current namespace to ``outer::inner`` + for the remaining code generation run: + + .. code-block:: + + sfg.namespace("outer") + sfg.namespace("inner") + + Subsequent calls to `namespace` can only create further nested namespaces. + + To step back out of a namespace, `namespace` can also be used as a context manager: + + .. code-block:: + + with sfg.namespace("detail"): + ... + + This way, code generated inside the ``with`` region is placed in the ``detail`` namespace, + and code after this block will again live in the enclosing namespace. + + """ return self._cursor.enter_namespace(namespace) def generate(self, generator: CustomGenerator): -- GitLab