diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 539ad48f9..84d191d61 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -28,7 +28,7 @@ concurrency: env: PYTHON_VERSION: "3.11" MPLBACKEND: Agg - PLOTLY_RENDERER: json + PLOTLY_RENDERER: notebook_connected jobs: build: @@ -72,14 +72,14 @@ jobs: path: docs/notebooks/**/*.ipynb key: notebooks-${{ steps.notebook-cache-key.outputs.hash }} - - name: Execute notebooks in parallel + - name: Execute fast notebooks if: steps.notebook-cache.outputs.cache-hit != 'true' run: | set -eo pipefail - # Execute all notebooks in parallel (4 at a time) - # Run from notebooks directory so relative imports work - cd docs/notebooks && find . -name '*.ipynb' -print0 | \ - xargs -0 -P 4 -I {} sh -c 'jupyter execute --inplace "$1" || exit 255' _ {} + # Execute fast notebooks in parallel (4 at a time), excluding slow ones + cd docs/notebooks && find . -name '*.ipynb' | \ + grep -vFf slow_notebooks.txt | \ + xargs -P 4 -I {} sh -c 'jupyter execute --inplace "$1" || exit 255' _ {} - name: Build docs env: @@ -136,12 +136,22 @@ jobs: path: docs/notebooks/**/*.ipynb key: notebooks-${{ steps.notebook-cache-key.outputs.hash }} - - name: Execute notebooks in parallel + - name: Execute fast notebooks if: steps.notebook-cache.outputs.cache-hit != 'true' run: | set -eo pipefail - cd docs/notebooks && find . -name '*.ipynb' -print0 | \ - xargs -0 -P 4 -I {} sh -c 'jupyter execute --inplace "$1" || exit 255' _ {} + # Execute fast notebooks in parallel (4 at a time), excluding slow ones + cd docs/notebooks && find . -name '*.ipynb' | \ + grep -vFf slow_notebooks.txt | \ + xargs -P 4 -I {} sh -c 'jupyter execute --inplace "$1" || exit 255' _ {} + + - name: Execute slow notebooks + if: steps.notebook-cache.outputs.cache-hit != 'true' + run: | + set -eo pipefail + # Execute slow notebooks (only on release) + cd docs/notebooks && cat slow_notebooks.txt | \ + xargs -I {} sh -c 'jupyter execute --inplace "$1" || exit 255' _ {} - name: Configure Git run: | diff --git a/docs/notebooks/slow_notebooks.txt b/docs/notebooks/slow_notebooks.txt new file mode 100644 index 000000000..974b4f54b --- /dev/null +++ b/docs/notebooks/slow_notebooks.txt @@ -0,0 +1,2 @@ +08b-rolling-horizon.ipynb +08c2-clustering-storage-modes.ipynb diff --git a/flixopt/config.py b/flixopt/config.py index c0029b609..bae75c5f0 100644 --- a/flixopt/config.py +++ b/flixopt/config.py @@ -818,11 +818,15 @@ def notebook(cls) -> type[CONFIG]: """Configure for Jupyter notebook environments. Optimizes settings for notebook usage: - - Sets plotly renderer to 'notebook' for inline display + - Sets plotly renderer to 'notebook' for inline display (unless PLOTLY_RENDERER env var is set) - Disables automatic plot.show() calls (notebooks display via _repr_html_) - Enables SUCCESS-level console logging - Disables solver console output for cleaner notebook cells + Note: + The plotly renderer can be overridden by setting the PLOTLY_RENDERER + environment variable (e.g., 'notebook_connected' for CDN-based rendering). + Examples: ```python # At the start of your notebook @@ -836,8 +840,9 @@ def notebook(cls) -> type[CONFIG]: """ import plotly.io as pio - # Set plotly to render inline in notebooks - pio.renderers.default = 'notebook' + # Set plotly to render inline in notebooks (respect PLOTLY_RENDERER env var) + if 'PLOTLY_RENDERER' not in os.environ: + pio.renderers.default = 'notebook' pio.templates.default = 'plotly_white' # Disable default show since notebooks render via _repr_html_