From 5c6a19a3baa1d749b408e8e393f688865d37f3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20H=C3=A9risson?= Date: Sat, 17 Oct 2026 01:06:47 +0200 Subject: [PATCH 1/2] feat(rr_cache): resolve bare cspace alias to latest versioned config Lets --chemical-space rr2026 resolve to whichever config_rr2026-v*.json is newest (e.g. rr2026-v3.1.0), so new versions don't require call sites to be updated to track the latest rr2026 release. Co-Authored-By: Claude Sonnet 5 --- rr_cache/rr_cache.py | 55 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/rr_cache/rr_cache.py b/rr_cache/rr_cache.py index a09d559..bb443a1 100644 --- a/rr_cache/rr_cache.py +++ b/rr_cache/rr_cache.py @@ -10,9 +10,12 @@ from json import dumps as json_dumps from json import load as json_load from logging import Logger, StreamHandler, getLogger +from os import listdir as os_listdir from os import makedirs from os import path as os_path from pathlib import Path +from re import compile as re_compile +from re import escape as re_escape from re import findall as re_findall from brs_utils import check_sha, download, print_end, print_progress, print_start @@ -54,6 +57,36 @@ def ask_user_input(): return True +def _resolve_latest_cspace(base: str, config_dirs: list[str]) -> "str | None": + """Find the highest-versioned config_{base}-v.json in config_dirs. + + Lets a bare alias (e.g. "rr2026") resolve to whichever versioned + cspace (e.g. "rr2026-v3.1.0") is newest, without hardcoding a version. + + Args: + base (str): Chemical space base name (e.g. "rr2026"). + config_dirs (list[str]): Directories to search for config files, in order. + + Returns: + str | None: Resolved cspace name, or None if no versioned config was found. + """ + pattern = re_compile(rf"^config_{re_escape(base)}-v(\d+(?:\.\d+)*)\.json$") + best_name = None + best_version = None + for config_dir in config_dirs: + if not os_path.isdir(config_dir): + continue + for fname in os_listdir(config_dir): + m = pattern.match(fname) + if not m: + continue + version = tuple(int(part) for part in m.group(1).split(".")) + if best_version is None or version > best_version: + best_version = version + best_name = f"{base}-v{m.group(1)}" + return best_name + + class FileCorruptedError(Exception): pass @@ -110,12 +143,32 @@ def __init__( # Config file # Search first in install_dir, # then in default config path + install_config_dir = os_path.join(install_dir, "config") cache_cfg_fln = os_path.join( - install_dir, "config", f"config_{self.__cspace}.json" + install_config_dir, f"config_{self.__cspace}.json" ) if not os_path.exists(cache_cfg_fln): cache_cfg_fln = os_path.join(CONFIG_PATH, f"config_{self.__cspace}.json") + # No exact match: treat cspace as a bare alias (e.g. "rr2026") and + # resolve it to its latest versioned config (e.g. "rr2026-v3.1.0") + if not os_path.exists(cache_cfg_fln): + resolved_cspace = _resolve_latest_cspace( + self.__cspace, [install_config_dir, CONFIG_PATH] + ) + if resolved_cspace is not None: + self.logger.info( + f"Resolved chemical space alias '{self.__cspace}' to latest version '{resolved_cspace}'" + ) + self.__cspace = resolved_cspace + cache_cfg_fln = os_path.join( + install_config_dir, f"config_{self.__cspace}.json" + ) + if not os_path.exists(cache_cfg_fln): + cache_cfg_fln = os_path.join( + CONFIG_PATH, f"config_{self.__cspace}.json" + ) + try: with open(cache_cfg_fln, "r") as f: cache_cfg = json_load(f) From e5ce9cab18d9a53c26f202444a8af7730f4bfdae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20H=C3=A9risson?= Date: Sat, 17 Oct 2026 01:12:02 +0200 Subject: [PATCH 2/2] style(rr_cache): reformat with black Co-Authored-By: Claude Sonnet 5 --- rr_cache/rr_cache.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rr_cache/rr_cache.py b/rr_cache/rr_cache.py index bb443a1..bd481cc 100644 --- a/rr_cache/rr_cache.py +++ b/rr_cache/rr_cache.py @@ -144,9 +144,7 @@ def __init__( # Search first in install_dir, # then in default config path install_config_dir = os_path.join(install_dir, "config") - cache_cfg_fln = os_path.join( - install_config_dir, f"config_{self.__cspace}.json" - ) + cache_cfg_fln = os_path.join(install_config_dir, f"config_{self.__cspace}.json") if not os_path.exists(cache_cfg_fln): cache_cfg_fln = os_path.join(CONFIG_PATH, f"config_{self.__cspace}.json")