Skip to content

Commit e6a33f2

Browse files
authored
Merge pull request #205 from AllenNeuralDynamics:feat-sort-cache
Sort caches before displaying
2 parents 5396c70 + e201452 commit e6a33f2

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/clabe/cache_manager.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
logger = logging.getLogger(__name__)
1313

1414
T = TypeVar("T")
15+
_DEFAULT_MAX_HISTORY = 9
1516

1617

1718
class SyncStrategy(str, Enum):
@@ -40,7 +41,7 @@ class CachedSettings(BaseModel, Generic[T]):
4041
"""
4142

4243
values: list[T] = Field(default_factory=list)
43-
max_history: int = Field(default=5, gt=0)
44+
max_history: int = Field(default=_DEFAULT_MAX_HISTORY, gt=0)
4445

4546
def add(self, value: T) -> None:
4647
"""
@@ -180,7 +181,7 @@ def _save_unlocked(self) -> None:
180181
with self.cache_path.open("w", encoding="utf-8") as f:
181182
f.write(cache_data.model_dump_json(indent=2))
182183

183-
def register_cache(self, name: str, max_history: int = 5) -> None:
184+
def register_cache(self, name: str, max_history: int = _DEFAULT_MAX_HISTORY) -> None:
184185
"""
185186
Register a new cache with a specific history limit (thread-safe).
186187
@@ -206,7 +207,7 @@ def add_to_cache(self, name: str, value: Any) -> None:
206207
"""
207208
with self._instance_lock:
208209
if name not in self.caches:
209-
self.caches[name] = CachedSettings(max_history=5)
210+
self.caches[name] = CachedSettings(max_history=_DEFAULT_MAX_HISTORY)
210211

211212
cache = self.caches[name]
212213

src/clabe/pickers/default_behavior.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def pick_rig(self, model: Type[TRig]) -> TRig:
211211
cache = None
212212

213213
if cache:
214+
cache.sort()
214215
rig_path = self.ui_helper.prompt_pick_from_list(
215216
cache,
216217
prompt="Choose a rig:",
@@ -420,6 +421,7 @@ def choose_subject(self, directory: str | os.PathLike) -> str:
420421
else:
421422
subjects = None
422423
if subjects:
424+
subjects.sort()
423425
subject = self.ui_helper.prompt_pick_from_list(
424426
subjects,
425427
prompt="Choose a subject:",
@@ -464,6 +466,7 @@ def prompt_experimenter(self, strict: bool = True) -> Optional[List[str]]:
464466
_picked: str | None = None
465467
while experimenter is None:
466468
if experimenters_cache:
469+
experimenters_cache.sort()
467470
_picked = self.ui_helper.prompt_pick_from_list(
468471
experimenters_cache,
469472
prompt="Choose an experimenter:",

src/clabe/ui/questionary_ui_helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _ask_sync(question):
3333
"""
3434
try:
3535
# Check if we're in an async context
36-
loop = asyncio.get_running_loop()
36+
asyncio.get_running_loop()
3737
# We are in an async context - use thread pool to avoid nested event loop
3838
import concurrent.futures
3939

@@ -47,6 +47,7 @@ def _ask_sync(question):
4747

4848
class QuestionaryUIHelper(_UiHelperBase):
4949
"""UI helper implementation using Questionary for interactive prompts."""
50+
5051
def __init__(self, style: Optional[questionary.Style] = None) -> None:
5152
"""Initializes the QuestionaryUIHelper with an optional custom style."""
5253
self.style = style or custom_style

0 commit comments

Comments
 (0)