mirror of
https://github.com/codeflash-ai/codeflash.git
synced 2026-05-04 18:25:17 +00:00
Merge pull request #2036 from codeflash-ai/perf/defer-main-imports
perf: defer module-level imports in main.py into main()
This commit is contained in:
commit
56841683c3
1 changed files with 21 additions and 11 deletions
|
|
@ -8,8 +8,7 @@ from __future__ import annotations
|
|||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Callable
|
||||
|
||||
if "--subagent" in sys.argv:
|
||||
os.environ["CODEFLASH_SUBAGENT_MODE"] = "true"
|
||||
|
|
@ -17,19 +16,26 @@ if "--subagent" in sys.argv:
|
|||
|
||||
warnings.filterwarnings("ignore")
|
||||
|
||||
from codeflash.cli_cmds.cli import parse_args, process_pyproject_config
|
||||
from codeflash.cli_cmds.console import paneled_text
|
||||
from codeflash.code_utils import env_utils
|
||||
from codeflash.code_utils.checkpoint import ask_should_use_checkpoint_get_functions
|
||||
from codeflash.code_utils.config_parser import parse_config_file
|
||||
from codeflash.code_utils.version_check import check_for_newer_minor_version
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import Namespace
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Entry point for the codeflash command-line interface."""
|
||||
# Fast path: --version exits before importing the full stack
|
||||
if len(sys.argv) == 2 and sys.argv[1] == "--version":
|
||||
from codeflash.version import __version__
|
||||
|
||||
print(f"Codeflash version {__version__}")
|
||||
return
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from codeflash.cli_cmds.cli import parse_args, process_pyproject_config
|
||||
from codeflash.code_utils import env_utils
|
||||
from codeflash.code_utils.checkpoint import ask_should_use_checkpoint_get_functions
|
||||
from codeflash.code_utils.config_parser import parse_config_file
|
||||
from codeflash.code_utils.version_check import check_for_newer_minor_version
|
||||
from codeflash.telemetry import posthog_cf
|
||||
from codeflash.telemetry.sentry import init_sentry
|
||||
|
||||
|
|
@ -89,7 +95,7 @@ def main() -> None:
|
|||
ask_run_end_to_end_test(args)
|
||||
else:
|
||||
# Check for first-run experience (no config exists)
|
||||
loaded_args = _handle_config_loading(args)
|
||||
loaded_args = _handle_config_loading(args, process_pyproject_config)
|
||||
if loaded_args is None:
|
||||
sys.exit(0)
|
||||
args = loaded_args
|
||||
|
|
@ -105,7 +111,9 @@ def main() -> None:
|
|||
optimizer.run_with_args(args)
|
||||
|
||||
|
||||
def _handle_config_loading(args: Namespace) -> Namespace | None:
|
||||
def _handle_config_loading(
|
||||
args: Namespace, process_pyproject_config: Callable[[Namespace], Namespace]
|
||||
) -> Namespace | None:
|
||||
"""Handle config loading with first-run experience support.
|
||||
|
||||
If no config exists and not in CI, triggers the first-run experience.
|
||||
|
|
@ -113,6 +121,7 @@ def _handle_config_loading(args: Namespace) -> Namespace | None:
|
|||
|
||||
Args:
|
||||
args: CLI args namespace.
|
||||
process_pyproject_config: Config processing function.
|
||||
|
||||
Returns:
|
||||
Updated args with config loaded, or None if user cancelled first-run.
|
||||
|
|
@ -157,6 +166,7 @@ def print_codeflash_banner() -> None:
|
|||
Renders the Codeflash ASCII logo inside a non-expanding panel titled with
|
||||
https://codeflash.ai, using bold gold text for visual emphasis.
|
||||
"""
|
||||
from codeflash.cli_cmds.console import paneled_text
|
||||
from codeflash.cli_cmds.console_constants import CODEFLASH_LOGO
|
||||
|
||||
paneled_text(
|
||||
|
|
|
|||
Loading…
Reference in a new issue