Skip to content

Commit 1871a87

Browse files
Merge branch 'main' into fix/handle-new-added-classes
2 parents 74122b6 + 827cf36 commit 1871a87

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

codeflash/code_utils/formatter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import subprocess
99
import tempfile
1010
from pathlib import Path
11-
from typing import Optional, Union
11+
from typing import Any, Optional, Union
1212

1313
import isort
1414

@@ -163,10 +163,10 @@ def format_code(
163163
return formatted_code
164164

165165

166-
def sort_imports(code: str, *, float_to_top: bool = False) -> str:
166+
def sort_imports(code: str, **kwargs: Any) -> str: # noqa : ANN401
167167
try:
168168
# Deduplicate and sort imports, modify the code in memory, not on disk
169-
sorted_code = isort.code(code=code, float_to_top=float_to_top)
169+
sorted_code = isort.code(code, **kwargs)
170170
except Exception: # this will also catch the FileSkipComment exception, use this fn everywhere
171171
logger.exception("Failed to sort imports with isort.")
172172
return code # Fall back to original code if isort fails

codeflash/code_utils/instrument_existing_tests.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from pathlib import Path
77
from typing import TYPE_CHECKING
88

9-
import isort
109
import libcst as cst
1110

1211
from codeflash.cli_cmds.console import logger
@@ -741,7 +740,7 @@ def inject_async_profiling_into_existing_test(
741740
new_imports.append(ast.Import(names=[ast.alias(name="timeout_decorator")]))
742741

743742
tree.body = [*new_imports, *tree.body]
744-
return True, isort.code(ast.unparse(tree), float_to_top=True)
743+
return True, sort_imports(ast.unparse(tree), float_to_top=True)
745744

746745

747746
def inject_profiling_into_existing_test(
@@ -789,7 +788,7 @@ def inject_profiling_into_existing_test(
789788
additional_functions = [create_wrapper_function(mode)]
790789

791790
tree.body = [*new_imports, *additional_functions, *tree.body]
792-
return True, isort.code(ast.unparse(tree), float_to_top=True)
791+
return True, sort_imports(ast.unparse(tree), float_to_top=True)
793792

794793

795794
def create_wrapper_function(mode: TestingMode = TestingMode.BEHAVIOR) -> ast.FunctionDef:

tests/test_instrumentation_run_results_aiservice.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import isort
99
from code_to_optimize.bubble_sort_method import BubbleSorter
1010
from codeflash.code_utils.code_utils import get_run_tmp_file
11+
from codeflash.code_utils.formatter import sort_imports
1112
from codeflash.discovery.functions_to_optimize import FunctionToOptimize
1213
from codeflash.models.models import FunctionParent, TestFile, TestFiles, TestingMode, TestType, VerificationType
1314
from codeflash.optimization.optimizer import Optimizer
@@ -115,7 +116,7 @@ def test_single_element_list():
115116
)
116117
"""
117118
)
118-
instrumented_behavior_test_source = isort.code(
119+
instrumented_behavior_test_source = sort_imports(
119120
instrumented_behavior_test_source, config=isort.Config(float_to_top=True)
120121
)
121122

@@ -257,7 +258,7 @@ def test_single_element_list():
257258
)
258259
"""
259260
)
260-
instrumented_behavior_test_source = isort.code(
261+
instrumented_behavior_test_source = sort_imports(
261262
instrumented_behavior_test_source, config=isort.Config(float_to_top=True)
262263
)
263264

0 commit comments

Comments
 (0)