Skip to content

Commit

Permalink
Uncommentable section in Dockerfile to autosave .py and .html alongsi…
Browse files Browse the repository at this point in the history
…de .ipynb
  • Loading branch information
ziembla committed Dec 11, 2017
1 parent 8fa96f1 commit bafc41b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
13 changes: 10 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ USER ${username}
WORKDIR ${workdir}


COPY docker/bashrc /tmp/bashrc
RUN cat /tmp/bashrc >> ${home}/.bashrc
COPY docker/bashrc.bash /tmp/
RUN cat /tmp/bashrc.bash >> ${home}/.bashrc
RUN echo "export PATH=\"${workdir}/docker/bin:$PATH\"" >> ${home}/.bashrc
RUN sudo rm /tmp/bashrc
RUN sudo rm /tmp/bashrc.bash


# INFO: Uncomment lines below to enable automatic save of python-only and html-only
# exports alongside the notebook
#COPY docker/jupyter_notebook_config.py /tmp/
#RUN cat /tmp/jupyter_notebook_config.py >> ${home}/.jupyter/jupyter_notebook_config.py
#RUN sudo rm /tmp/jupyter_notebook_config.py

# INFO: Uncomment the RUN command below to disable git diff paging
#RUN git config --global core.pager ''
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions docker/jupyter_notebook_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import subprocess

def export_script_and_view(model, os_path, contents_manager):
if model["type"] != "notebook":
return
dir_name, file_name = os.path.split(os_path)
file_base, file_ext = os.path.splitext(file_name)
if file_base.startswith("Untitled"):
return
export_name = file_base if file_ext == ".ipynb" else file_name
subprocess.check_call(["jupyter", "nbconvert", "--to", "script", file_name, "--output", export_name + "_script"], cwd=dir_name)
subprocess.check_call(["jupyter", "nbconvert", "--to", "html", file_name, "--output", export_name + "_view"], cwd=dir_name)

c.FileContentsManager.post_save_hook = export_script_and_view

0 comments on commit bafc41b

Please sign in to comment.