mirror of
https://github.com/codeflash-ai/codeflash.git
synced 2026-05-04 18:25:17 +00:00
refactor: move code_extractor, code_replacer to languages/python/static_analysis/
This commit is contained in:
parent
ae2ee47142
commit
ef99747697
16 changed files with 22 additions and 22 deletions
|
|
@ -10,7 +10,7 @@ from typing import TYPE_CHECKING
|
|||
import libcst as cst
|
||||
|
||||
from codeflash.cli_cmds.console import logger
|
||||
from codeflash.code_utils.code_extractor import add_needed_imports_from_module, find_preexisting_objects
|
||||
from codeflash.languages.python.static_analysis.code_extractor import add_needed_imports_from_module, find_preexisting_objects
|
||||
from codeflash.code_utils.code_utils import encoded_tokens_len, get_qualified_name, path_belongs_to_site_packages
|
||||
from codeflash.code_utils.config_consts import OPTIMIZATION_CONTEXT_TOKEN_LIMIT, TESTGEN_CONTEXT_TOKEN_LIMIT
|
||||
from codeflash.discovery.functions_to_optimize import FunctionToOptimize # noqa: TC001
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from typing import TYPE_CHECKING, Optional, Union
|
|||
import libcst as cst
|
||||
|
||||
from codeflash.cli_cmds.console import logger
|
||||
from codeflash.code_utils.code_replacer import replace_function_definitions_in_module
|
||||
from codeflash.languages.python.static_analysis.code_replacer import replace_function_definitions_in_module
|
||||
from codeflash.languages import is_javascript
|
||||
from codeflash.models.models import CodeString, CodeStringsMarkdown
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import libcst as cst
|
|||
from libcst.metadata import PositionProvider
|
||||
|
||||
from codeflash.cli_cmds.console import logger
|
||||
from codeflash.code_utils.code_extractor import (
|
||||
from codeflash.languages.python.static_analysis.code_extractor import (
|
||||
add_global_assignments,
|
||||
add_needed_imports_from_module,
|
||||
find_insertion_index_after_imports,
|
||||
|
|
@ -379,7 +379,7 @@ class PythonSupport:
|
|||
Modified source code with function replaced.
|
||||
|
||||
"""
|
||||
from codeflash.code_utils.code_replacer import replace_functions_in_file
|
||||
from codeflash.languages.python.static_analysis.code_replacer import replace_functions_in_file
|
||||
|
||||
try:
|
||||
# Determine the function names to replace
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ from codeflash.api.cfapi import add_code_context_hash, create_staging, get_cfapi
|
|||
from codeflash.benchmarking.utils import process_benchmark_data
|
||||
from codeflash.cli_cmds.console import code_print, console, logger, lsp_log, progress_bar
|
||||
from codeflash.code_utils import env_utils
|
||||
from codeflash.code_utils.code_extractor import get_opt_review_metrics, is_numerical_code
|
||||
from codeflash.code_utils.code_replacer import (
|
||||
from codeflash.languages.python.static_analysis.code_extractor import get_opt_review_metrics, is_numerical_code
|
||||
from codeflash.languages.python.static_analysis.code_replacer import (
|
||||
add_custom_marker_to_all_tests,
|
||||
modify_autouse_fixture,
|
||||
replace_function_definitions_in_module,
|
||||
|
|
|
|||
|
|
@ -293,7 +293,7 @@ class Optimizer:
|
|||
def prepare_module_for_optimization(
|
||||
self, original_module_path: Path
|
||||
) -> tuple[dict[Path, ValidCode], ast.Module | None] | None:
|
||||
from codeflash.code_utils.code_replacer import normalize_code, normalize_node
|
||||
from codeflash.languages.python.static_analysis.code_replacer import normalize_code, normalize_node
|
||||
from codeflash.languages.python.static_analysis.static_analysis import analyze_imported_modules
|
||||
|
||||
logger.info(f"loading|Examining file {original_module_path!s}")
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import git
|
|||
from codeflash.api import cfapi
|
||||
from codeflash.cli_cmds.console import console, logger
|
||||
from codeflash.code_utils import env_utils
|
||||
from codeflash.code_utils.code_replacer import is_zero_diff
|
||||
from codeflash.languages.python.static_analysis.code_replacer import is_zero_diff
|
||||
from codeflash.code_utils.git_utils import check_and_push_branch, get_current_branch, get_repo_owner_and_name
|
||||
from codeflash.code_utils.github_utils import github_pr_url
|
||||
from codeflash.code_utils.tabulate import tabulate
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ from pathlib import Path
|
|||
|
||||
import libcst as cst
|
||||
|
||||
from codeflash.code_utils.code_extractor import (
|
||||
from codeflash.languages.python.static_analysis.code_extractor import (
|
||||
DottedImportCollector,
|
||||
add_needed_imports_from_module,
|
||||
find_preexisting_objects,
|
||||
resolve_star_import,
|
||||
)
|
||||
from codeflash.code_utils.code_replacer import replace_functions_and_add_imports
|
||||
from codeflash.languages.python.static_analysis.code_replacer import replace_functions_and_add_imports
|
||||
from codeflash.models.models import FunctionParent
|
||||
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ import jedi
|
|||
import tiktoken
|
||||
from jedi.api.classes import Name
|
||||
from pydantic.dataclasses import dataclass
|
||||
from codeflash.code_utils.code_extractor import get_code, get_code_no_skeleton
|
||||
from codeflash.languages.python.static_analysis.code_extractor import get_code, get_code_no_skeleton
|
||||
from codeflash.code_utils.code_utils import path_belongs_to_site_packages
|
||||
from codeflash.discovery.functions_to_optimize import FunctionParent, FunctionToOptimize
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ import tiktoken
|
|||
from jedi.api.classes import Name
|
||||
from pydantic.dataclasses import dataclass
|
||||
|
||||
from codeflash.code_utils.code_extractor import get_code, get_code_no_skeleton
|
||||
from codeflash.languages.python.static_analysis.code_extractor import get_code, get_code_no_skeleton
|
||||
from codeflash.code_utils.code_utils import path_belongs_to_site_packages
|
||||
from codeflash.discovery.functions_to_optimize import FunctionParent, FunctionToOptimize
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
from codeflash.code_utils.code_extractor import GlobalAssignmentCollector, add_global_assignments
|
||||
from codeflash.code_utils.code_replacer import replace_functions_and_add_imports
|
||||
from codeflash.languages.python.static_analysis.code_extractor import GlobalAssignmentCollector, add_global_assignments
|
||||
from codeflash.languages.python.static_analysis.code_replacer import replace_functions_and_add_imports
|
||||
from codeflash.discovery.functions_to_optimize import FunctionToOptimize
|
||||
from codeflash.languages.python.context.code_context_extractor import (
|
||||
collect_names_from_annotation,
|
||||
|
|
@ -2870,7 +2870,7 @@ def test_global_function_collector():
|
|||
"""Test GlobalFunctionCollector correctly collects module-level function definitions."""
|
||||
import libcst as cst
|
||||
|
||||
from codeflash.code_utils.code_extractor import GlobalFunctionCollector
|
||||
from codeflash.languages.python.static_analysis.code_extractor import GlobalFunctionCollector
|
||||
|
||||
source_code = """
|
||||
# Module-level functions
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from codeflash.code_utils.code_extractor import add_needed_imports_from_module
|
||||
from codeflash.languages.python.static_analysis.code_extractor import add_needed_imports_from_module
|
||||
|
||||
|
||||
def test_add_needed_imports_with_none_aliases():
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ from pathlib import Path
|
|||
|
||||
import libcst as cst
|
||||
|
||||
from codeflash.code_utils.code_extractor import delete___future___aliased_imports, find_preexisting_objects
|
||||
from codeflash.code_utils.code_replacer import (
|
||||
from codeflash.languages.python.static_analysis.code_extractor import delete___future___aliased_imports, find_preexisting_objects
|
||||
from codeflash.languages.python.static_analysis.code_replacer import (
|
||||
AddRequestArgument,
|
||||
AutouseFixtureModifier,
|
||||
OptimFunctionCollector,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
from codeflash.code_utils.code_extractor import get_code
|
||||
from codeflash.languages.python.static_analysis.code_extractor import get_code
|
||||
from codeflash.discovery.functions_to_optimize import FunctionToOptimize
|
||||
from codeflash.models.models import FunctionParent
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from unittest.mock import patch
|
||||
|
||||
from codeflash.code_utils.code_extractor import is_numerical_code
|
||||
from codeflash.languages.python.static_analysis.code_extractor import is_numerical_code
|
||||
|
||||
|
||||
@patch("codeflash.code_utils.code_extractor.has_numba", True)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ from codeflash.languages.javascript.find_references import (
|
|||
find_references,
|
||||
)
|
||||
from codeflash.languages.base import Language, FunctionInfo, ReferenceInfo
|
||||
from codeflash.code_utils.code_extractor import _format_references_as_markdown
|
||||
from codeflash.languages.python.static_analysis.code_extractor import _format_references_as_markdown
|
||||
from codeflash.models.models import FunctionParent
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
from codeflash.code_utils.code_replacer import replace_function_definitions_for_language
|
||||
from codeflash.languages.python.static_analysis.code_replacer import replace_function_definitions_for_language
|
||||
from codeflash.languages.base import Language
|
||||
from codeflash.languages.current import set_current_language
|
||||
from codeflash.languages.javascript.module_system import (
|
||||
|
|
|
|||
Loading…
Reference in a new issue