@@ -67,20 +67,27 @@ def init_codeflash() -> None:
6767
6868        did_add_new_key  =  prompt_api_key ()
6969
70-         setup_info :  SetupInfo   =   collect_setup_info () 
70+         if   should_modify_pyproject_toml (): 
7171
72-         configure_pyproject_toml (setup_info )
72+             setup_info : SetupInfo  =  collect_setup_info ()
73+ 
74+             configure_pyproject_toml (setup_info )
7375
7476        install_github_app ()
7577
7678        install_github_actions (override_formatter_check = True )
7779
80+         module_string  =  "" 
81+         if  "setup_info"  in  locals ():
82+             module_string  =  f" you selected ({ setup_info .module_root }  )" 
83+ 
84+ 
7885        click .echo (
7986            f"{ LF }  " 
8087            f"⚡️ Codeflash is now set up! You can now run:{ LF }  " 
8188            f"    codeflash --file <path-to-file> --function <function-name> to optimize a function within a file{ LF }  " 
8289            f"    codeflash --file <path-to-file> to optimize all functions in a file{ LF }  " 
83-             f"    codeflash --all to optimize all functions in all files in the module you selected ( { setup_info . module_root } ) { LF }  " 
90+             f"    codeflash --all to optimize all functions in all files in the module{ module_string } { LF }  " 
8491            f"-or-{ LF }  " 
8592            f"    codeflash --help to see all options{ LF }  " 
8693        )
@@ -116,6 +123,30 @@ def ask_run_end_to_end_test(args: Namespace) -> None:
116123        bubble_sort_path , bubble_sort_test_path  =  create_bubble_sort_file_and_test (args )
117124        run_end_to_end_test (args , bubble_sort_path , bubble_sort_test_path )
118125
126+ def  should_modify_pyproject_toml () ->  bool :
127+     """ 
128+     Check if the current directory contains a valid pyproject.toml file with codeflash config 
129+     If it does, ask the user if they want to re-configure it. 
130+     """ 
131+     from  rich .prompt  import  Confirm 
132+     pyproject_toml_path  =  Path .cwd () /  "pyproject.toml" 
133+     if  not  pyproject_toml_path .exists ():
134+         return  True 
135+     try :
136+         config , config_file_path  =  parse_config_file (pyproject_toml_path )
137+     except  Exception  as  e :
138+         return  True 
139+ 
140+     if  "module_root"  not  in   config  or  config ["module_root" ] is  None  or  not  Path (config ["module_root" ]).is_dir ():
141+         return  True 
142+     if  "tests_root"  not  in   config  or  config ["tests_root" ] is  None  or  not  Path (config ["tests_root" ]).is_dir ():
143+         return  True 
144+ 
145+     create_toml  =  Confirm .ask (
146+         f"✅ A valid Codeflash config already exists in this project. Do you want to re-configure it?" , default = False , show_default = True 
147+     )
148+     return  create_toml 
149+ 
119150
120151def  collect_setup_info () ->  SetupInfo :
121152    curdir  =  Path .cwd ()
0 commit comments