Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 60 commits into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
76ad32e
Writing block fails to stderr
Titan-C Feb 14, 2016
3a56e3c
Print a list at build end of Failing examples
Titan-C Feb 14, 2016
7652b6e
Exit code on build finish
Titan-C Feb 14, 2016
f56ba72
Failed examples only trigger when examples fail
Titan-C Feb 14, 2016
c59d0b5
Stop building examples after a fail
Titan-C Feb 14, 2016
aa65988
Setub test build
Titan-C Feb 14, 2016
58ee7c0
Test single errored block run
Titan-C Feb 14, 2016
c079e24
Raise ValueError on test bad code
Titan-C Feb 20, 2016
e3a3678
Enable a set of expected to fail examples
Titan-C Feb 20, 2016
4d139b2
Change fail example message
Titan-C Feb 20, 2016
0490d48
Categorize failing examples and give traceback
Titan-C Feb 20, 2016
e21cea4
Expected to fail examples do not exit 1
Titan-C Feb 20, 2016
87b5dcd
Comment about fail example exit 1
Titan-C Feb 20, 2016
7816bb2
Configuration documentation about fail examples
Titan-C Feb 20, 2016
d7ee1b6
mark a file of broken example
Titan-C Mar 6, 2016
3631b96
Image_path needs numbers to format
Titan-C Mar 6, 2016
5562a46
Check for failed example on last build
Titan-C Mar 6, 2016
9045a75
Spellcheck advanced configuration
Titan-C Mar 6, 2016
62b7d21
Correct use of path join
Titan-C Mar 6, 2016
08012db
Pep8 into test function
Titan-C Mar 6, 2016
47d1c6e
Use config for tests
Titan-C Apr 12, 2016
1b3e3b0
UTF-8 for tests
Titan-C Apr 12, 2016
089bf92
Write md5 only after successful build
Titan-C Apr 21, 2016
9e42628
save failing image mark
Titan-C Apr 21, 2016
41d7477
Fix Broken image thumbnail display
Titan-C Apr 21, 2016
8cb59d5
Exit With ValueError on failed examples end report
Titan-C Apr 21, 2016
2efcb11
Use warnings for failed example
Titan-C Apr 21, 2016
d9d5262
Change ordering of end warn messages
Titan-C Apr 21, 2016
22d2366
PY2.6 fix example
Titan-C Apr 21, 2016
185944a
Consistent spelling in changes
Titan-C Apr 21, 2016
1874761
Address naming convention comments
Titan-C May 1, 2016
5a4ccea
Drop image existence check to validate build
Titan-C May 1, 2016
5ed2859
Remove Broken image tag file
Titan-C May 8, 2016
c148816
Update raise example comments
Titan-C May 8, 2016
be019e2
Address comments
Titan-C May 12, 2016
03e9488
Fix documentation content
Titan-C Jun 1, 2016
760e45f
Address comments for gen_gallery and gen_rst
Titan-C Jun 1, 2016
b930d1c
increase tests
Titan-C Jun 1, 2016
5125065
Address comments
Titan-C Jun 26, 2016
41773a0
Fix broken thumbnail issue
Titan-C Jun 26, 2016
3fa7a37
Update generate_file_rst docstring
Titan-C Jun 26, 2016
b6cc8e6
Use napoleon extension for documenting docstrings
Titan-C Jun 26, 2016
ce70a58
regex with raw string
Titan-C Jun 26, 2016
e2088cd
Change logic statements of when to execute script
Titan-C Jun 26, 2016
ef79cce
save_figures now returns the rst for images
Titan-C Jun 26, 2016
dde4dff
Simplified logic for generating rst file
Titan-C Jun 26, 2016
ece117d
save_thumbnail finds image to display
Titan-C Jun 26, 2016
76bda4a
Explicit failed example order
Titan-C Jul 3, 2016
04672f2
Fig bug: Examples are not rerun on second+ build
Titan-C Jul 3, 2016
cbc69e4
Fix #122 new configuration options
Titan-C Jul 3, 2016
1c3d19c
Fix text style comments
Titan-C Jul 3, 2016
9857e94
Rename the control variable to run examples
Titan-C Jul 10, 2016
095031d
[CI] Include a no-plot run
Titan-C Jul 10, 2016
2fb0cc6
[Fix BUG] no-plot caches the md5sum files
Titan-C Jul 10, 2016
d02b4e0
Don't execute example fail summary on no-plot
Titan-C Jul 10, 2016
637e57f
Simplify control logic on write md5sum file
Titan-C Jul 10, 2016
f66eedd
Address comments
Titan-C Jul 21, 2016
31c0dfa
Address comments
Titan-C Jul 21, 2016
e0d90bd
Pass block execution variables as a dictionary
Titan-C Jul 21, 2016
16da3e6
Harmonize example_fail vars for summary function
Titan-C Jul 22, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ script:
- if [ "$DISTRIB" == "ubuntu" ]; then python setup.py nosetests; fi
- if [ "$DISTRIB" == "conda" ]; then nosetests; fi
- cd doc
- make html-noplot
- make html
14 changes: 11 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ git master

