diff --git a/README.md b/README.md index 4e76c46..03ae03d 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,13 @@ Use [nbconvert](https://github.com/jupyter/nbconvert) with template pj (pretty-j jupyter nbconvert --to html --template pj ${PATH_TO_IPYNB} ``` +## Dev Installation +```sh +git clone https://github.com/JanPalasek/pretty-jupyter.git +cd pretty-jupyter +./env/install.ps1 # Or ./env/install.sh on linux +``` + ## Credits Credits for styles, toc, tabs etc. go to developers of RMarkdown and its packages. A big part of this project is applying their incredible work to Jupyter. diff --git a/env/install.ps1 b/env/install.ps1 index f2a999b..2ece4aa 100644 --- a/env/install.ps1 +++ b/env/install.ps1 @@ -8,5 +8,7 @@ python -m pip install --upgrade wheel setuptools pip-tools # install everything in requirements.txt ./env/sync.ps1 -# install the app -pretty-jupyter install \ No newline at end of file +python -m pip install -e . + +# install files +pretty-jupyter install-dev \ No newline at end of file diff --git a/setup.py b/setup.py index d0961d7..9858e74 100644 --- a/setup.py +++ b/setup.py @@ -5,21 +5,26 @@ with open("README.md", "r") as fh: long_description = fh.read() +# this is done only to copy to the nbconvert's expected target directory +# so 'jupyter nbconvert' recognizes our new template data_files = [] data_files.append( - ("share/jupyter/nbconvert/templates/pj", - list(glob.glob('src/pretty_jupyter/templates/pj/*.j2')) - + ["src/pretty_jupyter/templates/pj/conf.json"]) + ("share/jupyter/nbconvert/templates/pj", [ + "src/pretty_jupyter/templates/pj/conf.json", + "src/pretty_jupyter/templates/pj/index.html.j2", + "src/pretty_jupyter/templates/pj/base.html.j2"]) ) data_files.append( - ("share/jupyter/nbconvert/templates/pj/static", - list(glob.glob("src/pretty_jupyter/templates/static/*"))) + ("share/jupyter/nbconvert/templates/pj/static", [ + "src/pretty_jupyter/templates/pj/static/pj.js", + "src/pretty_jupyter/templates/pj/static/pj.css" + ]) ) setuptools.setup( name='pretty-jupyter', author="Jan Palasek", - version='0.1b1', + version='0.2a0', description="", long_description=long_description, long_description_content_type="text/markdown", diff --git a/src/pretty_jupyter/console.py b/src/pretty_jupyter/console.py index f00dcaa..5a79075 100644 --- a/src/pretty_jupyter/console.py +++ b/src/pretty_jupyter/console.py @@ -1,6 +1,5 @@ import os import shutil -import subprocess import sys import click from traitlets.config import Config @@ -34,9 +33,26 @@ def nbconvert(input, out, include_input): file.write(res[0]) +@click.command("install-dev") +def install_dev(): + """ + Installs this package and makes it callable by `jupyter nbconvert` without the need to specify extra_template_basedirs. + """ + src_folder = os.path.join(pkg_resources.resource_filename("pretty_jupyter", "templates"), "pj") + target_folder = os.path.join(sys.prefix, "share/jupyter/nbconvert/templates/pj") + + # for backward compatibility, otherwise copytree has dirs_exist_ok param + if os.path.exists(target_folder): + shutil.rmtree(target_folder) + shutil.copytree(src_folder, target_folder) + + + @click.version_option() @click.group() def cli(): pass + cli.add_command(nbconvert) +cli.add_command(install_dev) diff --git a/src/pretty_jupyter/templates/pj/index.html.j2 b/src/pretty_jupyter/templates/pj/index.html.j2 index e37863a..709b1fb 100644 --- a/src/pretty_jupyter/templates/pj/index.html.j2 +++ b/src/pretty_jupyter/templates/pj/index.html.j2 @@ -76,7 +76,7 @@ {% block notebook_css %} - {{ resources.include_css("static/rmd.css") }} + {{ resources.include_css("static/pj.css") }} {% endblock notebook_css %} {% for css in resources.inlining.css -%} @@ -117,7 +117,7 @@ {% block notebook_js %} - {{ resources.include_js("static/rmd.js") }} + {{ resources.include_js("static/pj.js") }} {% endblock notebook_js %} diff --git a/src/pretty_jupyter/templates/pj/static/rmd.css b/src/pretty_jupyter/templates/pj/static/pj.css similarity index 96% rename from src/pretty_jupyter/templates/pj/static/rmd.css rename to src/pretty_jupyter/templates/pj/static/pj.css index 52220ed..ca9b7f6 100644 --- a/src/pretty_jupyter/templates/pj/static/rmd.css +++ b/src/pretty_jupyter/templates/pj/static/pj.css @@ -1,3 +1,5 @@ +/* a lot of this code was taken from rmd styles directly included in the output html page, license was not present there but it is GPL3 */ + code { white-space: pre-wrap; color: inherit; diff --git a/src/pretty_jupyter/templates/pj/static/rmd.js b/src/pretty_jupyter/templates/pj/static/pj.js similarity index 96% rename from src/pretty_jupyter/templates/pj/static/rmd.js rename to src/pretty_jupyter/templates/pj/static/pj.js index 62c69da..6cb49ed 100644 --- a/src/pretty_jupyter/templates/pj/static/rmd.js +++ b/src/pretty_jupyter/templates/pj/static/pj.js @@ -1,3 +1,5 @@ +/* a lot of this code was taken from rmd styles directly included in the output html page, license was not present there but it is GPL3 */ + // custom preprocessing $(document).ready(function () { diff --git a/tox.ini b/tox.ini index 42d9d98..89bc108 100644 --- a/tox.ini +++ b/tox.ini @@ -12,5 +12,5 @@ python = deps = pytest commands = - pretty-jupyter install + pretty-jupyter install-dev pytest tests/ \ No newline at end of file