- 
                Notifications
    
You must be signed in to change notification settings  - Fork 28
 
          allow adding a preamble for try_examples
          #293
        
          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
Conversation
| 
           (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   | 
    
| 
           @agriyakhetarpal, any chance you might have time to look at this? I believe that's the only thing left before I can merge the   | 
    
There was a problem hiding this 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
| 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)) | 
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| 
           @martinRenou, would it be possible to get another review, please?  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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
pytestautouse fixtures that modify thedoctest_namespace).