@@ -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
76- install_github_actions ()
78+ install_github_actions (override_formatter_check = True )
79+
80+ module_string = ""
81+ if "setup_info" in locals ():
82+ module_string = f" you selected ({ setup_info .module_root } )"
83+
7784
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 ()
@@ -362,9 +393,9 @@ def check_for_toml_or_setup_file() -> str | None:
362393 return cast (str , project_name )
363394
364395
365- def install_github_actions () -> None :
396+ def install_github_actions (override_formatter_check : bool = False ) -> None :
366397 try :
367- config , config_file_path = parse_config_file ()
398+ config , config_file_path = parse_config_file (override_formatter_check = override_formatter_check )
368399
369400 ph ("cli-github-actions-install-started" )
370401 try :
@@ -504,11 +535,11 @@ def get_dependency_manager_installation_string(dep_manager: DependencyManager) -
504535 py_version = sys .version_info
505536 python_version_string = f"'{ py_version .major } .{ py_version .minor } '"
506537 if dep_manager == DependencyManager .UV :
507- return """name: Setup UV
538+ return """name: 🐍 Setup UV
508539 uses: astral-sh/setup-uv@v4
509540 with:
510541 enable-cache: true"""
511- return f"""name: Set up Python
542+ return f"""name: 🐍 Set up Python
512543 uses: actions/setup-python@v5
513544 with:
514545 python-version: { python_version_string } """
0 commit comments