azavea / noaa-hydro-data

NOAA Phase 2 Hydrological Data Processing
11 stars 3 forks source link

Add nbautoexport to make reviewing python notebooks easier #72

Closed vlulla closed 2 years ago

vlulla commented 2 years ago

Closes #70 Closes #73

Ensure that you rebuild the docker image after adding nbautoexport to requirements.txt file. scripts/update rebuilds the image. Ensure that the nbautoexport is installed. You can verify this using command -v nbautoexport in the container.

Installing and configuring nbautoexport

nbautoexport works by registering a post_save_hook to do the conversion of ipynb to script files. This registration is done by calling the command nbautoexport install. After the installation, you have to configure where the notebooks are saved. This configuration is done by nbautoexport configure <path of notebooks dir>. Here is the interaction in the container, should you wish to explore this (possibly for other projects using jupyter notebooks):

root@d00505b61bc6:/opt/src # command -v nbautoexport
/srv/conda/envs/notebook/bin/nbautoexport
root@d00505b61bc6:/opt/src # nbautoexport install
nbautoexport post-save hook successfully installed with Jupyter.
If a Jupyter server is already running, you will need to restart it for nbautoexport to work.
root@d00505b61bc6:/opt/src #
root@d00505b61bc6:/opt/src # nbautoexport configure ./notebooks

Since we do not mount the /opt/src directory during the image build process we cannot run the command nbautoexport configure ./notebooks inside the Dockerfile. However, since the command nbautoexport configure just creates a file called .nbautoexport in the directory mentioned, we just create the .nbautoexport file manually.

Now, whenever an ipynb file, in the notebooks directory, is saved a corresponding python script will be stored as a script file in the script directory. Please make sure to include the changed script files, along with the changes to your notebooks, in your commits.

Saved save_nhd_extract.ipynb to generate the corresponding script file in the script directory.

lewfish commented 2 years ago

Also Closes #73

rajadain commented 2 years ago

Taking a look now