Skip to content

Commit e80a054

Browse files
committed
all roads lead to VSC
1 parent c93a7ca commit e80a054

File tree

7 files changed

+115
-21
lines changed

7 files changed

+115
-21
lines changed

codeflash.code-workspace

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"folders": [
3+
{
4+
"path": ".",
5+
"name": "codeflash",
6+
"extensions": [
7+
"charliermarsh.ruff",
8+
"ms-python.python",
9+
]
10+
},
11+
{
12+
"path": "docs"
13+
},
14+
{
15+
"path": "tests"
16+
},
17+
{
18+
"path": "code_to_optimize"
19+
}
20+
],
21+
"settings": {
22+
"python.defaultInterpreterPath": "~/miniforge3/envs/dev/bin/python",
23+
"python.terminal.activateEnvironment": true
24+
},
25+
"launch": {
26+
"version": "0.2.0",
27+
"configurations": [
28+
{
29+
"name": "bubble_sort",
30+
"type": "debugpy",
31+
"request": "launch",
32+
"program": "${workspaceFolder:codeflash}/codeflash/main.py",
33+
"args": [
34+
"--file",
35+
"code_to_optimize/bubble_sort.py",
36+
"--module-root",
37+
"${workspaceFolder:codeflash}",
38+
"--function",
39+
"sorter",
40+
"--test-framework",
41+
"pytest",
42+
"--tests-root",
43+
"code_to_optimize/tests/pytest"
44+
],
45+
"cwd": "${workspaceFolder:codeflash}",
46+
"console": "integratedTerminal",
47+
"env": {
48+
"PYTHONUNBUFFERED": "1"
49+
},
50+
},
51+
{
52+
"name": "bubble_sort -all",
53+
"type": "debugpy",
54+
"request": "launch",
55+
"program": "${workspaceFolder:codeflash}/codeflash/main.py",
56+
"args": [
57+
"--all",
58+
"--test-framework",
59+
"pytest",
60+
"--tests-root",
61+
"code_to_optimize/tests/pytest",
62+
"--module-root",
63+
"code_to_optimize"
64+
],
65+
"cwd": "${workspaceFolder:codeflash}",
66+
"console": "integratedTerminal",
67+
"env": {
68+
"PYTHONUNBUFFERED": "1"
69+
},
70+
},
71+
{
72+
"name": "bubble_sort --file bubble_sort.py (MBR)",
73+
"type": "debugpy",
74+
"request": "launch",
75+
"program": "${workspaceFolder:codeflash}/codeflash/main.py",
76+
"args": [
77+
"--all",
78+
],
79+
"cwd": "/Users/krrt7/Desktop/work/my-best-repo",
80+
"console": "integratedTerminal",
81+
"env": {
82+
"PYTHONUNBUFFERED": "1"
83+
},
84+
}
85+
]
86+
}
87+
}

codeflash/api/aiservice.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self) -> None:
2929
def get_aiservice_base_url(self) -> str:
3030
if os.environ.get("CODEFLASH_AIS_SERVER", default="prod").lower() == "local":
3131
logger.info("Using local AI Service at http://localhost:8000")
32+
console.rule()
3233
return "http://localhost:8000"
3334
return "https://app.codeflash.ai"
3435

