aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/python_version.py
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2023-03-17 19:29:50 +0400
committerGravatar Hassan Abouelela <[email protected]>2023-03-17 19:29:50 +0400
commit59dce27d31567046d2205743ede41ab664a10011 (patch)
tree5d8ee81cebf4cce5cb19b2571b6c312aeddcc814 /scripts/python_version.py
parentMake Python Binary Mount Dynamic (diff)
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 <[email protected]>
Diffstat (limited to 'scripts/python_version.py')
-rw-r--r--scripts/python_version.py37
1 files changed, 13 insertions, 24 deletions
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