From 60fbb0e30d848e1051f4e8988890183d7a0a3daa Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Tue, 29 Oct 2024 11:52:58 +0000 Subject: [PATCH] Make list atlas function more robust --- brainglobe_atlasapi/list_atlases.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/brainglobe_atlasapi/list_atlases.py b/brainglobe_atlasapi/list_atlases.py index 9a5da303..40ea68ce 100644 --- a/brainglobe_atlasapi/list_atlases.py +++ b/brainglobe_atlasapi/list_atlases.py @@ -2,6 +2,8 @@ Some functionality to list all available and downloaded brainglobe atlases """ +import re + from rich import print as rprint from rich.panel import Panel from rich.table import Table @@ -43,11 +45,15 @@ def get_local_atlas_version(atlas_name): """ brainglobe_dir = config.get_brainglobe_dir() - return [ - f.name.split("_v")[1] - for f in brainglobe_dir.glob(f"*{atlas_name}*") - if f.is_dir() - ][0] + try: + return [ + re.search(r"_v(\d+\.\d+)$", f.name).group(1) + for f in brainglobe_dir.glob(f"*{atlas_name}*") + if f.is_dir() and re.search(r"_v(\d+\.\d+)$", f.name) + ][0] + except IndexError: + print(f"No atlas found with the name: {atlas_name}") + return None def get_all_atlases_lastversions():