From e8e73cfb87a7b1b5d679cd4538c700d285a2df6f Mon Sep 17 00:00:00 2001 From: "Anton I. Sipos" Date: Tue, 13 Mar 2012 16:28:33 -0700 Subject: [PATCH 02/15] Add .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..a3781fa71 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.py[co] +*.egg-info +*~ +*.bak From fbfee55df67341000fd27857c05480759bfb6c00 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Sun, 28 Apr 2013 12:11:18 -0700 Subject: [PATCH 03/15] Create exceptions file to house all of the convert specific exceptions. Refactored 'exporter' Lots of changes.... --- api/exceptions.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 api/exceptions.py diff --git a/api/exceptions.py b/api/exceptions.py new file mode 100644 index 000000000..f1904fabf --- /dev/null +++ b/api/exceptions.py @@ -0,0 +1,21 @@ +"""Contains all of the exceptions used in NBConvert explicitly""" +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- +from __future__ import print_function + +#----------------------------------------------------------------------------- +# Classes and functions +#----------------------------------------------------------------------------- +class ConversionException(Exception): + """An exception raised by the conversion process.""" + + pass \ No newline at end of file From 599ff6aac65b2c85371a5a01085007db2f9ec1dc Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Tue, 30 Apr 2013 12:16:01 -0700 Subject: [PATCH 04/15] Split exporter into base and latex. --- {api => utils}/exceptions.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {api => utils}/exceptions.py (100%) diff --git a/api/exceptions.py b/utils/exceptions.py similarity index 100% rename from api/exceptions.py rename to utils/exceptions.py From 81c1b3cb7e5022fd34c7c4ff833d1e5e47c98da7 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Tue, 30 Apr 2013 12:27:08 -0700 Subject: [PATCH 05/15] Moved all converter code into nbconvert subdirectory --- {utils => nbconvert/utils}/exceptions.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {utils => nbconvert/utils}/exceptions.py (100%) diff --git a/utils/exceptions.py b/nbconvert/utils/exceptions.py similarity index 100% rename from utils/exceptions.py rename to nbconvert/utils/exceptions.py From 8af3a89173d3acfa3b09345d058eb59ab5332077 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Mon, 6 May 2013 22:41:38 -0700 Subject: [PATCH 06/15] Finished a rough draft of the exporters. --- nbconvert/api/python_exporter.py | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 nbconvert/api/python_exporter.py diff --git a/nbconvert/api/python_exporter.py b/nbconvert/api/python_exporter.py new file mode 100644 index 000000000..eb3c45b8f --- /dev/null +++ b/nbconvert/api/python_exporter.py @@ -0,0 +1,34 @@ +"""TODO: Docstring +""" + +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +# local import +import exporter + +#----------------------------------------------------------------------------- +# Classes +#----------------------------------------------------------------------------- +class PythonExporter(exporter.Exporter): + + def __init__(self, preprocessors=None, jinja_filters=None, config=None, armor=False, **kw): + + #Call base class constructor. + super(exporter.Exporter, self).__init__(preprocessors, jinja_filters, config, **kw) + + #Set defaults + self.file_extension = "py" + if armor: + self.template_file = "python-armor" + else: + self.template_file = "python" From 09099ce3c5deadc2275efa454a319296d3bdd515 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Fri, 10 May 2013 13:17:52 -0700 Subject: [PATCH 07/15] Names reduced, too redundent. --- nbconvert/api/{python_exporter.py => python.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename nbconvert/api/{python_exporter.py => python.py} (100%) diff --git a/nbconvert/api/python_exporter.py b/nbconvert/api/python.py similarity index 100% rename from nbconvert/api/python_exporter.py rename to nbconvert/api/python.py From c51fd06b4e48863f167a970202eb195cbc50c225 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Mon, 13 May 2013 18:47:11 -0700 Subject: [PATCH 08/15] Fixed all broken references, refactored some stuff here and there, standardized nomenclature. Ready to test... --- nbconvert/api/python.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/nbconvert/api/python.py b/nbconvert/api/python.py index eb3c45b8f..bebc8fa65 100644 --- a/nbconvert/api/python.py +++ b/nbconvert/api/python.py @@ -15,20 +15,26 @@ # local import import exporter +from IPython.utils.traitlets import Unicode #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- class PythonExporter(exporter.Exporter): + file_extension = Unicode( + 'py', config=True, + help="Extension of the file that should be written to disk") + + template_file = Unicode( + 'python', config=True, + help="Name of the template file to use") + def __init__(self, preprocessors=None, jinja_filters=None, config=None, armor=False, **kw): #Call base class constructor. super(exporter.Exporter, self).__init__(preprocessors, jinja_filters, config, **kw) #Set defaults - self.file_extension = "py" - if armor: - self.template_file = "python-armor" - else: - self.template_file = "python" + self.extract_figure_transformer.enabled = False + From 433f5264f160156930048706a8aab26c27006d0b Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Mon, 13 May 2013 23:09:45 -0700 Subject: [PATCH 09/15] Almost have nbconvert working again... --- nbconvert/api/python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbconvert/api/python.py b/nbconvert/api/python.py index bebc8fa65..6084f5f80 100644 --- a/nbconvert/api/python.py +++ b/nbconvert/api/python.py @@ -33,7 +33,7 @@ class PythonExporter(exporter.Exporter): def __init__(self, preprocessors=None, jinja_filters=None, config=None, armor=False, **kw): #Call base class constructor. - super(exporter.Exporter, self).__init__(preprocessors, jinja_filters, config, **kw) + super(PythonExporter, self).__init__(preprocessors, jinja_filters, config, **kw) #Set defaults self.extract_figure_transformer.enabled = False From a406334f0fcc26f235141e1d453c4aa5b632fdaf Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Fri, 17 May 2013 11:31:57 -0700 Subject: [PATCH 10/15] Comment & Refactor, utils and nbconvert main. --- nbconvert/utils/exceptions.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/nbconvert/utils/exceptions.py b/nbconvert/utils/exceptions.py index f1904fabf..6a4e0e624 100644 --- a/nbconvert/utils/exceptions.py +++ b/nbconvert/utils/exceptions.py @@ -1,4 +1,4 @@ -"""Contains all of the exceptions used in NBConvert explicitly""" +"""NbConvert specific exceptions""" #----------------------------------------------------------------------------- # Copyright (c) 2013, the IPython Development Team. # @@ -7,14 +7,10 @@ # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- -from __future__ import print_function - #----------------------------------------------------------------------------- # Classes and functions #----------------------------------------------------------------------------- + class ConversionException(Exception): """An exception raised by the conversion process.""" From bb35a0ad21f3294d8d47db3ed4ca73e854d45b94 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Fri, 17 May 2013 13:46:54 -0700 Subject: [PATCH 11/15] Cleanup and refactor of API, almost complete. Still need to target exporter.py and convert.py Then one last run-trough. --- nbconvert/api/python.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/nbconvert/api/python.py b/nbconvert/api/python.py index 6084f5f80..a76a1fee9 100644 --- a/nbconvert/api/python.py +++ b/nbconvert/api/python.py @@ -1,6 +1,6 @@ -"""TODO: Docstring """ - +Python exporter which exports Notebook code into a PY file. +""" #----------------------------------------------------------------------------- # Copyright (c) 2013, the IPython Development Team. # @@ -13,15 +13,20 @@ # Imports #----------------------------------------------------------------------------- +from IPython.utils.traitlets import Unicode + # local import import exporter -from IPython.utils.traitlets import Unicode #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class PythonExporter(exporter.Exporter): +class PythonExporter(exporter.Exporter): + """ + Exports a Python code file. + """ + file_extension = Unicode( 'py', config=True, help="Extension of the file that should be written to disk") @@ -30,10 +35,10 @@ class PythonExporter(exporter.Exporter): 'python', config=True, help="Name of the template file to use") - def __init__(self, preprocessors=None, jinja_filters=None, config=None, armor=False, **kw): + def __init__(self, transformers=None, filters=None, config=None, armor=False, **kw): #Call base class constructor. - super(PythonExporter, self).__init__(preprocessors, jinja_filters, config, **kw) + super(PythonExporter, self).__init__(transformers, filters, config, **kw) #Set defaults self.extract_figure_transformer.enabled = False From 8b7a0e1a556d4627e08e6b76e0f78ca5ef40a3e7 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Mon, 20 May 2013 23:36:19 -0700 Subject: [PATCH 12/15] Finished rename/refact on API namespace --- nbconvert/api/python.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/nbconvert/api/python.py b/nbconvert/api/python.py index a76a1fee9..024c91c99 100644 --- a/nbconvert/api/python.py +++ b/nbconvert/api/python.py @@ -36,6 +36,23 @@ class PythonExporter(exporter.Exporter): help="Name of the template file to use") def __init__(self, transformers=None, filters=None, config=None, armor=False, **kw): + """ + Public constructor + + Parameters + ---------- + transformers : list[of transformer] + Custom transformers to apply to the notebook prior to engaging + the Jinja template engine. Any transformers specified here + will override existing transformers if a naming conflict + occurs. + filters : list[of filter] + Custom filters to make accessible to the Jinja templates. Any + filters specified here will override existing filters if a + naming conflict occurs. + config : config + User configuration instance. + """ #Call base class constructor. super(PythonExporter, self).__init__(transformers, filters, config, **kw) From 2102ad6a571382bf557fa03c2bc7ec493c758996 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Mon, 27 May 2013 14:39:45 -0700 Subject: [PATCH 13/15] Rename api to exporters, as in discussion --- nbconvert/{api => exporters}/python.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename nbconvert/{api => exporters}/python.py (100%) diff --git a/nbconvert/api/python.py b/nbconvert/exporters/python.py similarity index 100% rename from nbconvert/api/python.py rename to nbconvert/exporters/python.py From 2208e387d954fbf36b10a115fc3e7f88af64df6b Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Thu, 6 Jun 2013 00:10:53 +0200 Subject: [PATCH 14/15] finish up config merging --- nbconvert/exporters/python.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/nbconvert/exporters/python.py b/nbconvert/exporters/python.py index 024c91c99..8ef6c0c4b 100644 --- a/nbconvert/exporters/python.py +++ b/nbconvert/exporters/python.py @@ -35,7 +35,8 @@ class PythonExporter(exporter.Exporter): 'python', config=True, help="Name of the template file to use") - def __init__(self, transformers=None, filters=None, config=None, armor=False, **kw): + + def __init__(self, transformers=None, filters=None, config=None, **kw): """ Public constructor @@ -46,7 +47,7 @@ class PythonExporter(exporter.Exporter): the Jinja template engine. Any transformers specified here will override existing transformers if a naming conflict occurs. - filters : list[of filter] + filters : dict{of filter} Custom filters to make accessible to the Jinja templates. Any filters specified here will override existing filters if a naming conflict occurs. @@ -56,7 +57,3 @@ class PythonExporter(exporter.Exporter): #Call base class constructor. super(PythonExporter, self).__init__(transformers, filters, config, **kw) - - #Set defaults - self.extract_figure_transformer.enabled = False - From 478f3244bf06c70e1dcaf5c2fb174b05894aacb2 Mon Sep 17 00:00:00 2001 From: Matthias BUSSONNIER Date: Tue, 11 Jun 2013 22:29:25 +0200 Subject: [PATCH 15/15] fix config inheriting --- nbconvert/exporters/python.py | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/nbconvert/exporters/python.py b/nbconvert/exporters/python.py index 8ef6c0c4b..f81a74445 100644 --- a/nbconvert/exporters/python.py +++ b/nbconvert/exporters/python.py @@ -34,26 +34,3 @@ class PythonExporter(exporter.Exporter): template_file = Unicode( 'python', config=True, help="Name of the template file to use") - - - def __init__(self, transformers=None, filters=None, config=None, **kw): - """ - Public constructor - - Parameters - ---------- - transformers : list[of transformer] - Custom transformers to apply to the notebook prior to engaging - the Jinja template engine. Any transformers specified here - will override existing transformers if a naming conflict - occurs. - filters : dict{of filter} - Custom filters to make accessible to the Jinja templates. Any - filters specified here will override existing filters if a - naming conflict occurs. - config : config - User configuration instance. - """ - - #Call base class constructor. - super(PythonExporter, self).__init__(transformers, filters, config, **kw)