Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/clabe/cache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
logger = logging.getLogger(__name__)

T = TypeVar("T")
_DEFAULT_MAX_HISTORY = 9


class SyncStrategy(str, Enum):
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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).

Expand All @@ -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]

Expand Down
3 changes: 3 additions & 0 deletions src/clabe/pickers/default_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
Expand Down Expand Up @@ -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:",
Expand Down Expand Up @@ -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:",
Expand Down
3 changes: 2 additions & 1 deletion src/clabe/ui/questionary_ui_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Loading