Skip to content

Commit 9a002b7

Browse files
authored
Merge pull request #24 from codeflash-ai/VSC-workspace-integration
all roads lead to VSC
2 parents cbf6439 + 9842651 commit 9a002b7

File tree

7 files changed

+130
-20
lines changed

7 files changed

+130
-20
lines changed

.github/workflows/pr_agent.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
on:
2+
pull_request:
3+
types: [opened, reopened, ready_for_review]
4+
issue_comment:
5+
jobs:
6+
pr_agent_job:
7+
if: ${{ github.event.sender.type != 'Bot' }}
8+
runs-on: ubuntu-latest
9+
permissions:
10+
issues: write
11+
pull-requests: write
12+
contents: write
13+
name: Run pr agent on every pull request, respond to user comments
14+
steps:
15+
- name: PR Agent action step
16+
id: pragent
17+
uses: qodo-ai/pr-agent@main
18+
env:
19+
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

codeflash.code-workspace

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

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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,6 @@ def run_and_parse_tests(
10721072
cwd=self.project_root,
10731073
test_env=test_env,
10741074
pytest_timeout=INDIVIDUAL_TESTCASE_TIMEOUT,
1075-
pytest_cmd=self.test_cfg.pytest_cmd,
10761075
verbose=True,
10771076
enable_coverage=enable_coverage,
10781077
)
@@ -1081,8 +1080,8 @@ def run_and_parse_tests(
10811080
test_files,
10821081
cwd=self.project_root,
10831082
test_env=test_env,
1084-
pytest_timeout=INDIVIDUAL_TESTCASE_TIMEOUT,
10851083
pytest_cmd=self.test_cfg.pytest_cmd,
1084+
pytest_timeout=INDIVIDUAL_TESTCASE_TIMEOUT,
10861085
pytest_target_runtime_seconds=testing_time,
10871086
pytest_min_loops=pytest_min_loops,
10881087
pytest_max_loops=pytest_max_loops,

codeflash/verification/test_runner.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ def run_behavioral_tests(
5050
)
5151
else:
5252
test_files.append(str(file.instrumented_behavior_file_path))
53+
pytest_cmd_list = (
54+
shlex.split(f"{SAFE_SYS_EXECUTABLE} -m pytest", posix=IS_POSIX)
55+
if pytest_cmd == "pytest"
56+
else [SAFE_SYS_EXECUTABLE, "-m", *shlex.split(pytest_cmd, posix=IS_POSIX)]
57+
)
5358
test_files = list(set(test_files)) # remove multiple calls in the same test function
54-
pytest_cmd_list = shlex.split(pytest_cmd, posix=IS_POSIX)
55-
5659
common_pytest_args = [
5760
"--capture=tee-sys",
5861
f"--timeout={pytest_timeout}",
@@ -77,17 +80,19 @@ def run_behavioral_tests(
7780
) # this cleanup is necessary to avoid coverage data from previous runs, if there are any,
7881
# then the current run will be appended to the previous data, which skews the results
7982
logger.debug(cov_erase)
83+
coverage_cmd = [SAFE_SYS_EXECUTABLE, "-m", "coverage", "run", f"--rcfile={coveragercfile.as_posix()}", "-m"]
84+
85+
if pytest_cmd == "pytest":
86+
coverage_cmd.extend(["pytest"])
87+
else:
88+
coverage_cmd.extend(shlex.split(pytest_cmd, posix=IS_POSIX)[1:])
8089

81-
coverage_cmd = f"{SAFE_SYS_EXECUTABLE} -m coverage run --rcfile={coveragercfile.as_posix()} -m"
8290
results = execute_test_subprocess(
83-
shlex.split(coverage_cmd) + pytest_cmd_list + common_pytest_args + result_args + test_files,
84-
cwd=cwd,
85-
env=pytest_test_env,
86-
timeout=600,
91+
coverage_cmd + common_pytest_args + result_args + test_files, cwd=cwd, env=pytest_test_env, timeout=600
8792
)
8893
logger.debug(
89-
f"Result return code: {results.returncode}"
90-
+ (f", Result stderr: {results.stderr}" if results.stderr else "")
94+
f"Result return code: {results.returncode}, "
95+
f"{'Result stderr:' + str(results.stderr) if results.stderr else ''}"
9196
)
9297
else:
9398
results = execute_test_subprocess(
@@ -97,8 +102,7 @@ def run_behavioral_tests(
97102
timeout=600, # TODO: Make this dynamic
98103
)
99104
logger.debug(
100-
f"Result return code: {results.returncode}"
101-
+ (f", Result stderr: {results.stderr}" if results.stderr else "")
105+
f"""Result return code: {results.returncode}, {"Result stderr:" + str(results.stderr) if results.stderr else ""}"""
102106
)
103107
elif test_framework == "unittest":
104108
if enable_coverage:
@@ -110,8 +114,7 @@ def run_behavioral_tests(
110114
verbose=verbose, test_file_paths=test_files, test_env=test_env, cwd=cwd
111115
)
112116
logger.debug(
113-
f"Result return code: {results.returncode}"
114-
+ (f", Result stderr: {results.stderr}" if results.stderr else "")
117+
f"""Result return code: {results.returncode}, {"Result stderr:" + str(results.stderr) if results.stderr else ""}"""
115118
)
116119
else:
117120
msg = f"Unsupported test framework: {test_framework}"
@@ -134,7 +137,11 @@ def run_benchmarking_tests(
134137
pytest_max_loops: int = 100_000,
135138
) -> tuple[Path, subprocess.CompletedProcess]:
136139
if test_framework == "pytest":
137-
pytest_cmd_list = shlex.split(pytest_cmd, posix=IS_POSIX)
140+
pytest_cmd_list = (
141+
shlex.split(f"{SAFE_SYS_EXECUTABLE} -m pytest", posix=IS_POSIX)
142+
if pytest_cmd == "pytest"
143+
else shlex.split(pytest_cmd)
144+
)
138145
test_files: list[str] = []
139146
for file in test_paths.test_files:
140147
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"]
@@ -74,4 +76,4 @@ class TestConfig:
7476
# tests_project_rootdir corresponds to pytest rootdir,
7577
# or for unittest - project_root_from_module_root(args.tests_root, pyproject_file_path)
7678
concolic_test_root_dir: Optional[Path] = None
77-
pytest_cmd: str = "pytest"
79+
pytest_cmd: str = "pytest"

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ exclude = [
6969
[tool.poetry.dependencies]
7070
python = ">=3.9"
7171
unidiff = ">=0.7.4"
72-
pytest = ">=7.0.0"
72+
pytest = ">=7.0.0,<8.3.4"
7373
gitpython = ">=3.1.31"
7474
libcst = ">=1.0.1"
7575
jedi = ">=0.19.1"
@@ -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"
@@ -221,8 +222,8 @@ module-root = "codeflash"
221222
tests-root = "tests"
222223
test-framework = "pytest"
223224
formatter-cmds = [
224-
"poetry run ruff check --exit-zero --fix $file",
225-
"poetry run ruff format $file",
225+
"uvx ruff check --exit-zero --fix $file",
226+
"uvx ruff format $file",
226227
]
227228

228229

0 commit comments

Comments
 (0)