diff --git a/codeflash/cli_cmds/init_java.py b/codeflash/cli_cmds/init_java.py index 161c53d21..735e60e97 100644 --- a/codeflash/cli_cmds/init_java.py +++ b/codeflash/cli_cmds/init_java.py @@ -7,6 +7,7 @@ import xml.etree.ElementTree as ET from dataclasses import dataclass from enum import Enum, auto +from functools import lru_cache from pathlib import Path from typing import Any, Union @@ -55,6 +56,7 @@ class JavaSetupInfo: benchmarks_root: Union[str, None] = None +@lru_cache(maxsize=1) def _get_theme(): """Get the CodeflashTheme - imported lazily to avoid circular imports.""" from codeflash.cli_cmds.init_config import CodeflashTheme @@ -366,17 +368,15 @@ def _prompt_directory_override(dir_type: str, detected: str, curdir: Path) -> st def _prompt_custom_directory(dir_type: str) -> str: """Prompt for a custom directory path.""" + # Reuse the question object to avoid reconstructing it on every loop iteration. + custom_question = inquirer.Path( + "custom_path", + message=f"Enter the path to your {dir_type} directory", + path_type=inquirer.Path.DIRECTORY, + exists=True, + ) while True: - custom_questions = [ - inquirer.Path( - "custom_path", - message=f"Enter the path to your {dir_type} directory", - path_type=inquirer.Path.DIRECTORY, - exists=True, - ) - ] - - custom_answers = inquirer.prompt(custom_questions, theme=_get_theme()) + custom_answers = inquirer.prompt([custom_question], theme=_get_theme()) if not custom_answers: apologize_and_exit()