Skip to content

Commit fee274a

Browse files
committed
docs: extend with jupytext approach
1 parent ea6293b commit fee274a

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

doc/source/how-to/documenting.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,9 @@ Two best practices for examples are:
933933
- **Verifying the example**: Ensures that the example works as expected and helps catch
934934
errors before submission. The verification process should involve running the example
935935
and checking the output. If the example fails, it should be easy to identify and fix the issue.
936+
- **Making the example usable in multiple contexts**: Ensures that the example can be
937+
usable by a user reading the documentation, an application engineer using the library
938+
through a Notebook, or a developer including the example to the documentation.
936939

937940
Providing a template
938941
~~~~~~~~~~~~~~~~~~~~
@@ -972,3 +975,52 @@ includes a ``make`` target for this purpose:
972975
The pull request introducing this feature is: `PyAnsys Geometry PR #1893 <PyAnsys_geometry_pull_1893_>`_
973976
This implementation is specific to NB Sphinx, but the concept of creating a target to run a specific
974977
example and verify its output can be adapted to other libraries.
978+
979+
Making the example usable in multiple contexts
980+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
981+
982+
A core objective when designing examples is to ensure they can be used seamlessly across multiple
983+
contexts: whether it's by end users exploring them interactively, by documentation tools rendering
984+
them for the web, or by engineers verifying their correctness and updating them. Achieving this
985+
flexibility requires a careful balance between accessibility, structure, and maintainability.
986+
987+
To support this goal, we recommend a workflow where examples are authored and maintained as plain
988+
Python scripts, but using `Jupytext <https://jupytext.readthedocs.io/en/latest/>`_ to treat those
989+
scripts as notebooks when needed. Formatting your examples using the
990+
`light format <https://jupytext.readthedocs.io/en/latest/formats-scripts.html#the-light-format>`_
991+
makes them makes them fully compatible with JupyterLab, where they can be opened, edited, and
992+
executed just like traditional notebooks - all without needing a IPYNB file. Here is an example
993+
of a Jupytext light format script:
994+
995+
.. code-block:: python
996+
997+
# # Dipole antenna
998+
#
999+
# Keywords: **HFSS**, **antenna**, **3D component**, **far field**.
1000+
#
1001+
# ## Prerequisites
1002+
#
1003+
# ### Perform imports
1004+
#
1005+
# Import the packages required to run this example.
1006+
1007+
# +
1008+
import os
1009+
import tempfile
1010+
import time
1011+
1012+
from ansys.aedt.core import Hfss
1013+
1014+
# -
1015+
1016+
# ### Define constants
1017+
# Constants help ensure consistency and avoid repetition throughout the example.
1018+
1019+
AEDT_VERSION = "2025.1"
1020+
NUM_CORES = 4
1021+
NG_MODE = False # Open AEDT UI when it is launched.
1022+
1023+
Here are examples of PyAnsys projects using this approach:
1024+
1025+
- `PyAEDT examples repository <PyAEDT-examples_>`_
1026+
- `PySpeos repository <PySpeos_>`_

doc/source/links.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
.. _grpc_hello_world: https://github.com/ansys/pyansys-helloworld
5151
.. _Links_for_pymapdl: https://github.com/ansys/pymapdl/blob/main/doc/source/links.rst
5252
.. _PyAEDT: https://github.com/ansys/pyaedt
53+
.. _PyAEDT-examples: https://github.com/ansys/pyaedt-examples
5354
.. _PyAnsys_geometry_Docker_containers: https://geometry.docs.pyansys.com/version/stable/getting_started/docker/index.html
5455
.. _PyAnsys_geometry_examples_template: https://geometry.docs.pyansys.com/version/stable/examples/99_misc/template.html
5556
.. _PyAnsys_geometry_examples_contribution: https://geometry.docs.pyansys.com/version/stable/contributing.html#adding-examples
@@ -68,6 +69,7 @@
6869
.. _PyMAPDL Legacy Reader: https://github.com/ansys/pymapdl-reader
6970
.. _PyMechanical: https://github.com/ansys/pymechanical
7071
.. _PyMeilisearch: https://pymeilisearch.docs.ansys.com/
72+
.. _PySpeos:https://github.com/ansys/pyspeos
7173
.. _PyPIM: https://github.com/ansys/pypim
7274
.. _python_installer_qt_ui_releases: https://github.com/ansys/python-installer-qt-gui/releases
7375
.. _review_bot: https://github.com/ansys/review-bot

0 commit comments

Comments
 (0)