all roads lead to VSC

This commit is contained in:
Kevin Turcios 2025-02-24 14:19:56 -08:00
parent cbf643920a
commit 50873aeb11
6 changed files with 110 additions and 14 deletions

87
codeflash.code-workspace Normal file
View file

@ -0,0 +1,87 @@
{
"folders": [
{
"path": ".",
"name": "codeflash",
"extensions": [
"charliermarsh.ruff",
"ms-python.python",
]
},
{
"path": "docs"
},
{
"path": "tests"
},
{
"path": "code_to_optimize"
}
],
"settings": {
"python.defaultInterpreterPath": "~/miniforge3/envs/dev/bin/python",
"python.terminal.activateEnvironment": true
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "bubble_sort",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder:codeflash}/codeflash/main.py",
"args": [
"--file",
"code_to_optimize/bubble_sort.py",
"--module-root",
"${workspaceFolder:codeflash}",
"--function",
"sorter",
"--test-framework",
"pytest",
"--tests-root",
"code_to_optimize/tests/pytest"
],
"cwd": "${workspaceFolder:codeflash}",
"console": "integratedTerminal",
"env": {
"PYTHONUNBUFFERED": "1"
},
},
{
"name": "bubble_sort -all",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder:codeflash}/codeflash/main.py",
"args": [
"--all",
"--test-framework",
"pytest",
"--tests-root",
"code_to_optimize/tests/pytest",
"--module-root",
"code_to_optimize"
],
"cwd": "${workspaceFolder:codeflash}",
"console": "integratedTerminal",
"env": {
"PYTHONUNBUFFERED": "1"
},
},
{
"name": "bubble_sort --file bubble_sort.py (MBR)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder:codeflash}/codeflash/main.py",
"args": [
"--all",
],
"cwd": "/Users/krrt7/Desktop/work/my-best-repo",
"console": "integratedTerminal",
"env": {
"PYTHONUNBUFFERED": "1"
},
}
]
}
}

View file

@ -29,6 +29,7 @@ class AiServiceClient:
def get_aiservice_base_url(self) -> str:
if os.environ.get("CODEFLASH_AIS_SERVER", default="prod").lower() == "local":
logger.info("Using local AI Service at http://localhost:8000")
console.rule()
return "http://localhost:8000"
return "https://app.codeflash.ai"

View file

@ -1072,7 +1072,6 @@ class FunctionOptimizer:
cwd=self.project_root,
test_env=test_env,
pytest_timeout=INDIVIDUAL_TESTCASE_TIMEOUT,
pytest_cmd=self.test_cfg.pytest_cmd,
verbose=True,
enable_coverage=enable_coverage,
)
@ -1081,8 +1080,8 @@ class FunctionOptimizer:
test_files,
cwd=self.project_root,
test_env=test_env,
pytest_timeout=INDIVIDUAL_TESTCASE_TIMEOUT,
pytest_cmd=self.test_cfg.pytest_cmd,
pytest_timeout=INDIVIDUAL_TESTCASE_TIMEOUT,
pytest_target_runtime_seconds=testing_time,
pytest_min_loops=pytest_min_loops,
pytest_max_loops=pytest_max_loops,

View file

@ -50,9 +50,10 @@ def run_behavioral_tests(
)
else:
test_files.append(str(file.instrumented_behavior_file_path))
pytest_cmd_list = shlex.split(
f"{SAFE_SYS_EXECUTABLE} -m pytest" if pytest_cmd == "pytest" else pytest_cmd, posix=IS_POSIX
)
test_files = list(set(test_files)) # remove multiple calls in the same test function
pytest_cmd_list = shlex.split(pytest_cmd, posix=IS_POSIX)
common_pytest_args = [
"--capture=tee-sys",
f"--timeout={pytest_timeout}",
@ -81,13 +82,16 @@ def run_behavioral_tests(
coverage_cmd = f"{SAFE_SYS_EXECUTABLE} -m coverage run --rcfile={coveragercfile.as_posix()} -m"
results = execute_test_subprocess(
shlex.split(coverage_cmd) + pytest_cmd_list + common_pytest_args + result_args + test_files,
shlex.split(f"{SAFE_SYS_EXECUTABLE} -m coverage run --rcfile={coveragercfile.as_posix()} -m pytest")
+ common_pytest_args
+ result_args
+ test_files,
cwd=cwd,
env=pytest_test_env,
timeout=600,
)
logger.debug(
f"Result return code: {results.returncode}"
+ (f", Result stderr: {results.stderr}" if results.stderr else "")
f"""Result return code: {results.returncode}, {"Result stderr:" + str(results.stderr) if results.stderr else ""}"""
)
else:
results = execute_test_subprocess(
@ -97,8 +101,7 @@ def run_behavioral_tests(
timeout=600, # TODO: Make this dynamic
)
logger.debug(
f"Result return code: {results.returncode}"
+ (f", Result stderr: {results.stderr}" if results.stderr else "")
f"""Result return code: {results.returncode}, {"Result stderr:" + str(results.stderr) if results.stderr else ""}"""
)
elif test_framework == "unittest":
if enable_coverage:
@ -110,8 +113,7 @@ def run_behavioral_tests(
verbose=verbose, test_file_paths=test_files, test_env=test_env, cwd=cwd
)
logger.debug(
f"Result return code: {results.returncode}"
+ (f", Result stderr: {results.stderr}" if results.stderr else "")
f"""Result return code: {results.returncode}, {"Result stderr:" + str(results.stderr) if results.stderr else ""}"""
)
else:
msg = f"Unsupported test framework: {test_framework}"
@ -134,7 +136,11 @@ def run_benchmarking_tests(
pytest_max_loops: int = 100_000,
) -> tuple[Path, subprocess.CompletedProcess]:
if test_framework == "pytest":
pytest_cmd_list = shlex.split(pytest_cmd, posix=IS_POSIX)
pytest_cmd_list = (
shlex.split(f"{SAFE_SYS_EXECUTABLE} -m pytest", posix=IS_POSIX)
if pytest_cmd == "pytest"
else shlex.split(pytest_cmd)
)
test_files: list[str] = []
for file in test_paths.test_files:
if file.test_type in [TestType.REPLAY_TEST, TestType.EXISTING_UNIT_TEST] and file.tests_in_file:

View file

@ -6,6 +6,8 @@ from typing import Optional
from pydantic.dataclasses import dataclass
from codeflash.code_utils.compat import SAFE_SYS_EXECUTABLE
def get_test_file_path(test_dir: Path, function_name: str, iteration: int = 0, test_type: str = "unit") -> Path:
assert test_type in ["unit", "inspired", "replay", "perf"]
@ -74,4 +76,4 @@ class TestConfig:
# tests_project_rootdir corresponds to pytest rootdir,
# or for unittest - project_root_from_module_root(args.tests_root, pyproject_file_path)
concolic_test_root_dir: Optional[Path] = None
pytest_cmd: str = "pytest"
pytest_cmd: str = "pytest"

View file

@ -120,6 +120,7 @@ types-greenlet = "^3.1.0.20241221"
types-pexpect = "^4.9.0.20241208"
types-unidiff = "^0.7.0.20240505"
sqlalchemy = "^2.0.38"
uv = ">=0.6.2"
[tool.poetry.build]
script = "codeflash/update_license_version.py"
@ -221,8 +222,8 @@ module-root = "codeflash"
tests-root = "tests"
test-framework = "pytest"
formatter-cmds = [
"poetry run ruff check --exit-zero --fix $file",
"poetry run ruff format $file",
"uvx ruff check --exit-zero --fix $file",
"uvx ruff format $file",
]