Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions codeflash/cli_cmds/cmd_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,27 @@ def init_codeflash() -> None:

did_add_new_key = prompt_api_key()

setup_info: SetupInfo = collect_setup_info()
if should_modify_pyproject_toml():

configure_pyproject_toml(setup_info)
setup_info: SetupInfo = collect_setup_info()

configure_pyproject_toml(setup_info)

install_github_app()

install_github_actions(override_formatter_check=True)

module_string = ""
if "setup_info" in locals():
module_string = f" you selected ({setup_info.module_root})"


click.echo(
f"{LF}"
f"⚡️ Codeflash is now set up! You can now run:{LF}"
f" codeflash --file <path-to-file> --function <function-name> to optimize a function within a file{LF}"
f" codeflash --file <path-to-file> to optimize all functions in a file{LF}"
f" codeflash --all to optimize all functions in all files in the module you selected ({setup_info.module_root}){LF}"
f" codeflash --all to optimize all functions in all files in the module{module_string}{LF}"
f"-or-{LF}"
f" codeflash --help to see all options{LF}"
)
Expand Down Expand Up @@ -116,6 +123,30 @@ def ask_run_end_to_end_test(args: Namespace) -> None:
bubble_sort_path, bubble_sort_test_path = create_bubble_sort_file_and_test(args)
run_end_to_end_test(args, bubble_sort_path, bubble_sort_test_path)

def should_modify_pyproject_toml() -> bool:
"""
Check if the current directory contains a valid pyproject.toml file with codeflash config
If it does, ask the user if they want to re-configure it.
"""
from rich.prompt import Confirm
pyproject_toml_path = Path.cwd() / "pyproject.toml"
if not pyproject_toml_path.exists():
return True
try:
config, config_file_path = parse_config_file(pyproject_toml_path)
except Exception as e:
return True

if "module_root" not in config or config["module_root"] is None or not Path(config["module_root"]).is_dir():
return True
if "tests_root" not in config or config["tests_root"] is None or not Path(config["tests_root"]).is_dir():
return True

create_toml = Confirm.ask(
f"✅ A valid Codeflash config already exists in this project. Do you want to re-configure it?", default=False, show_default=True
)
return create_toml


def collect_setup_info() -> SetupInfo:
curdir = Path.cwd()
Expand Down
2 changes: 1 addition & 1 deletion codeflash/code_utils/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def parse_config_file(config_file_path: Path | None = None, override_formatter_c
"In pyproject.toml, Codeflash only supports the 'test-framework' as pytest and unittest."
)
if len(config["formatter-cmds"]) > 0:
#see if this is happening during Github actions setup
#see if this is happening during GitHub actions setup
if not override_formatter_check:
assert config["formatter-cmds"][0] != "your-formatter $file", (
"The formatter command is not set correctly in pyproject.toml. Please set the "
Expand Down
Loading