New features
''''''''''''

* Summary of failing examples with traceback at the end of the sphinx
build. By default the build exits with a 1 exit code if an example
has failed. A list of examples that are expected to fail can be
defined in `conf.py` and exit the build with 0
exit code. Alternatively it is possible to exit the build as soon as
one example has failed.
* Print aggregated and sorted list of computation times of all examples
in the console during the build.
* For examples that create multiple figures, set the thumbnail image.

* The ``plot_gallery`` and ``abort_on_example_error`` options can now
be specified in ``sphinx_gallery_conf``. The build option (``-D``
flag passed to ``sphinx-build``) takes precedence over the
``sphinx_gallery_conf`` option.

v0.1.2
------
Expand Down Expand Up @@ -41,7 +49,7 @@ Example scripts are now available for download as IPython Notebooks
`#75 <https://github.com/sphinx-gallery/sphinx-gallery/pull/75>`_

New features
------------
''''''''''''

* Configurable filename pattern to select which example scripts are
executed while building the Gallery
Expand Down
54 changes: 49 additions & 5 deletions doc/advanced_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ you would do:
}

Here, one should escape the dot ``'\.'`` as otherwise python `regular expressions`_ matches any character. Nevertheless, as
one is targetting a specific file, it is most certainly going to match the dot in the filename.
one is targeting a specific file, it is most certainly going to match the dot in the filename.

Similarly, to build only examples in a specific directory, you can do:

.. code-blocK:: python
.. code-block:: python

