Skip to content

docs: add example assets button #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 27, 2025
1 change: 1 addition & 0 deletions doc/changelog.d/518.documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add example assets button
3 changes: 3 additions & 0 deletions doc/source/_static/assets/download/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!README.md
1 change: 1 addition & 0 deletions doc/source/_static/assets/download/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Downloadable assets are stored here.
44 changes: 40 additions & 4 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
LaTeXBuilder.supported_image_types = ["image/png", "image/pdf", "image/svg+xml"]
os.environ["DOCUMENTATION_BUILDING"] = "true"

logger = logging.getLogger(__name__)

# Project information
project = "ansys-speos-core"
copyright = f"(c) {datetime.now().year} ANSYS, Inc. All rights reserved"
Expand Down Expand Up @@ -50,7 +52,6 @@
"pages": ["index"],
}


# Sphinx extensions
extensions = [
"numpydoc",
Expand Down Expand Up @@ -138,8 +139,9 @@
nbsphinx_prompt_width = ""
nbsphinx_prolog = """

.. grid:: 3
:gutter: 1
.. grid:: 5

.. grid-item::

.. grid-item::
:child-align: center
Expand All @@ -159,12 +161,24 @@

Download as Jupyter notebook :fas:`book`

.. grid-item::
:child-align: center

.. button-link:: {cname_pref}/{assets_loc}
:color: primary
:shadow:

Download example's assets :fa:`file`

.. grid-item::

----

""".format(
cname_pref=f"https://{cname}/version/{get_version_match(version)}",
python_file_loc="{{ env.docname }}.py",
ipynb_file_loc="{{ env.docname }}.ipynb",
assets_loc="_static/assets/download/",
)


Expand Down Expand Up @@ -261,6 +275,28 @@ def copy_examples_files_to_source_dir(app: sphinx.application.Sphinx):
destination_file.write_text(file.read_text(encoding="utf-8"), encoding="utf-8")


def copy_assets_to_output_dir(app: sphinx.application.Sphinx, exception: Exception):
"""Copy the assets directory to the output directory of the documentation.

Parameters
----------
app : sphinx.application.Sphinx
Sphinx application instance containing the all the doc build configuration.
exception : Exception
Exception encountered during the building of the documentation.
"""
if app.builder.name == "html":
SOURCE_ASSETS = pathlib.Path(app.outdir) / "_static" / "assets" / "download"
ASSETS_DIRECTORY = pathlib.Path(app.outdir).parent.parent.parent / "tests" / "assets"

logger.info("Extracting assets to output directory...")
zip_path = pathlib.Path(shutil.make_archive("assets", "zip", ASSETS_DIRECTORY))
zip_path = shutil.move(zip_path, SOURCE_ASSETS / zip_path.name)
logger.info(f"Extracted assets to {zip_path}.")
else:
logger.info(f"Skip assets extraction with build {app.builder.name}.")


def remove_examples_from_source_dir(app: sphinx.application.Sphinx, exception: Exception):
"""
Remove the example files from the documentation source directory.
Expand All @@ -274,7 +310,6 @@ def remove_examples_from_source_dir(app: sphinx.application.Sphinx, exception: E

"""
EXAMPLES_DIRECTORY = pathlib.Path(app.srcdir) / "examples"
logger = logging.getLogger(__name__)
logger.info(f"\nRemoving {EXAMPLES_DIRECTORY} directory...")
shutil.rmtree(EXAMPLES_DIRECTORY)

Expand All @@ -297,4 +332,5 @@ def setup(app: sphinx.application.Sphinx):
if BUILD_EXAMPLES:
app.connect("builder-inited", copy_examples_files_to_source_dir)
app.connect("build-finished", remove_examples_from_source_dir)
app.connect("build-finished", copy_assets_to_output_dir)
app.connect("build-finished", copy_examples_to_output_dir)
2 changes: 2 additions & 0 deletions examples/core/lpf-preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
tests_data_path = Path("/app") / "assets"
# If using local server
# tests_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# tests_data_path = Path("path/to/downloaded/example/assets")
# -

# ## Create connection with speos rpc server
Expand Down
2 changes: 2 additions & 0 deletions examples/core/opt-prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
tests_data_path = Path("/app") / "assets"
# If using local server
# tests_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# tests_data_path = Path("path/to/downloaded/example/assets")
# -

# ## Create connection with speos rpc server
Expand Down
2 changes: 2 additions & 0 deletions examples/core/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
tests_data_path = Path("/app") / "assets"
# If using local server
# tests_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# tests_data_path = Path("path/to/downloaded/example/assets")
# -

# ## Create connection with speos rpc server
Expand Down
2 changes: 2 additions & 0 deletions examples/core/prism-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
tests_data_path = Path("/app") / "assets"
# If using local server
# tests_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# tests_data_path = Path("path/to/downloaded/example/assets")
# -

# ## Create connection with speos rpc server
Expand Down
2 changes: 2 additions & 0 deletions examples/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
tests_data_path = Path("/app") / "assets"
# If using local server
# tests_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# tests_data_path = Path("path/to/downloaded/example/assets")
# -

# ## Create connection with speos rpc server
Expand Down
2 changes: 2 additions & 0 deletions examples/core/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
tests_data_path = Path("/app") / "assets"
# If using local server
# tests_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# tests_data_path = Path("path/to/downloaded/example/assets")
# -

# ## Create connection with speos rpc server
Expand Down
2 changes: 2 additions & 0 deletions examples/core/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
tests_data_path = Path("/app") / "assets"
# If using local server
# tests_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# tests_data_path = Path("path/to/downloaded/example/assets")
# -

# ## Create connection with speos rpc server
Expand Down
2 changes: 2 additions & 0 deletions examples/core/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
tests_data_path = Path("/app") / "assets"
# If using local server
# tests_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# tests_data_path = Path("path/to/downloaded/example/assets")
# -

# ## Create connection with speos rpc server
Expand Down
2 changes: 2 additions & 0 deletions examples/kernel/modify-scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
tests_data_path = Path("/app") / "assets"
# If using local server
# tests_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# tests_data_path = Path("path/to/downloaded/example/assets")
# -

# Create connection with speos rpc server
Expand Down
2 changes: 2 additions & 0 deletions examples/kernel/scene-job.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
tests_data_path = Path("/app") / "assets"
# If using local server
# tests_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# tests_data_path = Path("path/to/downloaded/example/assets")
# -

# Create connection with speos rpc server
Expand Down
2 changes: 2 additions & 0 deletions examples/workflow/combine-speos.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
tests_data_path = Path("/app") / "assets"
# If using local server
# tests_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# tests_data_path = Path("path/to/downloaded/example/assets")
# -

# ## Create connection with speos rpc server
Expand Down
2 changes: 2 additions & 0 deletions examples/workflow/open-result.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
tests_data_path = Path("/app") / "assets"
# If using local server
# tests_data_path = Path().resolve().parent.parent / "tests" / "assets"
# If using a different path
# tests_data_path = Path("path/to/downloaded/example/assets")
# -

# ## Create connection with speos rpc server
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/speos/core/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ def __init__(

@property
def photometric(self) -> Union[SensorCamera.Photometric, None]:
"""Property containing the instance of Camera.Photometric used to build the sensor.
"""Property containing the instance of SensorCamera.Photometric used to build the sensor.

Returns
-------
Expand Down