Skip to content

Commit 5a34697

Browse files
committed
Merge branch 'main' into codeflash-trace-decorator
2 parents 56e3447 + 778a213 commit 5a34697

File tree

4 files changed

+65
-32
lines changed

4 files changed

+65
-32
lines changed

codeflash/cli_cmds/cmd_init.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

120151
def collect_setup_info() -> SetupInfo:
121152
curdir = Path.cwd()

codeflash/code_utils/config_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def parse_config_file(config_file_path: Path | None = None, override_formatter_c
8585
"In pyproject.toml, Codeflash only supports the 'test-framework' as pytest and unittest."
8686
)
8787
if len(config["formatter-cmds"]) > 0:
88-
#see if this is happening during Github actions setup
88+
#see if this is happening during GitHub actions setup
8989
if not override_formatter_check:
9090
assert config["formatter-cmds"][0] != "your-formatter $file", (
9191
"The formatter command is not set correctly in pyproject.toml. Please set the "
Lines changed: 15 additions & 14 deletions
Loading

0 commit comments

Comments
 (0)