sphinx_gallery_conf = {
'filename_pattern' : '/directory/plot_'
Expand Down Expand Up @@ -251,7 +251,13 @@ your ``Makefile`` with::
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

Remember that for ``Makefile`` white space is significant and the indentation are tabs
and not spaces
and not spaces.

Alternatively, you can add the ``plot_gallery`` option to the
``sphinx_gallery_conf`` dictionary inside your ``conf.py``
configuration file to have it as a default. The highest precedence is
always given to the `-D` flag of the ``sphinx-build`` command.


Dealing with failing Gallery example scripts
============================================
Expand All @@ -267,7 +273,17 @@ failing code block. Refer to example
:ref:`sphx_glr_auto_examples_plot_raise.py` to view the default
behavior.

An extra functionality of Sphinx-Gallery is the early fail option. In
The build is also failed exiting with code 1 and giving you a summary
of the failed examples with their respective traceback. This way you
are aware of failing examples right after the build and can find them
easily.

There are some additional options at your hand to deal with broken examples.

Abort build on first fail
-------------------------

Sphinx-Gallery provides the early fail option. In
this mode the gallery build process breaks as soon as an exception
occurs in the execution of the examples scripts. To activate this
behavior you need to pass a flag at the build process. It can be done
Expand All @@ -279,6 +295,34 @@ by including in your ``Makefile``::
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

Remember that for ``Makefile`` white space is significant and the indentation are tabs
and not spaces
and not spaces.

Alternatively, you can add the ``abort_on_example_error`` option to
the ``sphinx_gallery_conf`` dictionary inside your ``conf.py``
configuration file to have it as a default. The highest precedence is
always given to the `-D` flag of the ``sphinx-build`` command.


Don't fail the build on exit
----------------------------

It might be the case that you want to keep the gallery even with
failed examples. Thus you can configure Sphinx-Gallery to allow
certain examples to fail and still exit with a 0 exit code. For this
you need to list all the examples you want to allow to fail during
build. Change your `conf.py` accordingly:


.. code-block:: python

sphinx_gallery_conf = {
...
'expected_failing_examples': ['../examples/plot_raise.py']
}

Here you list the examples you allow to fail during the build process,
keep in mind to specify the full relative path from your `conf.py` to
the example script.


.. _regular expressions: https://docs.python.org/2/library/re.html
27 changes: 15 additions & 12 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

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

OK

'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
Expand Down Expand Up @@ -114,6 +115,7 @@
# a list of builtin themes.
html_theme = 'default'


def setup(app):
app.add_stylesheet('theme_override.css')

Expand Down Expand Up @@ -199,22 +201,22 @@ def setup(app):
# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#'preamble': '',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'Sphinx-Gallery.tex', u'Sphinx-Gallery Documentation',
u'Óscar Nájera', 'manual'),
('index', 'Sphinx-Gallery.tex', u'Sphinx-Gallery Documentation',
u'Óscar Nájera', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -257,9 +259,9 @@ def setup(app):
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'Sphinx-Gallery', u'Sphinx-Gallery Documentation',
u'Óscar Nájera', 'Sphinx-Gallery', 'One line description of project.',
'Miscellaneous'),
('index', 'Sphinx-Gallery', u'Sphinx-Gallery Documentation',
u'Óscar Nájera', 'Sphinx-Gallery', 'One line description of project.',
'Miscellaneous'),
]

# Documents to append as an appendix to all manuals.
Expand Down Expand Up @@ -304,4 +306,5 @@ def setup(app):
'examples_dirs': examples_dirs,
'gallery_dirs': gallery_dirs,
'find_mayavi_figures': find_mayavi_figures,
}
'expected_failing_examples': ['../examples/plot_raise.py']
}
2 changes: 1 addition & 1 deletion examples/plot_quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
for b in [10, 20, 30]:
n = 2 * (np.exp(b * (mu - 1)) + np.exp(b * (2 * mu - 3))) / \
(1 + np.exp(b * (mu - 1)) * (2 + np.exp(b * (mu - 2))))
plt.plot(mu, n, label=r"$\beta={}$".format(b))
plt.plot(mu, n, label=r"$\beta={0}$".format(b))
plt.xlabel(r'$\mu$ ($\epsilon=1$, $U=1$)')
plt.ylabel(r'$\langle N \rangle=\langle n_\uparrow \rangle+\langle n_\downarrow\rangle$')
plt.legend(loc=0)
Expand Down
20 changes: 11 additions & 9 deletions examples/plot_raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
You also get the python traceback of the failed code block
"""

iae

###############################################################################
# Sphinx gallery as it executes scripts by block will continue
# evaluating the script after exceptions, but there is no warranty
# figure ordering will continue to match block's code. Anyway when the
# script is broken, you should try to fix it first.

# Code source: Óscar Nájera
# License: BSD 3 clause

Expand All @@ -26,8 +18,18 @@

plt.pcolormesh(np.random.randn(100, 100))

###############################################################################
# This next block will raise a NameError

iae

###############################################################################
# Sphinx gallery will stop executing the remaining code blocks after
# the exception has occurred in the example script. Nevertheless the
# html will still render all the example annotated text and
# code blocks, but no output will be shown.

###############################################################################
# Here is another error raising Block
# Here is another error raising block but will not be executed

plt.plot('Strings are not a valid argument for the plot function')
86 changes: 75 additions & 11 deletions sphinx_gallery/gen_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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 build-finished but will not deal with the exceptions.

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')
Copy link
Member

Choose a reason for hiding this comment

The 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):

  • DEFAULT_GALLERY_CONF
  • sphinx_gallery_conf (in conf.py)
  • override provided to sphinx-build through the -D flag

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)


Expand Down
Loading