From b63c1f4f5e1eaf23baebeec7243b977dd9dc1667 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Wed, 20 Nov 2024 20:05:42 +0200 Subject: [PATCH] FIXUP: Factor out retrieval of Python version --- dev_scripts/qa.py | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/dev_scripts/qa.py b/dev_scripts/qa.py index 956794d..18313c5 100755 --- a/dev_scripts/qa.py +++ b/dev_scripts/qa.py @@ -813,30 +813,39 @@ class QAWindows(QABase): while msvcrt.kbhit(): msvcrt.getch() - @QABase.task( - f"Install the latest version of Python {PYTHON_VERSION_STR}", ref=REF_BUILD - ) - def install_python(self): - cur_version = list(sys.version_info[:3]) - - logger.info("Getting latest Python release") + def get_latest_python_release(self): with urllib.request.urlopen(EOL_PYTHON_URL) as f: resp = f.read() releases = json.loads(resp) for release in releases: if release["cycle"] == PYTHON_VERSION_STR: - latest_version = [int(num) for num in release["latest"].split(".")] - if latest_version > cur_version: - self.prompt( - f"You need to install the latest Python version ({release['latest']})" - ) - elif latest_version == cur_version: - logger.info( - f"Verified that the latest Python version ({release['latest']}) is installed" - ) - return + # Transform the Python version string (e.g., "3.12.7") into a list + # (e.g., [3, 12, 7]), and return it + return [int(num) for num in release["latest"].split(".")] - logger.error("Could not verify that the latest Python version is installed") + raise RuntimeError( + f"Could not find a Python release for version {PYTHON_VERSION_STR}" + ) + + @QABase.task( + f"Install the latest version of Python {PYTHON_VERSION_STR}", ref=REF_BUILD + ) + def install_python(self): + logger.info("Getting latest Python release") + try: + latest_version = self.get_latest_python_release() + except Exception: + logger.error("Could not verify that the latest Python version is installed") + + cur_version = list(sys.version_info[:3]) + if latest_version > cur_version: + self.prompt( + f"You need to install the latest Python version ({latest_version})" + ) + elif latest_version == cur_version: + logger.info( + f"Verified that the latest Python version ({latest_version}) is installed" + ) @QABase.task("Install and Run Docker Desktop", ref=REF_BUILD) def install_docker(self):