Skip to content

Conversation

keewis
Copy link
Contributor

@keewis keewis commented May 8, 2025

As requested by @agriyakhetarpal in pydata/xarray#10299, this is my very simple attempt at supporting a "preamble" feature for try-examples. The main use case is importing modules, setting up a rng with a seed, and other configuration (very similar to pytest autouse fixtures that modify the doctest_namespace).

@keewis keewis marked this pull request as draft May 8, 2025 21:54
@keewis
Copy link
Contributor Author

keewis commented May 10, 2025

(FYI the only reason this is a draft is because I didn't really do any additional work like figuring out whether there should be an option in conf.py, or add documentation. Either way feel free to take over the PR if you'd like.)

@keewis
Copy link
Contributor Author

keewis commented May 21, 2025

@agriyakhetarpal, any chance you might have time to look at this? I believe that's the only thing left before I can merge the xarray PR.

@keewis keewis marked this pull request as ready for review August 24, 2025 19:38
Copy link
Member

@martinRenou martinRenou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not taking the time to review earlier. And thanks for contributing!

I have a small question/suggestion.

Otherwise I believe we should document this as part of this PR

Comment on lines 823 to 829
preamble_path = Path("try_examples_preamble.py")
if preamble_path.is_file():
preamble = preamble_path.read_text()
# or raise an error if `preamble` is empty
if preamble:
# insert after the "experimental" warning
nb.cells.insert(1, new_code_cell(preamble))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be an external file really?

Could we make it an option in the config, passing a string "jupyterlite_sphinx_try_examples_preamble" or something like this?

Copy link
Contributor Author

@keewis keewis Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I remember correctly, the only reason was that that was the first thing I could think of this has somewhat of a precedent in try_examples.json, but I'm not particularly attached to that.

try_examples settings are currently just try_examples_*, so I'll keep that convention.

The most recent commits should contain the requested changes.

@mfisher87 mfisher87 added the enhancement New feature or request label Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants