diff --git a/docker/Dockerfile b/docker/Dockerfile index adf97f1..2d24d04 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 '' diff --git a/docker/bashrc b/docker/bashrc.bash similarity index 100% rename from docker/bashrc rename to docker/bashrc.bash diff --git a/docker/jupyter_notebook_config.py b/docker/jupyter_notebook_config.py new file mode 100644 index 0000000..971a49a --- /dev/null +++ b/docker/jupyter_notebook_config.py @@ -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