File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -26,3 +26,10 @@ repos:
26
26
rev : 20.8b1
27
27
hooks :
28
28
- id : black
29
+ - repo : local
30
+ hooks :
31
+ - id : watermark
32
+ name : Check notebooks have watermark
33
+ types : [jupyter]
34
+ entry : python scripts/check_watermark.py
35
+ language : python
Original file line number Diff line number Diff line change
1
+ """
2
+ Check that given Jupyter notebooks all contain a final watermark cell to facilite reproducibility.
3
+
4
+ This is intended to be used as a pre-commit hook, see `.pre-commit-config.yaml`.
5
+ You can run it manually with `pre-commit run watermark --all`.
6
+ """
7
+
8
+ import argparse
9
+ from pathlib import Path
10
+ import re
11
+
12
+ if __name__ == "__main__" :
13
+ parser = argparse .ArgumentParser ()
14
+ parser .add_argument ("filenames" , nargs = "*" )
15
+ args = parser .parse_args ()
16
+ for file_ in args .filenames :
17
+ assert (
18
+ re .search (
19
+ r"%load_ext watermark.*%watermark -n -u -v -iv -w" ,
20
+ Path (file_ ).read_text (),
21
+ flags = re .DOTALL ,
22
+ )
23
+ is not None
24
+ ), (
25
+ f"Watermark not found in { file_ } - please see the PyMC3 Jupyter Notebook Style guide:\n "
26
+ "https://github.com/pymc-devs/pymc3/wiki/PyMC's-Jupyter-Notebook-Style"
27
+ )
You can’t perform that action at this time.
0 commit comments