Last active
October 22, 2023 12:25
-
Star
(196)
You must be signed in to star a gist -
Fork
(46)
You must be signed in to fork a gist
-
-
Save pbugnion/ea2797393033b54674af to your computer and use it in GitHub Desktop.
Revisions
-
Pascal Bugnion renamed this gist
Dec 26, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Pascal Bugnion revised this gist
Dec 26, 2014 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ The notebooks themselves are not changed. See also this blogpost: http://pascalbugnion.net/blog/ipython-notebooks-and-git.html. Usage instructions ================== This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,6 @@ This gist lets you keep IPython notebooks in git repositories. It tells git to i To use the script, follow the instructions given in the script's docstring. For further details, read [this blogpost](http://pascalbugnion.net/blog/ipython-notebooks-and-git.html). The procedure outlined here is inspired by [this answer](http://stackoverflow.com/a/20844506/827862) on Stack Overflow. -
Pascal Bugnion revised this gist
Dec 25, 2014 . 2 changed files with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ 4. Connect this script to the filter by running the following git commands: git config --global filter.clean_ipynb.clean ipynb_drop_output git config --global filter.clean_ipynb.smudge cat To tell git to ignore the output and prompts for a notebook, File renamed without changes. -
Pascal Bugnion renamed this gist
Dec 24, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Pascal Bugnion revised this gist
Dec 24, 2014 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
Pascal Bugnion renamed this gist
Dec 24, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Pascal Bugnion renamed this gist
Dec 24, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Pascal Bugnion renamed this gist
Dec 24, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Pascal Bugnion revised this gist
Dec 24, 2014 . 2 changed files with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,4 +3,6 @@ This gist lets you keep IPython notebooks in git repositories. It tells git to i To use the script, follow the instructions given in the script's docstring. For further details, read {{ blogpost }}. The procedure outlined here is inspired by [this answer](http://stackoverflow.com/a/20844506/827862) on Stack Overflow. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,6 +48,13 @@ You may need to "touch" the notebooks for git to actually register a change, if your notebooks are already under version control. Notes ===== This script is inspired by http://stackoverflow.com/a/20844506/827862, but lets the user specify whether the ouptut of a notebook should be suppressed in the notebook's metadata, and works for IPython v3.0. """ import sys -
Pascal Bugnion revised this gist
Dec 24, 2014 . 2 changed files with 24 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ This gist lets you keep IPython notebooks in git repositories. It tells git to ignore prompt numbers and program outputs when checking that a file has changed. To use the script, follow the instructions given in the script's docstring. For further details, read {{ blogpost }}. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,29 +6,31 @@ This script will tell git to ignore prompt numbers and cell output when looking at ipynb files if their metadata contains: "git" : { "suppress_output" : true } The notebooks themselves are not changed. See also {{ blogpost }}. Usage instructions ================== 1. Put this script in a directory that is on the system's path. For future reference, I will assume you saved it in `~/scripts/ipynb_drop_output`. 2. Make sure it is executable by typing the command `chmod +x ~/scripts/ipynb_drop_output`. 3. Register a filter for ipython notebooks by putting the following line in `~/.config/git/attributes`: `*.ipynb filter=clean_ipynb` 4. Connect this script to the filter by running the following git commands: git config --global filter.clean_ipynb.clean ~/scripts/ipynb_drop_output git config --global filter.clean_ipynb.smudge cat To tell git to ignore the output and prompts for a notebook, open the notebook's metadata (Edit > Edit Notebook Metadata). A panel should open containing the lines: { @@ -41,11 +43,11 @@ { "name" : "", "signature" : "don't change the hash, but add a comma at the end of the line", "git" : { "suppress_outputs" : true } } You may need to "touch" the notebooks for git to actually register a change, if your notebooks are already under version control. """ import sys @@ -56,8 +58,8 @@ json_in = json.loads(nb) nb_metadata = json_in["metadata"] suppress_output = False if "git" in nb_metadata: if "suppress_outputs" in nb_metadata["git"] and nb_metadata["git"]["suppress_outputs"]: suppress_output = True if not suppress_output: sys.stdout.write(nb) -
Pascal Bugnion created this gist
Dec 23, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,84 @@ #!/usr/bin/env python """ Suppress output and prompt numbers in git version control. This script will tell git to ignore prompt numbers and cell output when looking at ipynb files if their metadata contains: "vc" : { "suppress_output" : true } The notebooks themselves are not changed. Usage instructions ================== 1. Put this script in a directory that is on the system's path. 2. Make sure it is executable by typing `cd /location/of/script && chmod +x ipynb_output_filter.py` in a terminal. 3. Register a filter for ipython notebooks by creating a `.gitattributes` file in your home directory containing the line: `*.ipynb filter=dropoutput_ipynb` 4. Connect this script to the filter by running the following git commands: git config --global core.attributesfile ~/.gitattributes git config --global filter.dropoutput_ipynb.clean /path/to/script/ipynb_output_filter.py git config --global filter.dropoutput_ipynb.smudge cat To enable this, open the notebook's metadata (Edit > Edit Notebook Metadata). A panel should open containing the lines: { "name" : "", "signature" : "some very long hash" } Add an extra line so that the metadata now looks like: { "name" : "", "signature" : "don't change the hash, but add a comma at the end of the line", "vc" : { "suppress_outputs" : true } } You may need to "touch" the notebooks for git to actually register a change. """ import sys import json nb = sys.stdin.read() json_in = json.loads(nb) nb_metadata = json_in["metadata"] suppress_output = False if "vc" in nb_metadata: if "suppress_outputs" in nb_metadata["vc"] and nb_metadata["vc"]["suppress_outputs"]: suppress_output = True if not suppress_output: sys.stdout.write(nb) exit() ipy_version = int(json_in["nbformat"])-1 # nbformat is 1 more than actual version. def strip_output_from_cell(cell): if "outputs" in cell: cell["outputs"] = [] if "prompt_number" in cell: del cell["prompt_number"] if ipy_version == 2: for sheet in json_in["worksheets"]: for cell in sheet["cells"]: strip_output_from_cell(cell) else: for cell in json_in["cells"]: strip_output_from_cell(cell) json.dump(json_in, sys.stdout, sort_keys=True, indent=1, separators=(",",": "))