Skip to content

Commit f5f1040

Browse files
committed
fix formatting issues
1 parent 86bb1b5 commit f5f1040

File tree

3 files changed

+70
-48
lines changed

3 files changed

+70
-48
lines changed

codeflash/api/cfapi.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414

1515
from codeflash.cli_cmds.console import console, logger
1616
from codeflash.code_utils.env_utils import ensure_codeflash_api_key, get_codeflash_api_key, get_pr_number
17-
from codeflash.code_utils.git_utils import get_repo_owner_and_name, git_root_dir, get_current_branch
18-
from codeflash.result.explanation import Explanation
19-
from codeflash.version import __version__
17+
from codeflash.code_utils.git_utils import get_current_branch, get_repo_owner_and_name, git_root_dir
2018
from codeflash.github.PrComment import FileDiffContent, PrComment
19+
from codeflash.version import __version__
2120

2221
if TYPE_CHECKING:
2322
from requests import Response
2423

24+
from codeflash.result.explanation import Explanation
25+
2526
from packaging import version
2627

2728
if os.environ.get("CODEFLASH_CFAPI_SERVER", default="prod").lower() == "local":
@@ -175,8 +176,9 @@ def create_pr(
175176
}
176177
return make_cfapi_request(endpoint="/create-pr", method="POST", payload=payload)
177178

