-
Notifications
You must be signed in to change notification settings - Fork 207
[MRG] Exitcodes #97
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
[MRG] Exitcodes #97
Changes from all commits
76ad32e
3a56e3c
7652b6e
f56ba72
c59d0b5
aa65988
58ee7c0
c079e24
e3a3678
4d139b2
0490d48
e21cea4
87b5dcd
7816bb2
d7ee1b6
3631b96
5562a46
9045a75
62b7d21
08012db
47d1c6e
1b3e3b0
089bf92
9e42628
41d7477
8cb59d5
2efcb11
d9d5262
22d2366
185944a
1874761
5a4ccea
5ed2859
c148816
be019e2
03e9488
760e45f
b930d1c
5125065
41773a0
3fa7a37
b6cc8e6
ce70a58
e2088cd
ef79cce
dde4dff
ece117d
76bda4a
04672f2
cbc69e4
1c3d19c
9857e94
095031d
2fb0cc6
d02b4e0
637e57f
f66eedd
31c0dfa
e0d90bd
16da3e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,27 @@ | |
|
||
|
||
from __future__ import division, print_function, absolute_import | ||
import copy | ||
import re | ||
import os | ||
from . import glr_path_static | ||
from .gen_rst import generate_dir_rst, SPHX_GLR_SIG | ||
from .docs_resolv import embed_code_links | ||
|
||
DEFAULT_GALLERY_CONF = { | ||
'filename_pattern': re.escape(os.sep) + 'plot', | ||
'examples_dirs': os.path.join('..', 'examples'), | ||
'gallery_dirs': 'auto_examples', | ||
'mod_example_dir': os.path.join('modules', 'generated'), | ||
'doc_module': (), | ||
'reference_url': {}, | ||
# build options | ||
'plot_gallery': True, | ||
'abort_on_example_error': False, | ||
'failing_examples': {}, | ||
'expected_failing_examples': set(), | ||
} | ||
|
||
|
||
def clean_gallery_out(build_dir): | ||
"""Deletes images under the sphx_glr namespace in the build directory""" | ||
|
@@ -55,6 +70,7 @@ def generate_gallery_rst(app): | |
except TypeError: | ||
plot_gallery = bool(app.builder.config.plot_gallery) | ||
|
||
gallery_conf = copy.deepcopy(DEFAULT_GALLERY_CONF) | ||
gallery_conf.update(app.config.sphinx_gallery_conf) | ||
gallery_conf.update(plot_gallery=plot_gallery) | ||
gallery_conf.update( | ||
|
@@ -143,28 +159,76 @@ def touch_empty_backreferences(app, what, name, obj, options, lines): | |
open(examples_path, 'w').close() | ||
|
||
|
||
gallery_conf = { | ||
'filename_pattern': re.escape(os.sep) + 'plot', | ||
'examples_dirs': '../examples', | ||
'gallery_dirs': 'auto_examples', | ||
'mod_example_dir': os.path.join('modules', 'generated'), | ||
'doc_module': (), | ||
'reference_url': {}, | ||
} | ||
def sumarize_failing_examples(app, exception): | ||
"""Collects the list of falling examples during build and prints them with the traceback | ||
|
||
Raises ValueError if there where failing examples | ||
""" | ||
if exception is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know off the top of your head when exception is not None? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is part of Sphinx black magic. The thing is that Sphinx mostly stops build on exceptions but other times it accumulates them in this exception variable. This statement seems to bee the common practice for functions that execute on |
||
return | ||
|
||
# Under no-plot Examples are not run so nothing to summarize | ||
if not app.config.sphinx_gallery_conf['plot_gallery']: | ||
return | ||
|
||
gallery_conf = app.config.sphinx_gallery_conf | ||
failing_examples = set(gallery_conf['failing_examples']) | ||
expected_failing_examples = set(gallery_conf['expected_failing_examples']) | ||
|
||
examples_expected_to_fail = failing_examples.intersection( | ||
expected_failing_examples) | ||
expected_fail_msg = [] | ||
if examples_expected_to_fail: | ||
expected_fail_msg.append("Examples failing as expected:") | ||
for fail_example in examples_expected_to_fail: | ||
expected_fail_msg.append(fail_example + ' failed leaving traceback:\n' + | ||
gallery_conf['failing_examples'][fail_example] + '\n') | ||
print("\n".join(expected_fail_msg)) | ||
|
||
examples_not_expected_to_fail = failing_examples.difference( | ||
expected_failing_examples) | ||
fail_msgs = [] | ||
if examples_not_expected_to_fail: | ||
fail_msgs.append("Unexpected failing examples:") | ||
for fail_example in examples_not_expected_to_fail: | ||
fail_msgs.append(fail_example + ' failed leaving traceback:\n' + | ||
gallery_conf['failing_examples'][fail_example] + '\n') | ||
|
||
examples_not_expected_to_pass = expected_failing_examples.difference( | ||
failing_examples) | ||
if examples_not_expected_to_pass: | ||
fail_msgs.append("Examples expected to fail, but not failling:\n" + | ||
"Please remove this examples from\n" + | ||
"sphinx_gallery_conf['expected_failing_examples']\n" + | ||
"in your conf.py file" | ||
"\n".join(examples_not_expected_to_pass)) | ||
|
||
if fail_msgs: | ||
raise ValueError("Here is a summary of the problems encountered when " | ||
"running the examples\n\n" + "\n".join(fail_msgs) + | ||
"\n" + "-" * 79) | ||
|
||
|
||
def get_default_config_value(key): | ||
def default_getter(conf): | ||
return conf['sphinx_gallery_conf'].get(key, DEFAULT_GALLERY_CONF[key]) | ||
return default_getter | ||
|
||
|
||
def setup(app): | ||
"""Setup sphinx-gallery sphinx extension""" | ||
app.add_config_value('plot_gallery', True, 'html') | ||
app.add_config_value('abort_on_example_error', False, 'html') | ||
app.add_config_value('sphinx_gallery_conf', gallery_conf, 'html') | ||
app.add_config_value('sphinx_gallery_conf', DEFAULT_GALLERY_CONF, 'html') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like this seems to do what #122 wanted. Feel free to refactor it the way you like: diff --git a/sphinx_gallery/gen_gallery.py b/sphinx_gallery/gen_gallery.py
index 32bdf3a..4147e75 100644
--- a/sphinx_gallery/gen_gallery.py
+++ b/sphinx_gallery/gen_gallery.py
@@ -198,11 +198,20 @@ def sumarize_failing_examples(app, exception):
"running the examples\n\n" + "\n".join(fail_msgs) + "-" * 79)
+def get_default_plot_gallery(conf):
+ return conf['sphinx_gallery_conf'].get('plot_gallery', True)
+
+
+def get_default_abort_on_example(conf):
+ return conf['sphinx_gallery_conf'].get('abort_on_example_error', False)
+
+
def setup(app):
"""Setup sphinx-gallery sphinx extension"""
- app.add_config_value('plot_gallery', True, 'html')
- app.add_config_value('abort_on_example_error', False, 'html')
app.add_config_value('sphinx_gallery_conf', DEFAULT_GALLERY_CONF, 'html')
+ app.add_config_value('plot_gallery', get_default_plot_gallery, 'html')
+ app.add_config_value('abort_on_example_error', get_default_abort_on_example, 'html')
+
app.add_stylesheet('gallery.css')
if 'sphinx.ext.autodoc' in app._extensions: Basically the order of priority is (from lower to higher priority):
|
||
for key in ['plot_gallery', 'abort_on_example_error']: | ||
app.add_config_value(key, get_default_config_value(key), 'html') | ||
|
||
app.add_stylesheet('gallery.css') | ||
|
||
if 'sphinx.ext.autodoc' in app._extensions: | ||
app.connect('autodoc-process-docstring', touch_empty_backreferences) | ||
|
||
app.connect('builder-inited', generate_gallery_rst) | ||
|
||
app.connect('build-finished', sumarize_failing_examples) | ||
app.connect('build-finished', embed_code_links) | ||
|
||
|
||
|
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.
Out of curiosity, are there any advantages of using napoleon vs numpydoc?
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.
Yes napoleon is inside sphinx. numpydoc is an extra dependency. They do the same thing
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.
OK