Skip to content

Commit 2367160

Browse files
committed
removed prints, added cfapi.py func
1 parent 5760316 commit 2367160

File tree

3 files changed

+16
-38
lines changed

3 files changed

+16
-38
lines changed

codeflash/api/cfapi.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
from functools import lru_cache
88
from pathlib import Path
9-
from typing import TYPE_CHECKING, Any, Optional
9+
from typing import TYPE_CHECKING, Any, Optional, Dict
1010

1111
import requests
1212
import sentry_sdk
@@ -204,18 +204,17 @@ def get_blocklisted_functions() -> dict[str, set[str]] | dict[str, Any]:
204204
return {Path(k).name: {v.replace("()", "") for v in values} for k, values in content.items()}
205205

206206

207-
def is_function_being_optimized_again(code_context: CodeOptimizationContext) -> bool:
207+
def is_function_being_optimized_again(owner: str, repo: str, pr_number: int, code_contexts: dict[str, str]) -> Dict:
208208
"""Check if the function being optimized is being optimized again."""
209-
pr_number = get_pr_number()
210-
if pr_number is None:
211-
# Only want to do this check during GH Actions
212-
return False
213-
owner, repo = get_repo_owner_and_name()
214-
# TODO: Add file paths
215-
rw_context_hash = hashlib.sha256(str(code_context.read_writable_code).encode()).hexdigest()
216-
217-
payload = {"owner": owner, "repo": repo, "pullNumber": pr_number, "code_hash": rw_context_hash}
218-
response = make_cfapi_request(endpoint="/is-function-being-optimized-again", method="POST", payload=payload)
219-
if not response.ok or response.text != "true":
220-
logger.error(f"Error: {response.text}")
221-
return False
209+
response = make_cfapi_request(
210+
"/is-already-optimized",
211+
"POST",
212+
{
213+
"owner": owner,
214+
"repo": repo,
215+
"pr_number": pr_number,
216+
"code_contexts": code_contexts
217+
}
218+
)
219+
response.raise_for_status()
220+
return response.json()

codeflash/discovery/functions_to_optimize.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import libcst as cst
1616
from pydantic.dataclasses import dataclass
1717

18-
from codeflash.api.cfapi import get_blocklisted_functions, make_cfapi_request
18+
from codeflash.api.cfapi import get_blocklisted_functions, make_cfapi_request, is_function_being_optimized_again
1919
from codeflash.cli_cmds.console import DEBUG_MODE, console, logger
2020
from codeflash.code_utils.code_utils import (
2121
is_class_defined_in_file,
@@ -474,7 +474,6 @@ def check_optimization_status(
474474
Returns:
475475
Tuple of (filtered_functions_dict, remaining_count)
476476
"""
477-
logger.info("entering function")
478477
# Build the code_contexts dictionary for the API call
479478
code_contexts = {}
480479
path_to_function_map = {}
@@ -491,23 +490,9 @@ def check_optimization_status(
491490
return {}, 0
492491

493492
try:
494-
# Call the optimization check API
495-
logger.info("Checking status")
496-
response = make_cfapi_request(
497-
"/is-already-optimized",
498-
"POST",
499-
{
500-
"owner": owner,
501-
"repo": repo,
502-
"pr_number": pr_number,
503-
"code_contexts": code_contexts
504-
}
505-
)
506-
response.raise_for_status()
507-
result = response.json()
493+
result = is_function_being_optimized_again(owner, repo, pr_number, code_contexts)
508494
already_optimized_paths = set(result.get("already_optimized_paths", []))
509495

510-
logger.info(f"Found {len(already_optimized_paths)} already optimized functions")
511496

512497
# Filter out already optimized functions
513498
filtered_functions = defaultdict(list)
@@ -522,7 +507,6 @@ def check_optimization_status(
522507

523508
except Exception as e:
524509
logger.warning(f"Failed to check optimization status: {e}")
525-
logger.info("Proceeding with all functions (optimization check failed)")
526510
# Return all functions if API call fails
527511
total_count = sum(len(funcs) for funcs in functions_by_file.values())
528512
return functions_by_file, total_count
@@ -536,7 +520,6 @@ def filter_functions(
536520
module_root: Path,
537521
disable_logs: bool = False,
538522
) -> tuple[dict[Path, list[FunctionToOptimize]], int]:
539-
logger.info("filtering functions boogaloo")
540523
blocklist_funcs = get_blocklisted_functions()
541524
# Remove any function that we don't want to optimize
542525

@@ -601,7 +584,6 @@ def filter_functions(
601584
repository = git.Repo(Path.cwd(), search_parent_directories=True)
602585
owner, repo = get_repo_owner_and_name(repository)
603586
pr_number = get_pr_number()
604-
print(owner, repo, pr_number)
605587
if owner and repo and pr_number is not None:
606588
path_based_functions, functions_count = check_optimization_status(
607589
path_based_functions, owner, repo, pr_number

codeflash/optimization/function_optimizer.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ def optimize_function(self) -> Result[BestOptimization, str]:
145145
if has_any_async_functions(code_context.read_writable_code):
146146
return Failure("Codeflash does not support async functions in the code to optimize.")
147147

148-
if is_function_being_optimized_again(code_context=code_context):
149-
return Failure("This code has already been optimized earlier")
150-
151148
code_print(code_context.read_writable_code)
152149
generated_test_paths = [
153150
get_test_file_path(

0 commit comments

Comments
 (0)