-
Notifications
You must be signed in to change notification settings - Fork 15
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
add support for async galleries #90
Conversation
This already works somewhat: A few issues though that I need to think about how to solve. Since we wrap the whole block in an async function,
|
Ok, maybe the issues in #90 (comment) aren't too bad after all:
|
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.
@smarie Could you make a first pass on this? I deviated a little from our plan in #88. Instead of having a feature flag for the async handling, I've opted to detect it, by checking if compiling the code leaves us with an async error. IMO this is robust enough, but I'll let you be the judge of that. The patch will also work with a feature flag, so we can easily switch to that if you prefer.
Don't worry about the 3.7 and 3.8 CI jobs that are failing. |
@@ -788,9 +848,7 @@ def execute_code_block(compiler, block, script: GalleryScript): | |||
|
|||
try: | |||
ast_Module = _ast_module() | |||
code_ast = ast_Module([bcontent]) |
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.
I was surprised to see this but it is indeed present in sphinx-gallery: https://github.com/sphinx-gallery/sphinx-gallery/blob/master/sphinx_gallery/gen_rst.py#L965
They probably use this as a pre-validator of good syntax. Should we keep it too ? In that case I suggest to keep these original lines and simply add your if _needs_async_handling
extra two lines below (dropping _parse_code
). That way the change will be easier to spot when comparing with sphinx-gallery code. Of course no hurry with this one, as this is a nitpick
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.
They probably use this as a pre-validator of good syntax. Should we keep it too ?
That is what we basically have right now. If we find a SyntaxError
there, we need to check whether this comes from using async stuff and can't just exit the try
branch pre-maturely. In the light of #90 (comment), we could just bubble up a SyntaxError
if our async handling doesn't resolve it.
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.
I've implemented my suggestion in 5e0e636. Please have a look.
@smarie I'm happy with the functionality. Other than #90 (comment) do you have any other comments that could prevent this from being merged? If no, I'll get on improving the example and documenting this change in general. As for tests, I see that a lot of them are commented out. How do you want to handle this? Just trust the fact that we can build the examples including the async one? |
Thanks @pmeier ! I'll have a more thorough look in the upcoming days, just a quick answer concerning the tests: this project was a port of sphinx-gallery "as close as possible to the original", so that evolutions/improvements/bugfixes could easily be performed on both sides. Obviously this was not ideal (creating a common core lib would do much better), and that forced me to stick with some coding style that I would not have performed from scratch. A side effect of trying to not change much the code design, was that I was totally unable to integrate the original tests - too far from what I would have intuitively done, and obviously very sticky with the design of the internals. Lacking time, I decided to go for a very crude strategy: the doc page of this project IS the main test. So if you add a gallery example for async, it will be taken into account for coverage for example. That being said, adding a few low-level tests dedicated to your utility functions could make this much more robust to edge cases, and error cases so I encourage you to do so. I hope this is clear enough, first day of 2024 - still a bit tired :) |
@smarie I've added some text to the example as well as tests. This is ready for another round of review. |
Ping @smarie |
1 similar comment
Ping @smarie |
Co-authored-by: Sylvain Marié <sylvain.marie@schneider-electric.com>
All set, thanks a lot for this nice PR @pmeier ! |
And here is 0.10.0 , showing your great new feature : https://smarie.github.io/mkdocs-gallery/generated/gallery/plot_12_async/ |
This Pull request fixes #88.
changelog.md
entries in the appropriate "in progress" section (not the last release one)b - My PR adds some features:
(Delete this section if not relevant)
with pytest.raises(MyErrorType, match="...")
)