Uncommentable section in Dockerfile to autosave .py and .html alongside .ipynb
parent
1d370f4001
commit
60bb0e4e50
|
@ -65,10 +65,17 @@ USER ${username}
|
||||||
WORKDIR ${workdir}
|
WORKDIR ${workdir}
|
||||||
|
|
||||||
|
|
||||||
COPY docker/bashrc /tmp/bashrc
|
COPY docker/bashrc.bash /tmp/
|
||||||
RUN cat /tmp/bashrc >> ${home}/.bashrc
|
RUN cat /tmp/bashrc.bash >> ${home}/.bashrc
|
||||||
RUN echo "export PATH=\"${workdir}/docker/bin:$PATH\"" >> ${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
|
# INFO: Uncomment the RUN command below to disable git diff paging
|
||||||
#RUN git config --global core.pager ''
|
#RUN git config --global core.pager ''
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue