|
5 | 5 | import random
|
6 | 6 | import warnings
|
7 | 7 | from _ast import AsyncFunctionDef, ClassDef, FunctionDef
|
| 8 | +from argparse import Namespace |
8 | 9 | from collections import defaultdict
|
9 | 10 | from functools import cache
|
10 | 11 | from pathlib import Path
|
|
26 | 27 | from codeflash.code_utils.git_utils import get_git_diff, get_repo_owner_and_name
|
27 | 28 | from codeflash.code_utils.time_utils import humanize_runtime
|
28 | 29 | from codeflash.discovery.discover_unit_tests import discover_unit_tests
|
29 |
| -from codeflash.models.models import FunctionParent |
| 30 | +from codeflash.models.models import CodeOptimizationContext, FunctionParent |
30 | 31 | from codeflash.telemetry.posthog_cf import ph
|
31 | 32 |
|
32 | 33 | if TYPE_CHECKING:
|
@@ -438,39 +439,32 @@ def was_function_previously_optimized(
|
438 | 439 | Tuple of (filtered_functions_dict, remaining_count)
|
439 | 440 |
|
440 | 441 | """
|
441 |
| - # Check optimization status if repository info is provided |
442 |
| - # already_optimized_count = 0 |
443 | 442 | try:
|
444 | 443 | owner, repo = get_repo_owner_and_name()
|
445 | 444 | except git.exc.InvalidGitRepositoryError:
|
446 | 445 | logger.warning("No git repository found")
|
447 | 446 | owner, repo = None, None
|
448 |
| - pr_number = get_pr_number() |
449 | 447 |
|
450 |
| - if not owner or not repo or pr_number is None or getattr(args, "no_pr", False): |
| 448 | + pr_number = get_pr_number() |
| 449 | + no_pr_flag = getattr(args, "no_pr", False) |
| 450 | + # Short-circuit if info missing |
| 451 | + if not owner or not repo or pr_number is None or no_pr_flag: |
451 | 452 | return False
|
452 | 453 |
|
453 |
| - code_contexts = [] |
454 |
| - |
455 | 454 | func_hash = code_context.hashing_code_context_hash
|
456 |
| - # Use a unique path identifier that includes function info |
457 | 455 |
|
458 |
| - code_contexts.append( |
| 456 | + code_contexts = [ |
459 | 457 | {
|
460 | 458 | "file_path": function_to_optimize.file_path,
|
461 | 459 | "function_name": function_to_optimize.qualified_name,
|
462 | 460 | "code_hash": func_hash,
|
463 | 461 | }
|
464 |
| - ) |
465 |
| - |
466 |
| - if not code_contexts: |
467 |
| - return False |
| 462 | + ] |
468 | 463 |
|
469 | 464 | try:
|
470 | 465 | result = is_function_being_optimized_again(owner, repo, pr_number, code_contexts)
|
471 |
| - already_optimized_paths: list[tuple[str, str]] = result.get("already_optimized_tuples", []) |
| 466 | + already_optimized_paths = result.get("already_optimized_tuples", []) |
472 | 467 | return len(already_optimized_paths) > 0
|
473 |
| - |
474 | 468 | except Exception as e:
|
475 | 469 | logger.warning(f"Failed to check optimization status: {e}")
|
476 | 470 | # Return all functions if API call fails
|
|
0 commit comments