File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 3636
3737logger = logging .getLogger (__name__ )
3838
39- __version__ = "0.4.2 "
39+ __version__ = "0.4.3 "
4040
4141
4242def _get_dynamic_version () -> str :
Original file line number Diff line number Diff line change 1+ import os
2+ import json
3+ import sys
4+
5+
6+ def clean_tqdm_bars_in_notebook (file_path ):
7+ with open (file_path , 'r' , encoding = 'utf-8' ) as f :
8+ notebook = json .load (f )
9+
10+ modified = False
11+ for cell in notebook .get ('cells' , []):
12+ if cell .get ('cell_type' ) == 'code' :
13+ original_outputs = cell .get ('outputs' , [])
14+ cleaned_outputs = [
15+ output for output in original_outputs
16+ if "data" not in output or 'application/vnd.jupyter.widget-view+json' not in output ['data' ]
17+ ]
18+ if len (cleaned_outputs ) != len (original_outputs ):
19+ cell ['outputs' ] = cleaned_outputs
20+ modified = True
21+
22+ if modified :
23+ with open (file_path , 'w' , encoding = 'utf-8' ) as f :
24+ json .dump (notebook , f , indent = 1 )
25+ print (f"Cleaned tqdm bars in: { file_path } " )
26+ else :
27+ print (f"No tqdm bars found in: { file_path } " )
28+
29+
30+ if __name__ == "__main__" :
31+ if len (sys .argv ) != 2 :
32+ print ("Usage: python clean_tqdm_bars.py <path_to_folder_with_notebooks>" )
33+ sys .exit (1 )
34+
35+ notebook_folder = sys .argv [1 ]
36+ for filename in os .listdir (notebook_folder ):
37+ if filename .endswith (".ipynb" ):
38+ clean_tqdm_bars_in_notebook (os .path .join (notebook_folder , filename ))
You can’t perform that action at this time.
0 commit comments