... | ... |
@@ -14,19 +14,25 @@ from nbconvert.preprocessors import Preprocessor |
14 | 14 |
|
15 | 15 |
class RemoveMetadata(Preprocessor): |
16 | 16 |
def preprocess(self, nb, resources): |
17 |
- nb.metadata = {"language_info": {"name":"python", |
|
18 |
- "pygments_lexer": "ipython3"}} |
|
17 |
+ nb.metadata = { |
|
18 |
+ "language_info": {"name": "python", "pygments_lexer": "ipython3"} |
|
19 |
+ } |
|
19 | 20 |
return nb, resources |
20 | 21 |
|
21 | 22 |
|
22 |
-if __name__ == '__main__': |
|
23 |
+if __name__ == "__main__": |
|
23 | 24 |
# The filter is getting activated |
24 | 25 |
import os |
26 |
+ |
|
25 | 27 |
git_cmd = 'git config filter.ipynb_filter.clean "jupyter nbconvert --to notebook --config ipynb_filter.py --stdin --stdout"' |
26 | 28 |
os.system(git_cmd) |
27 | 29 |
else: |
28 | 30 |
# This script is used as config |
29 |
- c.Exporter.preprocessors = [RemoveMetadata] |
|
30 |
- c.ClearOutputPreprocessor.enabled = True |
|
31 |
- c.ClearOutputPreprocessor.remove_metadata_fields = [ |
|
32 |
- "deletable", "editable", "collapsed", "scrolled"] |
|
31 |
+ c.Exporter.preprocessors = [RemoveMetadata] # noqa: F821 |
|
32 |
+ c.ClearOutputPreprocessor.enabled = True # noqa: F821 |
|
33 |
+ c.ClearOutputPreprocessor.remove_metadata_fields = [ # noqa: F821 |
|
34 |
+ "deletable", |
|
35 |
+ "editable", |
|
36 |
+ "collapsed", |
|
37 |
+ "scrolled", |
|
38 |
+ ] |
1 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,32 @@ |
1 |
+#!/usr/bin/env python3 |
|
2 |
+ |
|
3 |
+# `ipynb_filter.py`: |
|
4 |
+# This is a git filters that strips out the outputs and |
|
5 |
+# meta data of a Jupyer notebook using `nbconvert`. |
|
6 |
+# Execute the following line in order to activate this filter: |
|
7 |
+# python ipynb_filter.py |
|
8 |
+# |
|
9 |
+# The following line should be in `.gitattributes`: |
|
10 |
+# *.ipynb filter=ipynb_filter |
|
11 |
+ |
|
12 |
+from nbconvert.preprocessors import Preprocessor |
|
13 |
+ |
|
14 |
+ |
|
15 |
+class RemoveMetadata(Preprocessor): |
|
16 |
+ def preprocess(self, nb, resources): |
|
17 |
+ nb.metadata = {"language_info": {"name":"python", |
|
18 |
+ "pygments_lexer": "ipython3"}} |
|
19 |
+ return nb, resources |
|
20 |
+ |
|
21 |
+ |
|
22 |
+if __name__ == '__main__': |
|
23 |
+ # The filter is getting activated |
|
24 |
+ import os |
|
25 |
+ git_cmd = 'git config filter.ipynb_filter.clean "jupyter nbconvert --to notebook --config ipynb_filter.py --stdin --stdout"' |
|
26 |
+ os.system(git_cmd) |
|
27 |
+else: |
|
28 |
+ # This script is used as config |
|
29 |
+ c.Exporter.preprocessors = [RemoveMetadata] |
|
30 |
+ c.ClearOutputPreprocessor.enabled = True |
|
31 |
+ c.ClearOutputPreprocessor.remove_metadata_fields = [ |
|
32 |
+ "deletable", "editable", "collapsed", "scrolled"] |