Skip to content
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 strict option to sphinx extension #2551

Merged
merged 4 commits into from
Jan 27, 2022
Merged

Add strict option to sphinx extension #2551

merged 4 commits into from
Jan 27, 2022

Conversation

jtilly
Copy link
Contributor

@jtilly jtilly commented Jan 27, 2022

Closes #2550

This adds a :strict: option to the altair sphinx extension. When set, it ensures that the documentation build fails when a code snippet can't be run. This is meant to prevent code snippets in the documentation from going stale. It is less restrictive than building the documentation with -W because warnings for other reasons won't cause the build of the documentation to fail.

@jtilly jtilly changed the title Add strict option to sphinx documentation Add strict option to sphinx extension Jan 27, 2022
)
raise nodes.SkipNode
if node["strict"]:
raise ValueError(message)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps raise ValueError(message) from e to allow the error to include more context.

@jakevdp
Copy link
Collaborator

jakevdp commented Jan 27, 2022

Looks good - I wonder if it would be worth adding a :strict: option to altair-gallery as well, which could forward it to the generated altair plots?

@jtilly
Copy link
Contributor Author

jtilly commented Jan 27, 2022

I'm not 100% sure what you mean, but I gave it a shot anyways: in eaf69c1 I imitated what's currently being done to the :code-below: flag.

@jakevdp
Copy link
Collaborator

jakevdp commented Jan 27, 2022

Yeah, I forgot that there's no gallery directive. That looks good.

Last thing: since there are no unit tests to exercise this option, have you tried it locally to confirm it works as expected?

@jtilly
Copy link
Contributor Author

jtilly commented Jan 27, 2022

Have you tried it locally to confirm it works as expected?

Yes!

With

.. _test:

====
Test
====

.. altair-plot::
    :output: none
    :strict:

    {1} + [2]

I get

/tmp/altair/lib/python3.9/site-packages/altair/sphinxext/altairplot.py:229: UserWarning: altair-plot: /tmp/doctest/docs/test.rst:7 Code Execution failed:TypeError: unsupported operand type(s) for +: 'set' and 'list'
  warnings.warn(message)

generating indices... genindex py-modindex done
writing additional pages... search done
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded, 13 warnings.

and with :strict: I get

.. _test:

====
Test
====

.. altair-plot::
    :output: none
    :strict:

    {1} + [2]
writing output... [100%] test                                                                                                                                                                                                                 
Exception occurred:
  File "/tmp/altair/lib/python3.9/site-packages/altair/sphinxext/altairplot.py", line 227, in html_visit_altair_plot
    raise ValueError(message) from e
ValueError: altair-plot: /tmp/doctest/docs/test.rst:7 Code Execution failed:TypeError: unsupported operand type(s) for +: 'set' and 'list'
The full traceback has been saved in /var/folders/gj/hb6rghv906vdldwzwg13bm3m0000gn/T/sphinx-err-8f07v1lb.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [Makefile:20: html] Error 2

@jakevdp
Copy link
Collaborator

jakevdp commented Jan 27, 2022

Very nice - thanks!

@jakevdp jakevdp merged commit b399d8e into vega:master Jan 27, 2022
@jtilly jtilly deleted the issue-2550 branch January 27, 2022 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add strict option to altair sphinx extension
2 participants