77import time
88from dataclasses import dataclass , field
99from typing import Optional
10+ import contextlib
11+ import tomllib
1012
1113
1214@dataclass
@@ -82,7 +84,6 @@ def run_codeflash_command(
8284 logging .basicConfig (level = logging .INFO )
8385 if config .trace_mode :
8486 return run_trace_test (cwd , config , expected_improvement_pct )
85-
8687 path_to_file = cwd / config .file_path
8788 file_contents = path_to_file .read_text ("utf-8" )
8889 pytest_dir = cwd / "tests" / "pytest"
@@ -102,7 +103,6 @@ def run_codeflash_command(
102103
103104 return_code = process .wait ()
104105 stdout = "" .join (output )
105-
106106 validated = validate_output (stdout , return_code , expected_improvement_pct , config )
107107 if not validated :
108108 # Write original file contents back to file
@@ -129,7 +129,20 @@ def build_command(
129129
130130 if config .function_name :
131131 base_command .extend (["--function" , config .function_name ])
132- base_command .extend (["--tests-root" , str (test_root ), "--module-root" , str (cwd )])
132+
133+ # Check if pyproject.toml exists with codeflash config - if so, don't override it
134+ pyproject_path = cwd / "pyproject.toml"
135+ has_codeflash_config = False
136+ if pyproject_path .exists ():
137+ with contextlib .suppress (Exception ):
138+ with open (pyproject_path , "rb" ) as f :
139+ pyproject_data = tomllib .load (f )
140+ has_codeflash_config = "tool" in pyproject_data and "codeflash" in pyproject_data ["tool" ]
141+
142+ # Only pass --tests-root and --module-root if they're not configured in pyproject.toml
143+ if not has_codeflash_config :
144+ base_command .extend (["--tests-root" , str (test_root ), "--module-root" , str (cwd )])
145+
133146 if benchmarks_root :
134147 base_command .extend (["--benchmark" , "--benchmarks-root" , str (benchmarks_root )])
135148 if config .use_worktree :
0 commit comments