Code Monkey home page Code Monkey logo

jupyter-githook-sample's Introduction

Jupyter Notebook Pre-Commit Git Hook Sample

Data science projects often start with using jupyter notebooks for exploration. When sharing results with others, it helps to have the python code separate from generated plots and plots separated from the code when sharing visualizations to others. Using a pre-commit githook to capture plots and code separately allows data science projects to be more organized and more easily be transitioned from exploration to production.

Git Hooks are scripts you can put in a hooks directory. In this case, we decided to use .githooks as our hooks directory. The hooks will trigger actions at certain points in git’s execution.

For example, the pre-commit, is invoked before obtaining the proposed commit log message and making a commit.

Setup Requirements

  • Git version >=2.9 installed on your system.
  • Filenames must not contain spaces.
  • jq

Setup

Create an .env file and specify NOTEBOOKS_PATH, SCRIPTS_PATH, and HTML_PATH.

For example:

export NOTEBOOKS_PATH="notebooks"
export SCRIPTS_PATH="scripts"
export HTML_PATH="html"

Run:

source .env
make

This will set up the git hooks directory to point to a directory called .githooks. Now, whenever you commit, the pre-commit hook will run.

Add and commit your changed notebook files to git.

git add .
git commit -m "Added iris exploration notebook."

FAQ

If you encounter an error when saving .ipynb file as a script, such as mv: cannot stat 'notebooks/iris_exploration.py': No such file or directory, you should restart the jupyter server and try again.

jupyter-githook-sample's People

Contributors

smarker avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

clmccart

jupyter-githook-sample's Issues

Allow for configurable directory structure.

Currently, the pre-commit hook requires that you have a notebooks, scripts, and html folders at the root of the project. It would be nice to allow the user to specify where the .ipynb plot/code outputs should go.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.