codeflash/optimization/function_optimizer.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,7 @@ def establish_original_code_baseline(
855855
)
856856
console.rule()
857857
return Failure("Failed to establish a baseline for the original code - bevhavioral tests failed.")
858-
if not coverage_critic(
859-
coverage_results, self.args.test_framework
860-
):
858+
if not coverage_critic(coverage_results, self.args.test_framework):
861859
return Failure("The threshold for test coverage was not met.")
862860
if test_framework == "pytest":
863861
benchmarking_results, _ = self.run_and_parse_tests(
@@ -898,7 +896,6 @@ def establish_original_code_baseline(
898896
)
899897
console.rule()
900898

901-
902899
total_timing = benchmarking_results.total_passed_runtime() # caution: doesn't handle the loop index
903900
functions_to_remove = [
904901
result.id.test_function_name
@@ -1077,7 +1074,6 @@ def run_and_parse_tests(
10771074
cwd=self.project_root,
10781075
test_env=test_env,
10791076
pytest_timeout=INDIVIDUAL_TESTCASE_TIMEOUT,
1080-
pytest_cmd=self.test_cfg.pytest_cmd,
10811077
verbose=True,
10821078
enable_coverage=enable_coverage,
10831079
)
@@ -1086,8 +1082,8 @@ def run_and_parse_tests(
10861082
test_files,
10871083
cwd=self.project_root,
10881084
test_env=test_env,
1089-
pytest_timeout=INDIVIDUAL_TESTCASE_TIMEOUT,
10901085
pytest_cmd=self.test_cfg.pytest_cmd,
1086+
pytest_timeout=INDIVIDUAL_TESTCASE_TIMEOUT,
10911087
pytest_target_runtime_seconds=testing_time,
10921088
pytest_min_loops=pytest_min_loops,
10931089
pytest_max_loops=pytest_max_loops,
@@ -1097,13 +1093,13 @@ def run_and_parse_tests(
10971093
raise ValueError(f"Unexpected testing type: {testing_type}")
10981094
except subprocess.TimeoutExpired:
10991095
logger.exception(
1100-
f'Error running tests in {", ".join(str(f) for f in test_files.test_files)}.\nTimeout Error'
1096+
f"Error running tests in {', '.join(str(f) for f in test_files.test_files)}.\nTimeout Error"
11011097
)
11021098
return TestResults(), None
11031099
if run_result.returncode != 0 and testing_type == TestingMode.BEHAVIOR:
11041100
logger.debug(
1105-
f'Nonzero return code {run_result.returncode} when running tests in '
1106-
f'{", ".join([str(f.instrumented_behavior_file_path) for f in test_files.test_files])}.\n'
1101+
f"Nonzero return code {run_result.returncode} when running tests in "
1102+
f"{', '.join([str(f.instrumented_behavior_file_path) for f in test_files.test_files])}.\n"
11071103
f"stdout: {run_result.stdout}\n"
11081104
f"stderr: {run_result.stderr}\n"
11091105
)
@@ -1149,4 +1145,3 @@ def generate_and_instrument_tests(
11491145
zip(generated_test_paths, generated_perf_test_paths)
11501146
)
11511147
]
1152-

codeflash/optimization/optimizer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def run(self) -> None:
149149
f"Optimizing function {function_iterator_count} of {num_optimizable_functions}: "
150150
f"{function_to_optimize.qualified_name}"
151151
)
152+
console.rule()
152153

153154
if not (
154155
function_to_optimize_ast := get_first_top_level_function_or_method_ast(

codeflash/verification/test_runner.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ def run_behavioral_tests(
4949
)
5050
else:
5151
test_files.append(str(file.instrumented_behavior_file_path))
52+
pytest_cmd_list = shlex.split(
53+
f"{SAFE_SYS_EXECUTABLE} -m pytest" if pytest_cmd == "pytest" else pytest_cmd, posix=IS_POSIX
54+
)
5255
test_files = list(set(test_files)) # remove multiple calls in the same test function
53-
pytest_cmd_list = shlex.split(pytest_cmd, posix=IS_POSIX)
54-
5556
common_pytest_args = [
5657
"--capture=tee-sys",
5758
f"--timeout={pytest_timeout}",
@@ -78,8 +79,7 @@ def run_behavioral_tests(
7879
logger.debug(cov_erase)
7980

8081
results = execute_test_subprocess(
81-
shlex.split(f"{SAFE_SYS_EXECUTABLE} -m coverage run --rcfile={coveragercfile.as_posix()} -m")
82-
+ pytest_cmd_list
82+
shlex.split(f"{SAFE_SYS_EXECUTABLE} -m coverage run --rcfile={coveragercfile.as_posix()} -m pytest")
8383
+ common_pytest_args
8484
+ result_args
8585
+ test_files,
@@ -88,7 +88,8 @@ def run_behavioral_tests(
8888
timeout=600,
8989
)
9090
logger.debug(
91-
f"""Result return code: {results.returncode}, {"Result stderr:" + str(results.stderr) if results.stderr else ''}""")
91+
f"""Result return code: {results.returncode}, {"Result stderr:" + str(results.stderr) if results.stderr else ""}"""
92+
)
9293
else:
9394
results = execute_test_subprocess(
9495
pytest_cmd_list + common_pytest_args + result_args + test_files,
@@ -97,15 +98,17 @@ def run_behavioral_tests(
9798
timeout=600, # TODO: Make this dynamic
9899
)
99100
logger.debug(
100-
f"""Result return code: {results.returncode}, {"Result stderr:" + str(results.stderr) if results.stderr else ''}""")
101+
f"""Result return code: {results.returncode}, {"Result stderr:" + str(results.stderr) if results.stderr else ""}"""
102+
)
101103
elif test_framework == "unittest":
102104
if enable_coverage:
103105
raise ValueError("Coverage is not supported yet for unittest framework")
104106
test_env["CODEFLASH_LOOP_INDEX"] = "1"
105107
test_files = [file.instrumented_behavior_file_path for file in test_paths.test_files]
106108
result_file_path, results = run_unittest_tests(verbose, test_files, test_env, cwd)
107109
logger.debug(
108-
f"""Result return code: {results.returncode}, {"Result stderr:" + str(results.stderr) if results.stderr else ''}""")
110+
f"""Result return code: {results.returncode}, {"Result stderr:" + str(results.stderr) if results.stderr else ""}"""
111+
)
109112
else:
110113
raise ValueError(f"Unsupported test framework: {test_framework}")
111114

@@ -125,7 +128,11 @@ def run_benchmarking_tests(
125128
pytest_max_loops: int = 100_000,
126129
):
127130
if test_framework == "pytest":
128-
pytest_cmd_list = shlex.split(pytest_cmd, posix=IS_POSIX)
131+
pytest_cmd_list = (
132+
shlex.split(f"{SAFE_SYS_EXECUTABLE} -m pytest", posix=IS_POSIX)
133+
if pytest_cmd == "pytest"
134+
else shlex.split(pytest_cmd)
135+
)
129136
test_files: list[str] = []
130137
for file in test_paths.test_files:
131138
if file.test_type in [TestType.REPLAY_TEST, TestType.EXISTING_UNIT_TEST] and file.tests_in_file:

codeflash/verification/verification_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from pydantic.dataclasses import dataclass
88

9+
from codeflash.code_utils.compat import SAFE_SYS_EXECUTABLE
10+
911

1012
def get_test_file_path(test_dir: Path, function_name: str, iteration: int = 0, test_type: str = "unit") -> Path:
1113
assert test_type in ["unit", "inspired", "replay", "perf"]
@@ -73,4 +75,4 @@ class TestConfig:
7375
# tests_project_rootdir corresponds to pytest rootdir,
7476
# or for unittest - project_root_from_module_root(args.tests_root, pyproject_file_path)
7577
concolic_test_root_dir: Optional[Path] = None
76-
pytest_cmd: str = "pytest"
78+
pytest_cmd: str = "pytest"

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ types-greenlet = "^3.1.0.20241221"
120120
types-pexpect = "^4.9.0.20241208"
121121
types-unidiff = "^0.7.0.20240505"
122122
sqlalchemy = "^2.0.38"
123+
uv = ">=0.6.2"
123124

124125
[tool.poetry.build]
125126
script = "codeflash/update_license_version.py"
@@ -215,8 +216,8 @@ module-root = "codeflash"
215216
tests-root = "tests"
216217
test-framework = "pytest"
217218
formatter-cmds = [
218-
"poetry run ruff check --exit-zero --fix $file",
219-
"poetry run ruff format $file",
219+
"uvx ruff check --exit-zero --fix $file",
220+
"uvx ruff format $file",
220221
]
221222

222223

0 commit comments

Comments
 (0)