diff --git a/src/clabe/cache_manager.py b/src/clabe/cache_manager.py index 5c1c9f4..69085db 100644 --- a/src/clabe/cache_manager.py +++ b/src/clabe/cache_manager.py @@ -12,6 +12,7 @@ logger = logging.getLogger(__name__) T = TypeVar("T") +_DEFAULT_MAX_HISTORY = 9 class SyncStrategy(str, Enum): @@ -40,7 +41,7 @@ class CachedSettings(BaseModel, Generic[T]): """ values: list[T] = Field(default_factory=list) - max_history: int = Field(default=5, gt=0) + max_history: int = Field(default=_DEFAULT_MAX_HISTORY, gt=0) def add(self, value: T) -> None: """ @@ -180,7 +181,7 @@ def _save_unlocked(self) -> None: with self.cache_path.open("w", encoding="utf-8") as f: f.write(cache_data.model_dump_json(indent=2)) - def register_cache(self, name: str, max_history: int = 5) -> None: + def register_cache(self, name: str, max_history: int = _DEFAULT_MAX_HISTORY) -> None: """ Register a new cache with a specific history limit (thread-safe). @@ -206,7 +207,7 @@ def add_to_cache(self, name: str, value: Any) -> None: """ with self._instance_lock: if name not in self.caches: - self.caches[name] = CachedSettings(max_history=5) + self.caches[name] = CachedSettings(max_history=_DEFAULT_MAX_HISTORY) cache = self.caches[name] diff --git a/src/clabe/pickers/default_behavior.py b/src/clabe/pickers/default_behavior.py index 9bc9270..2bbef82 100644 --- a/src/clabe/pickers/default_behavior.py +++ b/src/clabe/pickers/default_behavior.py @@ -211,6 +211,7 @@ def pick_rig(self, model: Type[TRig]) -> TRig: cache = None if cache: + cache.sort() rig_path = self.ui_helper.prompt_pick_from_list( cache, prompt="Choose a rig:", @@ -420,6 +421,7 @@ def choose_subject(self, directory: str | os.PathLike) -> str: else: subjects = None if subjects: + subjects.sort() subject = self.ui_helper.prompt_pick_from_list( subjects, prompt="Choose a subject:", @@ -464,6 +466,7 @@ def prompt_experimenter(self, strict: bool = True) -> Optional[List[str]]: _picked: str | None = None while experimenter is None: if experimenters_cache: + experimenters_cache.sort() _picked = self.ui_helper.prompt_pick_from_list( experimenters_cache, prompt="Choose an experimenter:", diff --git a/src/clabe/ui/questionary_ui_helper.py b/src/clabe/ui/questionary_ui_helper.py index ba2c3f8..7c0cc9b 100644 --- a/src/clabe/ui/questionary_ui_helper.py +++ b/src/clabe/ui/questionary_ui_helper.py @@ -33,7 +33,7 @@ def _ask_sync(question): """ try: # Check if we're in an async context - loop = asyncio.get_running_loop() + asyncio.get_running_loop() # We are in an async context - use thread pool to avoid nested event loop import concurrent.futures @@ -47,6 +47,7 @@ def _ask_sync(question): class QuestionaryUIHelper(_UiHelperBase): """UI helper implementation using Questionary for interactive prompts.""" + def __init__(self, style: Optional[questionary.Style] = None) -> None: """Initializes the QuestionaryUIHelper with an optional custom style.""" self.style = style or custom_style