GithubHelp home page GithubHelp logo

pvphaneuf / dropoutput Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adrn/dropoutput

0.0 2.0 0.0 9 KB

Remove cell numbers and output from IPython notebooks when adding to a git repository

License: MIT License

Python 100.00%

dropoutput's Introduction

Clear Jupyter notebook output on commit

Removes cell numbers and output from IPython notebooks added to a git repository, but leaves the files unchanged.

Note: this only works for notebook versions >= 3

Install

  1. Clone or download this repository. Let's assume you clone it to:

     ~/.config/git/dropoutput/
    
  2. Make sure the drop_ipynb_output.py script is executable, e.g.:

     chmod a+x ~/.config/git/dropoutput/drop_ipynb_output.py
    
  3. Add a git filter for files with .ipynb extensions. Add this to your git attributes file (usually located in ~/.config/git/attributes):

     *.ipynb  filter=clean_ipynb
    
  4. Connect the drop_ipynb_output.py script to the filter:

     git config --global filter.clean_ipynb.clean "~/.config/git/dropoutput/drop_ipynb_output.py %f"
     git config --global filter.clean_ipynb.smudge cat
    

Configuration

By default, this script will tell git to ignore prompt numbers and cell output when adding any .ipynb file to a git repositorie. Note that the notebook files themselves are not changed, this script just filters out the outputs before adding and committing with git.

This default behavior can be changed either on a notebook-by-notebook basis, or for entire paths. To include output for a single notebook, modify the metadata of the notebook (Edit -> Edit Notebook Metadata in the menu bar) and add this line to the metadata:

"git" : { "clear_outputs" : false }

To include output for any notebook that matches a given glob pattern (e.g., for an entire path), you can create and add paths to the file: ~/.config/git/clean_ipynb_ignore. For example, to include output for all notebooks in ~/projects/notebooks that start with "demo", add a line to the ignore file with:

~/projects/notebooks/demo*

Acknowledgements

This code was inspired by this blog post.

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.