diff options
author | Javi Merino <javi.merino@arm.com> | 2016-04-27 09:58:55 +0100 |
---|---|---|
committer | Javi Merino <javi.merino@arm.com> | 2016-04-27 16:24:41 +0100 |
commit | 0e6aa44c54f87cedb39fdee542ace0061f94f6f0 (patch) | |
tree | 3d4ab64ceb6d4e3257a3451d88a37bbb6b4e3dba /trappy/nbexport | |
parent | 90b588aeb958af7f6ccf587226958f2e6b8b81d1 (diff) | |
download | trappy-0e6aa44c54f87cedb39fdee542ace0061f94f6f0.tar.gz |
trappy: allow running the testsuite in environments without ipython
nose tries to import all __init__.py files. Even if you do in
trappy/__init__.py:
try:
import trappy.nbexport
except ImportError:
pass
The testsuite fails because it then goes on and tries to import
trappy/nbexport/__init__.py. To avoid that, let
trappy/nbexport/__init__.py fail gracefully if it fails to import
anything needing for the export.
Diffstat (limited to 'trappy/nbexport')
-rw-r--r-- | trappy/nbexport/__init__.py | 16 | ||||
-rw-r--r-- | trappy/nbexport/exporter.py (renamed from trappy/nbexport/preprocessors.py) | 9 |
2 files changed, 15 insertions, 10 deletions
diff --git a/trappy/nbexport/__init__.py b/trappy/nbexport/__init__.py index 0293318..050a357 100644 --- a/trappy/nbexport/__init__.py +++ b/trappy/nbexport/__init__.py @@ -17,13 +17,9 @@ * Custom Preprocessing """ -from nbconvert.exporters.html import HTMLExporter -from trappy.nbexport.preprocessors import TrappyPlotterPreprocessor - - -class HTML(HTMLExporter): - """HTML Exporter class for TRAPpy notebooks""" - - def __init__(self, **kwargs): - super(HTML, self).__init__(**kwargs) - self.register_preprocessor(TrappyPlotterPreprocessor, enabled=True) +try: + from trappy.nbexport.exporter import HTML +except ImportError: + # Avoid testsuite errors when the testsuite is run in an environment without + # ipython + HTML = object diff --git a/trappy/nbexport/preprocessors.py b/trappy/nbexport/exporter.py index 096dab6..d83ca96 100644 --- a/trappy/nbexport/preprocessors.py +++ b/trappy/nbexport/exporter.py @@ -16,6 +16,7 @@ """Preprocessor to remove Marked Lines from IPython Output Cells""" +from nbconvert.exporters.html import HTMLExporter from nbconvert.preprocessors import Preprocessor import os import re @@ -27,6 +28,14 @@ IMPORT_SCRIPT = r'/\* TRAPPY_PUBLISH_IMPORT = "([^"]+)" \*/' SOURCE_LIB = r'<!-- TRAPPY_PUBLISH_SOURCE_LIB = "([^"]+)" -->' +class HTML(HTMLExporter): + """HTML Exporter class for TRAPpy notebooks""" + + def __init__(self, **kwargs): + super(HTML, self).__init__(**kwargs) + self.register_preprocessor(TrappyPlotterPreprocessor, enabled=True) + + class TrappyPlotterPreprocessor(Preprocessor): """Preprocessor to remove Marked Lines from IPython Output Cells""" |