From 59dce27d31567046d2205743ede41ab664a10011 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Fri, 17 Mar 2023 19:29:50 +0400 Subject: Refactor Python Version Parsing Remove the pointless function and allow the file-level constants to be imported by external callers. Signed-off-by: Hassan Abouelela --- scripts/python_version.py | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'scripts/python_version.py') diff --git a/scripts/python_version.py b/scripts/python_version.py index 6c8f25c..0a6b518 100644 --- a/scripts/python_version.py +++ b/scripts/python_version.py @@ -23,32 +23,21 @@ class Version: is_main: bool -_ALL_VERSIONS = None -_MAIN_VERSION = None - - -def get_all_versions() -> tuple[list[Version], Version]: - """ - Get a list of all available versions for this evaluation. - - Returns a tuple of all versions, and the main version. - """ - # Return a cached result - global _ALL_VERSIONS, _MAIN_VERSION - if _ALL_VERSIONS is not None: - return _ALL_VERSIONS, _MAIN_VERSION - - versions = [] - main_version: Version | None = None - +ALL_VERSIONS: list[Version] = [] +"""A list of all versions available for eval.""" +MAIN_VERSION: Version = None +"""The default eval version, and the version used by the server.""" +VERSION_DISPLAY_NAMES: list[str] = [] +"""The display names for all available eval versions.""" + +if MAIN_VERSION is None: + # Set the constants' values the first time the file is imported for version_json in json.loads(VERSIONS_FILE.read_text("utf-8")): version = Version(**version_json) if version.is_main: - main_version = version - versions.append(version) + MAIN_VERSION = version + ALL_VERSIONS.append(version) + VERSION_DISPLAY_NAMES.append(version.display_name) - if main_version is None: + if MAIN_VERSION is None: raise Exception("Exactly one version must be configured as the main version.") - - _ALL_VERSIONS, _MAIN_VERSION = versions, main_version - return versions, main_version -- cgit v1.2.3