Skip to content

Commit baee96e

Browse files
authored
Merge pull request #620 from codeflash-ai/pre-commit-update
Pre commit update
2 parents 8cb4172 + 9f9fc30 commit baee96e

File tree

8 files changed

+24
-21
lines changed

8 files changed

+24
-21
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
repos:
2-
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: "v0.11.0"
4-
hooks:
5-
- id: ruff
6-
args: [--fix, --exit-non-zero-on-fix, --config=pyproject.toml]
7-
- id: ruff-format
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.12.7
4+
hooks:
5+
# Run the linter.
6+
- id: ruff-check
7+
# Run the formatter.
8+
- id: ruff-format

codeflash/benchmarking/instrument_codeflash_trace.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ def leave_ClassDef(
3232
def visit_ClassDef(self, node: ClassDef) -> Optional[bool]:
3333
if self.class_name: # Don't go into nested class
3434
return False
35-
self.class_name = node.name.value # noqa: RET503
35+
self.class_name = node.name.value
36+
return None
3637

3738
def visit_FunctionDef(self, node: FunctionDef) -> Optional[bool]:
3839
if self.function_name: # Don't go into nested function
3940
return False
40-
self.function_name = node.name.value # noqa: RET503
41+
self.function_name = node.name.value
42+
return None
4143

4244
def leave_FunctionDef(self, original_node: FunctionDef, updated_node: FunctionDef) -> FunctionDef:
4345
if self.function_name == original_node.name.value:

codeflash/cli_cmds/cmd_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from argparse import Namespace
3939

4040
CODEFLASH_LOGO: str = (
41-
f"{LF}" # noqa: ISC003
41+
f"{LF}"
4242
r" _ ___ _ _ " + f"{LF}"
4343
r" | | / __)| | | | " + f"{LF}"
4444
r" ____ ___ _ | | ____ | |__ | | ____ ___ | | _ " + f"{LF}"

codeflash/models/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def unique_invocation_loop_id(self) -> str:
480480
return f"{self.loop_index}:{self.id.id()}"
481481

482482

483-
class TestResults(BaseModel):
483+
class TestResults(BaseModel): # noqa: PLW1641
484484
# don't modify these directly, use the add method
485485
# also we don't support deletion of test results elements - caution is advised
486486
test_results: list[FunctionTestInvocation] = []

codeflash/result/critic.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Optional
3+
from typing import TYPE_CHECKING
44

55
from codeflash.cli_cmds.console import logger
66
from codeflash.code_utils import env_utils
@@ -29,7 +29,8 @@ def speedup_critic(
2929
candidate_result: OptimizedCandidateResult,
3030
original_code_runtime: int,
3131
best_runtime_until_now: int | None,
32-
disable_gh_action_noise: Optional[bool] = None,
32+
*,
33+
disable_gh_action_noise: bool = False,
3334
) -> bool:
3435
"""Take in a correct optimized Test Result and decide if the optimization should actually be surfaced to the user.
3536
@@ -39,10 +40,8 @@ def speedup_critic(
3940
The noise floor is doubled when benchmarking on a (noisy) GitHub Action virtual instance, also we want to be more confident there.
4041
"""
4142
noise_floor = 3 * MIN_IMPROVEMENT_THRESHOLD if original_code_runtime < 10000 else MIN_IMPROVEMENT_THRESHOLD
42-
if not disable_gh_action_noise:
43-
in_github_actions_mode = bool(env_utils.get_pr_number())
44-
if in_github_actions_mode:
45-
noise_floor = noise_floor * 2 # Increase the noise floor in GitHub Actions mode
43+
if not disable_gh_action_noise and env_utils.is_ci():
44+
noise_floor = noise_floor * 2 # Increase the noise floor in GitHub Actions mode
4645

4746
perf_gain = performance_gain(
4847
original_runtime_ns=original_code_runtime, optimized_runtime_ns=candidate_result.best_test_runtime

codeflash/verification/parse_test_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def parse_test_xml(
271271
groups = match.groups()
272272
if len(groups[5].split(":")) > 1:
273273
iteration_id = groups[5].split(":")[0]
274-
groups = groups[:5] + (iteration_id,)
274+
groups = (*groups[:5], iteration_id)
275275
end_matches[groups] = match
276276

277277
if not begin_matches or not begin_matches:

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ ignore = [
239239
"D104",
240240
"PERF203",
241241
"LOG015",
242-
"PLC0415"
242+
"PLC0415",
243+
"UP045"
243244
]
244245

245246
[tool.ruff.lint.flake8-type-checking]

tests/test_critic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_speedup_critic() -> None:
4141
total_candidate_timing=12,
4242
)
4343

44-
assert speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now, True) # 20% improvement
44+
assert speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now, disable_gh_action_noise=True) # 20% improvement
4545

4646
candidate_result = OptimizedCandidateResult(
4747
max_loop_count=5,
@@ -52,7 +52,7 @@ def test_speedup_critic() -> None:
5252
optimization_candidate_index=0,
5353
)
5454

55-
assert not speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now, True) # 6% improvement
55+
assert not speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now, disable_gh_action_noise=True) # 6% improvement
5656

5757
original_code_runtime = 100000
5858
best_runtime_until_now = 100000
@@ -66,7 +66,7 @@ def test_speedup_critic() -> None:
6666
optimization_candidate_index=0,
6767
)
6868

69-
assert speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now, True) # 6% improvement
69+
assert speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now, disable_gh_action_noise=True) # 6% improvement
7070

7171

7272
def test_generated_test_critic() -> None:

0 commit comments

Comments
 (0)