From 71eb8420ff712dd91ba303277a50f139b5bfd42a Mon Sep 17 00:00:00 2001 From: "Patrick J. Roddy" Date: Wed, 15 Jan 2025 13:27:30 +0000 Subject: [PATCH] Fix examples --- examples/run.py | 37 +++++++++++++++++++++++++++++++++++++ pyproject.toml | 6 +++--- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 examples/run.py diff --git a/examples/run.py b/examples/run.py new file mode 100644 index 00000000..b2a5a298 --- /dev/null +++ b/examples/run.py @@ -0,0 +1,37 @@ +"""_summary_.""" + +import pathlib +import subprocess +import sys + + +def main() -> None: + """_summary_.""" + if len(sys.argv) > 1 and "html" in sys.argv[1:]: + print("Generating HTML for the example notebooks") + subprocess.run( # noqa: S603 + [ # noqa: S607 + "jupyter", + "nbconvert", + "--to", + "html", + "--embed-images", + "examples/**/*.ipynb", + ], + check=False, + ) + else: + notebooks = [str(p) for p in pathlib.Path().glob("examples/**/*.ipynb")] + subprocess.run( # noqa: S603 + [ # noqa: S607 + "jupyter", + "execute", + "--inplace", + *notebooks, + ], + check=False, + ) + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml index 684f9efc..bb3a3da7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -160,6 +160,7 @@ lint.per-file-ignores = {"__init__.py" = [ "D100", # undocumented-public-module "INP001", # implicit-namespace-package, ], "examples*" = [ + "INP001", # implicit-namespace-package "PLR2004", # magic-value-comparison "T201", # print ], "glass*" = [ @@ -224,9 +225,8 @@ legacy_tox_ini = """ [testenv:examples] extras = examples - commands = - !html: jupyter execute --inplace examples/**/*.ipynb {posargs} - html: jupyter nbconvert --to html --embed-images examples/**/*.ipynb + commands = python examples/run.py {posargs} + description = Run the example notebooks. Pass "html" to build html. [testenv:docs] extras = docs