@@ -50,7 +50,14 @@ def convert_notebook(filepath):
5050 cells = []
5151 cell_pattern = re .compile (r'<VSCode\.Cell.*?language="(.*?)".*?>(.*?)</VSCode\.Cell>' , re .DOTALL )
5252
53- for match in cell_pattern .finditer (content ):
53+ matches = list (cell_pattern .finditer (content ))
54+ if not matches :
55+ print (f" WARNING: No cells found in { filepath } " )
56+ return False
57+
58+ print (f" Found { len (matches )} cells" )
59+
60+ for match in matches :
5461 cell_type , cell_content = match .groups ()
5562
5663 if cell_type == "markdown" :
@@ -139,65 +146,6 @@ def convert_notebook(filepath):
139146 print (f" ERROR processing { filepath } : { str (e )} " )
140147 return False
141148
142- def verify_notebooks (directory = "." ):
143- """Check all notebooks are in valid Jupyter format for GitHub"""
144- notebook_files = []
145- for root , dirs , files in os .walk (directory ):
146- if '.git' in dirs :
147- dirs .remove ('.git' )
148- if '.github' in dirs :
149- dirs .remove ('.github' )
150- for file in files :
151- if file .endswith ('.ipynb' ):
152- notebook_files .append (os .path .join (root , file ))
153-
154- print (f"\n Verifying { len (notebook_files )} notebooks for GitHub compatibility" )
155-
156- errors = 0
157- for nb_path in notebook_files :
158- print (f"Checking { nb_path } " )
159- try :
160- with open (nb_path , 'r' , encoding = 'utf-8' ) as f :
161- content = f .read ()
162-
163- # Check if it's still in XML format
164- if '<VSCode.Cell' in content :
165- print (f" ERROR: { nb_path } is still in XML format" )
166- errors += 1
167- continue
168-
169- # Try to load as JSON
170- try :
171- nb_dict = json .loads (content )
172- except json .JSONDecodeError as e :
173- print (f" ERROR: { nb_path } is not valid JSON: { str (e )} " )
174- errors += 1
175- continue
176-
177- # Check for widget state
178- if "widgets" not in nb_dict .get ("metadata" , {}):
179- print (f" WARNING: { nb_path } is missing widget state metadata" )
180-
181- # Validate with nbformat
182- try :
183- validate (nb_dict )
184- print (f" SUCCESS: { nb_path } is valid for GitHub rendering" )
185- except Exception as e :
186- print (f" ERROR: { nb_path } validation failed: { str (e )} " )
187- errors += 1
188-
189- except Exception as e :
190- print (f" ERROR checking { nb_path } : { str (e )} " )
191- errors += 1
192-
193- if errors > 0 :
194- print (f"\n { errors } notebooks may have issues with GitHub rendering" )
195- else :
196- print ("\n All notebooks are properly formatted for GitHub rendering" )
197-
198- return errors
199-
200149if __name__ == "__main__" :
201150 print ("Rendering notebooks for GitHub compatibility..." )
202151 process_notebooks ()
203- verify_notebooks ()
0 commit comments