diff --git a/docs/source/conf.py b/docs/source/conf.py index da6f4d729898cb0215658f99bf1ecea2b018edb5..d6aab17bc3f667bbfc923c80c2d1c35b9e08a3d7 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 4a1f6aa7c34ae4667b938d80fc8bd4b595050361..3141feec607c7eff68394288624b67a192d84ad0 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 7c08b6765a8b3ca76839d55aee2c7018e68bb939..e75f0e29e4d41825a8d0d8cf1547bab046c1731a 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):