179+
178180
def create_staging(
179-
original_code:str,
181+
original_code: str,
180182
new_code: str,
181183
explanation: Explanation,
182184
existing_tests_source: str,
@@ -204,27 +206,28 @@ def create_staging(
204206
for p in original_code
205207
}
206208
payload = {
207-
"baseBranch": get_current_branch(),
209+
"baseBranch": get_current_branch(),
208210
"diffContents": build_file_changes,
209-
"prCommentFields": PrComment(
210-
optimization_explanation=explanation.explanation_message(),
211-
best_runtime=explanation.best_runtime_ns,
212-
original_runtime=explanation.original_runtime_ns,
213-
function_name=explanation.function_name,
214-
relative_file_path=relative_path,
215-
speedup_x=explanation.speedup_x,
216-
speedup_pct=explanation.speedup_pct,
217-
winning_behavioral_test_results=explanation.winning_behavioral_test_results,
218-
winning_benchmarking_test_results=explanation.winning_benchmarking_test_results,
219-
benchmark_details=explanation.benchmark_details,
220-
).to_json(),
211+
"prCommentFields": PrComment(
212+
optimization_explanation=explanation.explanation_message(),
213+
best_runtime=explanation.best_runtime_ns,
214+
original_runtime=explanation.original_runtime_ns,
215+
function_name=explanation.function_name,
216+
relative_file_path=relative_path,
217+
speedup_x=explanation.speedup_x,
218+
speedup_pct=explanation.speedup_pct,
219+
winning_behavioral_test_results=explanation.winning_behavioral_test_results,
220+
winning_benchmarking_test_results=explanation.winning_benchmarking_test_results,
221+
benchmark_details=explanation.benchmark_details,
222+
).to_json(),
221223
"existingTests": existing_tests_source,
222224
"generatedTests": generated_original_test_source,
223225
"traceId": function_trace_id,
224226
"coverage_message": coverage_message,
225227
}
226228
return make_cfapi_request(endpoint="/create-staging", method="POST", payload=payload)
227229

230+
228231
def is_github_app_installed_on_repo(owner: str, repo: str) -> bool:
229232
"""Check if the Codeflash GitHub App is installed on the specified repository.
230233

codeflash/cli_cmds/cli.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ def parse_args() -> Namespace:
4747
parser.add_argument(
4848
"--no-pr", action="store_true", help="Do not create a PR for the optimization, only update the code locally."
4949
)
50-
parser.add_argument(
51-
"--staging-review",
52-
action="store_true",
53-
help="Upload optimizations to staging for review"
54-
)
50+
parser.add_argument("--staging-review", action="store_true", help="Upload optimizations to staging for review")
5551
parser.add_argument(
5652
"--verify-setup",
5753
action="store_true",

codeflash/optimization/function_optimizer.py

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from rich.tree import Tree
2020

2121
from codeflash.api.aiservice import AiServiceClient, LocalAiServiceClient
22-
from codeflash.api.cfapi import add_code_context_hash, mark_optimization_success, create_staging
22+
from codeflash.api.cfapi import add_code_context_hash, create_staging, mark_optimization_success
2323
from codeflash.benchmarking.utils import process_benchmark_data
2424
from codeflash.cli_cmds.console import code_print, console, logger, progress_bar
2525
from codeflash.code_utils import env_utils
@@ -997,28 +997,50 @@ def find_and_process_best_optimization(
997997
original_code_combined[explanation.file_path] = self.function_to_optimize_source_code
998998
new_code_combined = new_helper_code.copy()
999999
new_code_combined[explanation.file_path] = new_code
1000-
self.process_review(original_code_baseline, best_optimization, generated_tests,
1001-
test_functions_to_remove, concolic_test_str, original_code_combined, new_code_combined,
1002-
explanation, function_to_all_tests, exp_type, original_helper_code)
1000+
self.process_review(
1001+
original_code_baseline,
1002+
best_optimization,
1003+
generated_tests,
1004+
test_functions_to_remove,
1005+
concolic_test_str,
1006+
original_code_combined,
1007+
new_code_combined,
1008+
explanation,
1009+
function_to_all_tests,
1010+
exp_type,
1011+
original_helper_code,
1012+
)
10031013
self.log_successful_optimization(explanation, generated_tests, exp_type)
10041014
return best_optimization
10051015

10061016
def process_review(
1007-
self, original_code_baseline, best_optimization, generated_tests,
1008-
test_functions_to_remove, concolic_test_str, original_code_combined,
1009-
new_code_combined, explanation, function_to_all_tests, exp_type, original_helper_code
1010-
):
1017+
self,
1018+
original_code_baseline: OriginalCodeBaseline,
1019+
best_optimization: BestOptimization,
1020+
generated_tests: GeneratedTestsList,
1021+
test_functions_to_remove: list[str],
1022+
concolic_test_str: str | None,
1023+
original_code_combined: dict[Path, str],
1024+
new_code_combined: dict[Path, str],
1025+
explanation: Explanation,
1026+
function_to_all_tests: dict[str, set[FunctionCalledInTest]],
1027+
exp_type: str,
1028+
original_helper_code: dict[Path, str],
1029+
) -> None:
10111030
coverage_message = (
10121031
original_code_baseline.coverage_results.build_message()
1013-
if original_code_baseline.coverage_results else "Coverage data not available"
1032+
if original_code_baseline.coverage_results
1033+
else "Coverage data not available"
10141034
)
10151035

10161036
generated_tests = remove_functions_from_generated_tests(
10171037
generated_tests=generated_tests, test_functions_to_remove=test_functions_to_remove
10181038
)
10191039

10201040
original_runtime_by_test = original_code_baseline.benchmarking_test_results.usable_runtime_data_by_test_case()
1021-
optimized_runtime_by_test = best_optimization.winning_benchmarking_test_results.usable_runtime_data_by_test_case()
1041+
optimized_runtime_by_test = (
1042+
best_optimization.winning_benchmarking_test_results.usable_runtime_data_by_test_case()
1043+
)
10221044

10231045
generated_tests = add_runtime_comments_to_generated_tests(
10241046
self.test_cfg, generated_tests, original_runtime_by_test, optimized_runtime_by_test
@@ -1038,15 +1060,17 @@ def process_review(
10381060
optimized_runtimes_all=optimized_runtime_by_test,
10391061
)
10401062

1041-
data = dict(
1042-
original_code=original_code_combined,
1043-
new_code=new_code_combined,
1044-
explanation=explanation,
1045-
existing_tests_source=existing_tests,
1046-
generated_original_test_source=generated_tests_str,
1047-
function_trace_id=self.function_trace_id[:-4] + exp_type if self.experiment_id else self.function_trace_id,
1048-
coverage_message=coverage_message,
1049-
)
1063+
data = {
1064+
"original_code": original_code_combined,
1065+
"new_code": new_code_combined,
1066+
"explanation": explanation,
1067+
"existing_tests_source": existing_tests,
1068+
"generated_original_test_source": generated_tests_str,
1069+
"function_trace_id": self.function_trace_id[:-4] + exp_type
1070+
if self.experiment_id
1071+
else self.function_trace_id,
1072+
"coverage_message": coverage_message,
1073+
}
10501074

10511075
if not self.args.no_pr and not self.args.staging_review:
10521076
data["git_remote"] = self.args.git_remote
@@ -1059,13 +1083,12 @@ def process_review(
10591083
trace_id=self.function_trace_id, is_optimization_found=best_optimization is not None
10601084
)
10611085

1062-
if (not self.args.no_pr) or not self.args.staging_review:
1063-
if self.args.all or env_utils.get_pr_number() or (self.args.file and not self.args.function):
1064-
self.write_code_and_helpers(
1065-
self.function_to_optimize_source_code,
1066-
original_helper_code,
1067-
self.function_to_optimize.file_path,
1068-
)
1086+
if ((not self.args.no_pr) or not self.args.staging_review) and (
1087+
self.args.all or env_utils.get_pr_number() or (self.args.file and not self.args.function)
1088+
):
1089+
self.write_code_and_helpers(
1090+
self.function_to_optimize_source_code, original_helper_code, self.function_to_optimize.file_path
1091+
)
10691092

10701093
def establish_original_code_baseline(
10711094
self,

0 commit comments

Comments
 (0)