1111"""
1212
1313import argparse
14- import os
1514import re
1615import subprocess
1716import sys
@@ -50,8 +49,8 @@ def process_pip_installations(markdown_content):
5049 if not packages :
5150 return markdown_content
5251
53- # Deduplicate packages while preserving order
54- unique_packages = " " .join (dict . fromkeys ( packages ))
52+ # Deduplicate packages
53+ unique_packages = " " .join (sorted ( set ( packages ) ))
5554
5655 # Remove code blocks containing pip installs
5756 content = re .sub (r"```python\n(?:[^`])*?%pip install[^\n]*\n(?:[^`])*?```\n?" , "" , markdown_content )
@@ -79,7 +78,7 @@ def process_pip_installations(markdown_content):
7978</CodeGroup>
8079"""
8180
82- lines .insert (min ( line_pos , len ( lines )) , installation_section )
81+ lines .insert (line_pos , installation_section )
8382 return "\n " .join (lines )
8483
8584
@@ -135,17 +134,18 @@ def main():
135134 notebook_path = parser .parse_args ().notebook_path
136135
137136 # Validate notebook path
138- if not os .path .exists (notebook_path ):
137+ notebook_file = Path (notebook_path )
138+ if not notebook_file .exists ():
139139 sys .exit (f"Error: Notebook file not found: { notebook_path } " )
140140
141- if not notebook_path . endswith ( ".ipynb" ) :
141+ if notebook_file . suffix != ".ipynb" :
142142 sys .exit (f"Error: File must be a Jupyter notebook (.ipynb): { notebook_path } " )
143143
144- if not notebook_path .startswith ("examples/" ):
144+ if not str ( notebook_file ) .startswith ("examples/" ):
145145 sys .exit (f"Error: Notebook must be in the examples/ directory: { notebook_path } " )
146146
147147 # Generate output path
148- folder_name = Path ( notebook_path ) .parent .name . replace ( "_examples" , "" )
148+ folder_name = notebook_file .parent .name
149149 output_path = Path (f"docs/v2/examples/{ folder_name } .mdx" )
150150
151151 print (f"Processing: { notebook_path } -> { output_path } " )
@@ -158,7 +158,6 @@ def main():
158158 existing_frontmatter = get_existing_frontmatter (output_path )
159159
160160 if existing_frontmatter :
161- print ("Preserving existing frontmatter with special configurations" )
162161 final_content = generate_mdx_content (notebook_path , processed_content , existing_frontmatter )
163162 else :
164163 print ("Generating new frontmatter and content" )
0 commit comments