Skip to content

Commit 78fac69

Browse files
committed
Cached output filter
1 parent 4379966 commit 78fac69

7 files changed

+15
-16
lines changed

Diff for: .gitattributes

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
*.ipynb filter=nbfilter
21
*.ipynb filter=cached-output

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@ auto
2424
# Compressed files for upload
2525
generated
2626

27+
# Cached output
28+
.nb_output_cache
29+
2730
# Misc
2831
.DS_Store

Diff for: scripts/__init__.py

Whitespace-only changes.

Diff for: scripts/cache_filter_clean.sh

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
data=$(cat)
21
temp_out=$(mktemp)
3-
echo "$data" > $temp_out.ipynb
4-
jupyter nbconvert --to notebook --config convert_config.py $temp_out.ipynb --output $temp_out.ipynb
5-
jupyter nbconvert --to notebook --ClearOutputPreprocessor.enabled=True $temp_out.ipynb --output $temp_out.ipynb
6-
data=$(<$temp_out.ipynb)
7-
echo "$data"
2+
cat > $temp_out.ipynb
3+
jupyter nbconvert --to notebook --config scripts/convert_config.py $temp_out.ipynb --output $temp_out.ipynb 1>&2
4+
jupyter nbconvert --to notebook --ClearOutputPreprocessor.enabled=True $temp_out.ipynb --output $temp_out.ipynb 1>&2
5+
cat $temp_out.ipynb

Diff for: scripts/cache_filter_smudge.sh

100644100755
+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
data=$(cat)
21
temp_out=$(mktemp)
3-
echo "$data" > $temp_out.ipynb
4-
jupyter trust $temp_out.ipynb
5-
jupyter nbconvert --to notebook --config convert_config.py $temp_out.ipynb --output $temp_out.ipynb
6-
data=$(<$temp_out.ipynb)
7-
echo "$data"
2+
cat > $temp_out.ipynb
3+
jupyter nbconvert --to notebook --config scripts/convert_config.py $temp_out.ipynb --output $temp_out.ipynb 1>&2
4+
jupyter trust $temp_out.ipynb > /dev/null
5+
cat $temp_out.ipynb

Diff for: scripts/cachedoutput.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ class CachedOutputPreprocessor(ExecutePreprocessor):
7171
Output is stored in a cache directory, and only recomputed if needed.
7272
"""
7373

74-
#cache_directory = Unicode('/tmp/nb_output_cache', config=True)
75-
cache_directory = Unicode(os.path.abspath("../.nb_output_cache"), config=True)
74+
cache_directory = Unicode('/tmp/nb_output_cache', config=True)
7675

7776
setup_cells = Integer(1, config=True,
7877
help="""The number of code cells at the beginning of the notebook to use as setup for other cells.

Diff for: scripts/convert_config.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import os
12
c = get_config()
23

3-
c.Exporter.preprocessors = ['cachedoutput.CachedOutputPreprocessor']
4+
c.Exporter.preprocessors = ['scripts.cachedoutput.CachedOutputPreprocessor']
45
c.CachedOutputPreprocessor['enabled'] = True
6+
c.CachedOutputPreprocessor.cache_directory = os.path.abspath(".nb_output_cache")

0 commit comments

Comments
 (0)