-
-
Notifications
You must be signed in to change notification settings - Fork 532
DOC: Add interactive notebooks to pages in the "Usage Examples" section #741
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
rgommers
merged 74 commits into
PyWavelets:main
from
agriyakhetarpal:make-usage-examples-section-interactive
Jan 28, 2025
Merged
Changes from 71 commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
50bd61c
DEP: Add MyST-NB as a docs dependency
agriyakhetarpal 2b68c2e
DOC: Remove all reST files for Usage Examples
agriyakhetarpal bf5389c
DOC: Add configuration values for MyST content
agriyakhetarpal d46e304
DOC: Use Jupytext for usage examples (DWT-IDWT)
agriyakhetarpal 3432906
DOC: Use Jupytext for usage examples (extras)
agriyakhetarpal 5e42538
DOC: Use Jupytext for usage examples (Multilevel Wavelet Transforms)
agriyakhetarpal ef57274
DOC: Use Jupytext for usage examples (Signal Extension Modes)
agriyakhetarpal 112e846
DOC: Use Jupytext for usage examples (Wavelet object)
agriyakhetarpal 0db1ac5
DOC: Use Jupytext for usage examples (Wavelet Packets)
agriyakhetarpal b3a1904
DOC: Use Jupytext for usage examples (Wavelet Packets 2D)
agriyakhetarpal 0b9817c
MAINT: Ignore Jupyter Notebook execution cache folder
agriyakhetarpal 888540e
DOC: Add `NotebookLite` directive to all notebooks
agriyakhetarpal 4aef679
DEP: Add Jupytext CLI to dependencies
agriyakhetarpal 2dad68f
DOC: Custom Sphinx extension to invoke Jupytext
agriyakhetarpal aff50c8
MAINT: Ignore auto-generated notebooks
agriyakhetarpal 8033905
STY, DOC: Fix issues from `prettier` and linters
agriyakhetarpal f066013
DOC, DEP: Add and configure `sphinx-design`
agriyakhetarpal 61ac9cc
DOC: Enable downloads, add dropdown (Signal Extension Modes)
agriyakhetarpal 7b243fb
DOC: Enable downloads, add dropdown (DWT-IDWT)
agriyakhetarpal e75294c
DOC: Enable downloads, add dropdown (Wavelet Packets 2D)
agriyakhetarpal e9cd5de
DOC: Enable downloads, add dropdown (Wavelet Packets)
agriyakhetarpal 14648a9
DOC: Enable downloads, add dropdown (Wavelet object)
agriyakhetarpal 152c380
DOC: Enable downloads, add dropdown (Multilevel Wavelet Transforms)
agriyakhetarpal 685b5dd
DOC: Enable downloads, add dropdown (Gotchas)
agriyakhetarpal b3c85f7
DOC: Silence JupyterLite
agriyakhetarpal 4bd6487
DOC: Normalise initial Markdown cell, add tags
agriyakhetarpal f2c613e
DEP: Add `nbformat` as a dependency
agriyakhetarpal 295020e
DOC: Clean up Markdown notebooks at build time
agriyakhetarpal 2feb9a9
DOC: Disable frozen module debugging warnings
agriyakhetarpal 6b4d0e8
API: Remove unneeded `__future__` imports
agriyakhetarpal f0439b9
DOC: Clean up unneeded type conversions
agriyakhetarpal 2e321dc
DOC: Fix sync for notebook conversion + cleanup
agriyakhetarpal 9bd9e9e
STY: Fix deprecated Ruff configuration
agriyakhetarpal 962aaf0
DOC: Use the `jupytext` API instead of its CLI
agriyakhetarpal 4e3ecd2
DOC: Revise `preprocess_notebooks()` for conversion
agriyakhetarpal 7a9bdb5
DOC: change `pygment` ➡️ `pygments`
agriyakhetarpal 6865650
DOC: Add `strip_tagged_cells = True` confval
agriyakhetarpal 269dddd
DOC: Add `"jupyterlite_sphinx_strip"` to notebooks
agriyakhetarpal 25c2f38
DOC, DEP: Bump `jupyterlite-sphinx` to `>=0.16.1`
agriyakhetarpal c28c8a6
DOC: Silence JupyterLite
agriyakhetarpal 1b93651
DOC, DEP: Bump `jupyterlite-sphinx` to `>=0.16.2`
agriyakhetarpal b121320
STY: Fix style errors
agriyakhetarpal bcdc025
DOC: Remove redundant options from MyST-NB
agriyakhetarpal 5149a65
STY: Fix style errors
agriyakhetarpal b3cdd4c
DOC: Replace references to the API with standard code text
agriyakhetarpal 2964686
Try to fix deprecation warning at doctest import
agriyakhetarpal 114894e
Provide JupyterLite and download links via include file
gabalafou 3f44dba
restyle notebook cells
gabalafou 60f8843
mock and hide outputs, update styles
gabalafou 07f381f
exclude cells tagged jupyterlite_sphinx_strip from md to ipynb conver…
gabalafou abcc8e5
Use better CSS selectors
gabalafou 69f082a
Add README file to regression folder
gabalafou 7a79a0c
Update regression/index.rst
gabalafou e1d6b50
Fail docs build if cell throws but does not have raises-exception tag
gabalafou 38e24d6
improve notebook doc page header
gabalafou 1630eba
formatting
gabalafou 4c663d1
follow Melissa's style
gabalafou 76d5544
fix dark mode
gabalafou fb0d107
Bump jupyterlite-sphinx to 0.17.1 to use notebooklite
gabalafou 45f8023
suggestions from code review
gabalafou 49df46d
Make the output left aligned with the input
gabalafou 1b0ddfd
Improve CSS
gabalafou 3402f88
Match font weight to captioned code block (plus bottom border)
gabalafou e6970f3
oops, put the border in the right place
gabalafou a8f287c
Merge pull request #4 from gabalafou/notebook-header-directive
agriyakhetarpal be2b72a
Bump and pin to `jupyterlite-pyodide-kernel` 0.5.1
agriyakhetarpal 466f241
Bump to `jupyterlite-sphinx` >=0.18.0
agriyakhetarpal 7353a09
Fix Prettier/pre-commit error
agriyakhetarpal d2b6019
Fix deprecations tests failures
agriyakhetarpal 78c3475
Fix Prettier lint again
agriyakhetarpal 410a3e3
Oops, drop deprecation warnings tests
agriyakhetarpal 19ea9ff
link to and partially copy regression/README into the index file (#5)
gabalafou 7580c42
Merge branch 'main' into make-usage-examples-section-interactive
agriyakhetarpal 1463121
Fix style checks
agriyakhetarpal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* MyST-NB | ||
|
|
||
| This stylesheet targets elements output by MyST-NB that represent notebook | ||
| cells. | ||
|
|
||
| In some cases these rules override MyST-NB. In some cases they override PyData | ||
| Sphinx Theme or Sphinx. And in some cases they do not override existing styling | ||
| but add new styling. */ | ||
|
|
||
| /* Set up a few variables for this stylesheet */ | ||
| .cell, | ||
| .pywt-handcoded-cell-output { | ||
| --pywt-cell-input-border-left-width: .2rem; | ||
|
|
||
| /* This matches the padding applied to <pre> elements by PyData Sphinx Theme */ | ||
| --pywt-code-block-padding: 1rem; | ||
|
|
||
| /* override mystnb */ | ||
| --mystnb-source-border-radius: .25rem; /* match PyData Sphinx Theme */ | ||
| } | ||
|
|
||
| .cell .cell_input::before { | ||
| content: "In"; | ||
| border-bottom: var(--mystnb-source-border-width) solid var(--pst-color-border); | ||
| font-weight: var(--pst-font-weight-caption); | ||
|
|
||
| /* Left-aligns the text in this box and the one that follows it */ | ||
| padding-left: var(--pywt-code-block-padding); | ||
| } | ||
|
|
||
| /* Cannot use `.cell .cell_input` selector because the stylesheet from MyST-NB | ||
| uses `div.cell div.cell_input` and we want to override those rules */ | ||
| div.cell div.cell_input { | ||
| background-color: inherit; | ||
| border-color: var(--pst-color-border); | ||
| border-left-width: var(--pywt-cell-input-border-left-width); | ||
| background-clip: padding-box; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| .cell .cell_output, | ||
| .pywt-handcoded-cell-output { | ||
| border: var(--mystnb-source-border-width) solid var(--pst-color-surface); | ||
| border-radius: var(--mystnb-source-border-radius); | ||
| background-clip: padding-box; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| .cell .cell_output::before, | ||
| .pywt-handcoded-cell-output::before { | ||
| content: "Out"; | ||
| display: block; | ||
| font-weight: var(--pst-font-weight-caption); | ||
|
|
||
| /* Left-aligns the text in this box and the one that follows it */ | ||
| padding-left: var(--pywt-code-block-padding); | ||
| } | ||
|
|
||
| .cell .cell_output .output { | ||
| background-color: inherit; | ||
| border: none; | ||
| margin-top: 0; | ||
| } | ||
|
|
||
| .cell .cell_output, | ||
| /* must prefix the following selector with `div.` to override Sphinx margin rule on div[class*=highlight-] */ | ||
| div.pywt-handcoded-cell-output { | ||
| /* Left-align the text in the output with the text in the input */ | ||
| margin-left: calc(var(--pywt-cell-input-border-left-width) - var(--mystnb-source-border-width)); | ||
| } | ||
|
|
||
| .cell .cell_output .output, | ||
| .cell .cell_input pre, | ||
| .cell .cell_output pre, | ||
| .pywt-handcoded-cell-output .highlight, | ||
| .pywt-handcoded-cell-output pre { | ||
| border-radius: 0; | ||
| } | ||
|
|
||
| .pywt-handcoded-cell-output pre { | ||
| border: none; /* MyST-NB sets border to none for <pre> tags inside div.cell */ | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,37 @@ | ||
| /* Custom CSS rules for the interactive documentation button */ | ||
|
|
||
| .try_examples_button { | ||
| color: white; | ||
| background-color: #0054a6; | ||
| border: none; | ||
| padding: 5px 10px; | ||
| border-radius: 10px; | ||
| margin-bottom: 5px; | ||
| box-shadow: 0 2px 5px rgba(108,108,108,0.2); | ||
| font-weight: bold; | ||
| font-size: small; | ||
| color: white; | ||
| background-color: #0054a6; | ||
| border: none; | ||
| padding: 5px 10px; | ||
| border-radius: 10px; | ||
| margin-bottom: 5px; | ||
| box-shadow: 0 2px 5px rgba(108,108,108,0.2); | ||
| font-weight: bold; | ||
| font-size: small; | ||
| } | ||
|
|
||
| .try_examples_button:hover { | ||
| background-color: #0066cc; | ||
| transform: scale(1.02); | ||
| box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); | ||
| cursor: pointer; | ||
| background-color: #0066cc; | ||
| transform: scale(1.02); | ||
| box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .try_examples_button_container { | ||
| display: flex; | ||
| justify-content: flex-start; | ||
| gap: 10px; | ||
| margin-bottom: 20px; | ||
| display: flex; | ||
| justify-content: flex-start; | ||
| gap: 10px; | ||
| margin-bottom: 20px; | ||
| } | ||
|
|
||
| /* | ||
| Admonitions on this site are styled with some top margin. This makes sense when | ||
| the admonition appears within the flow of the article. But when it is the very | ||
| first child of an article, its top margin gets added to the article's top | ||
| padding, resulting in too much whitespace. | ||
| */ | ||
| .admonition.pywt-margin-top-0 { | ||
| margin-top: 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Regression folder | ||
|
|
||
| This folder contains various useful examples illustrating how to use and how not | ||
| to use PyWavelets. | ||
|
|
||
| The examples are written in the [MyST markdown notebook | ||
| format](https://myst-nb.readthedocs.io/en/v0.13.2/use/markdown.html). This | ||
| allows each .md file to function simultaneously as documentation that can be fed | ||
| into Sphinx and as a source file that can be converted to the Jupyter notebook | ||
| format (.ipynb), which can then be opened in notebook applications such as | ||
| JupyterLab. For this reason, each example page in this folder includes a header template | ||
| that adds a blurb to the top of each page about how the page can be | ||
| run or downloaded as a Jupyter notebook. | ||
|
|
||
| There a few shortcomings to this approach of generating the code cell outputs in | ||
| the documentation pages at build time rather than hand editing them into the | ||
| document source file. One is that we can no longer compare the generated outputs | ||
| with the expected outputs as we used to do with doctest. Another is that we | ||
| lose some control over how we want the outputs to appear, unless we use a workaround. | ||
|
|
||
| Here is the workaround we created. First we tell MyST-NB to remove the generated | ||
| cell output from the documentation page by adding the `remove-output` tag to the | ||
| `code-cell` directive in the markdown file. Then we hand code the output in a | ||
| `code-block` directive, not to be confused with `code-cell`! The `code-cell` | ||
| directive says "I am notebook code cell input, run me!" The `code-block` | ||
| directive says, "I am just a block of code for documentation purposes, don't run | ||
| me!" To the code block, we add the `.pywt-handcoded-cell-output` class so that | ||
| we can style it to look the same as other cell outputs on the same HTML page. | ||
| Finally, we tag the handcoded output with `jupyterlite_sphinx_strip` so that we | ||
| can exclude it when converting from .md to .ipynb. That way only generated | ||
| output appears in the .ipynb notebook. | ||
|
|
||
| To recap: | ||
|
|
||
| - We use the `remove-output` tag to remove the **generated** code cell output | ||
| during .md to .html conversion (this conversion is done by MyST-NB). | ||
| - We use the `jupyterlite_sphinx_strip` tag to remove the **handcoded** output | ||
| during .md to .ipynb conversion (this conversion is done by Jupytext). | ||
|
|
||
| Example markdown: | ||
|
|
||
| ```{code-cell} | ||
| :tags: [raises-exception, remove-output] | ||
| 1 / 0 | ||
| ``` | ||
|
|
||
| +++ {"tags" ["jupyterlite_sphinx_strip"]} | ||
|
|
||
| ```{code-block} python | ||
| :class: pywt-handcoded-cell-output | ||
| Traceback (most recent call last): | ||
| ... | ||
| ZeroDivisionError: division by zero | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.