PKwWM^ jupytercontrib/__init__.py""" Some Jupyter contrib extensions """ __version__ = '0.0.7' from .py2to3exporter import Python2to3Exporter from .mdoutputexporter import MarkdownOutputExporter PK;tNI "jupytercontrib/mdoutputexporter.py""" Custom exporter that encloses notebook outputs in ```output ``` code blocks. """ import os.path from nbconvert.exporters.markdown import MarkdownExporter #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- class MarkdownOutputExporter(MarkdownExporter): @property def template_path(self): x = super(MarkdownOutputExporter, self).template_path+[os.path.join(os.path.dirname(__file__), "templates")] print(x) return x def _template_file_default(self): return 'md_output' # markdown PKOtNI3yW jupytercontrib/py2to3exporter.py# Copyright 2016 - The Jupyter development team # adapted from Thomas Kluyver nb2to3 script: # https://gist.github.com/takluyver/c8839593c615bb2f6e80 """ Simple exporter that convert a notebook from Legacy Python 2 to Python 3 """ from nbconvert.exporters.notebook import NotebookExporter #!/usr/bin/env python3 """ To run: python3 nb2to3.py notebook-or-directory """ # Authors: Thomas Kluyver, Fernando Perez # See: https://gist.github.com/takluyver/c8839593c615bb2f6e80 import lib2to3 from lib2to3.refactor import RefactoringTool, get_fixers_from_package from nbconvert.preprocessors import Preprocessor class Python2to3Preprocessor(Preprocessor): """A Pelican specific preprocessor to remove some of the cells of a notebook""" # I could also read the cells from nb.metadata.pelican if someone wrote a JS extension, # but for now I'll stay with configurable value. def __init__(self, *args, **kwargs): super(Python2to3Preprocessor, self).__init__(*args, **kwargs) availables_fixes = set(get_fixers_from_package('lib2to3.fixes')) self.refactoring_tool = RefactoringTool(availables_fixes) def preprocess(self, nb, resources): self.log.info("runnign 2to3 on each cell of the notebook.") refactor_notebook_inplace(nb, self.refactoring_tool, '') return nb, resources def refactor_notebook_inplace(nb, refactoring_tool, path): def refactor_cell(src): try: tree = refactoring_tool.refactor_string(src+'\n', str(path) + '/cell-%d' % i) except (lib2to3.pgen2.parse.ParseError, lib2to3.pgen2.tokenize.TokenError): return src else: return str(tree)[:-1] # Run 2to3 on code for i, cell in enumerate(nb.cells, start=1): if cell.cell_type == 'code': if cell.execution_count in (' ', '*'): cell.execution_count = None if cell.source.startswith('%%'): # For cell magics, try to refactor the body, in case it's # valid python head, source = cell.source.split('\n', 1) cell.source = head + '\n' + refactor_cell(source) else: cell.source = refactor_cell(cell.source) # Update notebook metadata nb.metadata.kernelspec = { 'display_name': 'Python 3', 'name': 'python3', 'language': 'python', } if 'language_info' in nb.metadata: nb.metadata.language_info.codemirror_mode = { 'name': 'ipython', 'version': 3, } nb.metadata.language_info.pygments_lexer = 'ipython3' nb.metadata.language_info.pop('version', None) class Python2to3Exporter(NotebookExporter): """ This is a custom exporter that will pate all cells to use Python 3. """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.register_preprocessor( Python2to3Preprocessor(), enabled=True) PKiWM?j&jupytercontrib/templates/md_output.tpl{% extends "markdown.tpl" %} {% block input %} {% if nb.metadata.language_info %} ```{{ nb.metadata.language_info.name }} {% else %} ```python {% endif %}{{ cell.source}} ``` {% endblock input %} {% block traceback_line %} ```output {{ line.rstrip() | strip_ansi }} ``` {% endblock traceback_line %} {% block stream %} ```output {{ output.text.rstrip() }} ``` {% endblock stream %} {% block data_text scoped %} ```output {{ output.data['text/plain'].rstrip() }} ``` {% endblock data_text %} PK)tNI8q$jupytercontrib/tests/test_imports.py def test_py2to3_import(): from jupytercontrib.py2to3exporter import Python2to3Exporter Python2to3Exporter() def test_mdconvert_import(): from jupytercontrib.mdoutputexporter import MarkdownOutputExporter MarkdownOutputExporter() PK!H|Mm/jupytercontrib-0.0.7.dist-info/entry_points.txtKJ+K-*K(/*I-*2*7*-r%EIV%y WBܔҒtE)y`Yr.PK*QXHh X)>>&jupytercontrib-0.0.7.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2016 Matthias Bussonnier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HJVSa$jupytercontrib-0.0.7.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,rzd&Y)r$[)T&UD"PK!HbXRj'jupytercontrib-0.0.7.dist-info/METADATA}T]6|X^-;<K]%AQ%,DR%WwMmiffcѵ}w9]oQrN~wL//ߪZƜeyΥ%Yإ~B<[>H;ݭb;S%^ ӝiwpXb[ms.R$So9Vd-fq1HyFO?9uM&9-X(Þn>#no`쭉+AZ\Qj-Zu4$ҁ)pįnIDy!v)刲nHzu͔TFwT̕?2w415FKrܐ ̑`;jIS3G'l9*kPdNZM!ޓPLQ ;NjP׷_Z1QdpϦ7X- 5cnM3pV But菦fnؾKt%8|/*ĥӄ#nb~QlխN~N7cYè.IƇj>C*Nn",mqHxϥ5[XzqWOcg^:ewk7PK!Hü#h%jupytercontrib-0.0.7.dist-info/RECORDɒ@{? ,>( 6m\(Bf&/yiV%Uc9xTLcc.&XE+AC 7R lչf8qvWeC$հ"7cuѺSݔ'}B3F-#wyJ; X;0%^Yzǰ HĭB>&jupytercontrib-0.0.7.dist-info/LICENSEPK!HJVSa$Yjupytercontrib-0.0.7.dist-info/WHEELPK!HbXRj'jupytercontrib-0.0.7.dist-info/METADATAPK!Hü#h%jupytercontrib-0.0.7.dist-info/RECORDPK 7