Skip to content

Commit

Permalink
Added hv.util.command and set it as an entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed May 29, 2017
1 parent cbec66d commit fe57fa2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
19 changes: 1 addition & 18 deletions holoviews/ipython/preprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
python holoviews/ipython/convert.py Conversion_Example.ipynb | python
"""
import nbconvert, nbformat
import ast
from nbconvert.preprocessors import Preprocessor
import os, sys, ast



def comment_out_magics(source):
Expand Down Expand Up @@ -193,18 +191,3 @@ def preprocess_cell(self, cell, resources, index):
substitution = self.replace(outputs['data']['text/html'])
outputs['data']['text/html'] = substitution
return cell, resources


if __name__ == '__main__':
filename = sys.argv[1]
basename = os.path.splitext(os.path.basename(filename))[0]
with open(filename) as f:
nb = nbformat.read(f, nbformat.NO_CONVERT)
exporter = nbconvert.PythonExporter()
preprocessors = [OptsMagicProcessor(),
OutputMagicProcessor(),
StripMagicsProcessor()]
for preprocessor in preprocessors:
exporter.register_preprocessor(preprocessor)
source, meta = exporter.from_notebook_node(nb)
print(source)
29 changes: 29 additions & 0 deletions holoviews/util/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
python -m holoviews.util.command Conversion_Example.ipynb
OR
holoviews Conversion_Example.ipynb
"""

from __future__ import absolute_import

import sys, os
import nbformat, nbconvert
from ..ipython.preprocessors import OptsMagicProcessor, OutputMagicProcessor
from ..ipython.preprocessors import StripMagicsProcessor


def main(preprocessors=[OptsMagicProcessor(),
OutputMagicProcessor(),
StripMagicsProcessor()]):
with open(sys.argv[1]) as f:
nb = nbformat.read(f, nbformat.NO_CONVERT)
exporter = nbconvert.PythonExporter()
for preprocessor in preprocessors:
exporter.register_preprocessor(preprocessor)
source, meta = exporter.from_notebook_node(nb)
print(source)


if __name__ == '__main__':
main()

4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
platforms=['Windows', 'Mac OS X', 'Linux'],
license='BSD',
url='http://ioam.github.com/holoviews/',
entry_points={
'console_scripts': [
'holoviews = holoviews.util.command:main'
]},
packages = ["holoviews",
"holoviews.core",
"holoviews.core.data",
Expand Down

0 comments on commit fe57fa2

Please sign in to comment.