aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/python_version.py37
-rw-r--r--scripts/set_versions.py10
2 files changed, 17 insertions, 30 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
diff --git a/scripts/set_versions.py b/scripts/set_versions.py
index fb33dc1..3bd2ab4 100644
--- a/scripts/set_versions.py
+++ b/scripts/set_versions.py
@@ -3,18 +3,16 @@
from pathlib import Path
from textwrap import dedent
-from scripts import python_version
+from scripts.python_version import ALL_VERSIONS, MAIN_VERSION
DOCKERFILE_TEMPLATE = Path("scripts/in.Dockerfile").read_text("utf-8")
DOCKERFILE = Path("Dockerfile")
-versions, main_version = python_version.get_all_versions()
-
# Download and copy multiple python images into one layer
python_build = ""
previous_layer = "first"
-for version in versions:
+for version in ALL_VERSIONS:
if version.is_main:
# Main is handled separately later
continue
@@ -31,14 +29,14 @@ for version in versions:
# Main version is installed twice, once at the very beginning to make sure
# its files aren't overwritten, and once at the end which actually makes use of the version
-python_build = f"FROM python:{main_version.image_tag} as base-first\n" + python_build
+python_build = f"FROM python:{MAIN_VERSION.image_tag} as base-first\n" + python_build
# Write new dockerfile
DOCKERFILE.write_text(
"# THIS FILE IS AUTOGENERATED, DO NOT MODIFY! #\n"
+ DOCKERFILE_TEMPLATE.replace("{python_install_commands}", python_build)
.replace("{final_base}", previous_layer)
- .replace("{main_version_tag}", main_version.image_tag),
+ .replace("{main_version_tag}", MAIN_VERSION.image_tag),
"utf-8",
)