From 34d131fee3b44d11eaa11cfd02bfae5b151261df Mon Sep 17 00:00:00 2001 From: Oluwadamisi Ayinde Date: Wed, 15 Jan 2025 05:24:03 +0100 Subject: [PATCH 1/2] Fixing: issue #1501 --- ersilia/cli/create_cli.py | 20 ++++++++++++++++++-- ersilia/cli/messages.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/ersilia/cli/create_cli.py b/ersilia/cli/create_cli.py index 0bf2e1779..f4acea061 100644 --- a/ersilia/cli/create_cli.py +++ b/ersilia/cli/create_cli.py @@ -1,6 +1,9 @@ +import sys + from ..auth.auth import Auth from .cmd import Command from .commands import ersilia_cli +from .messages import VersionNotSupported def create_ersilia_cli(): @@ -9,12 +12,25 @@ def create_ersilia_cli(): This function initializes the Command class, checks if the user is a contributor, and dynamically imports and executes various CLI commands based on the user's role. + It also verifies that Python 3.8+ is being used. Returns ------- - ersilia_cli : module - The configured Ersilia CLI module. + ersilia_cli : module | None + The configured Ersilia CLI module if Python version >= 3.8 + None if the program exits due to version check failure + Raises + ------ + SystemExit + If Python version is less than 3.8 + Notes + ----- + This function will terminate the program with sys.exit(1) if Python version < 3.8 """ + # Check Python version + if sys.version_info.major < 3 or sys.version_info.minor < 8: + VersionNotSupported(sys.version.major, sys.version.minor) + is_contributor = Auth().is_contributor() cmd = Command() diff --git a/ersilia/cli/messages.py b/ersilia/cli/messages.py index d321a5378..371ec4db8 100644 --- a/ersilia/cli/messages.py +++ b/ersilia/cli/messages.py @@ -72,3 +72,39 @@ def echo(self): ) ) sys.exit(0) + + +class VersionNotSupported: + """ + A class to handle the scenario when the python version used is less than 3.8 + + Attributes + ---------- + versionMajor : int + The user's major version (e.g 3 in version 3.8). + versionMinor : int + The user's minor version (e.g 8 in version 3.8). + + Methods + ------- + echo() + prints an error message to the console in red and exits the program. + """ + + def __init__(self, versionMajor, versionMinor): + self.versionMajor = versionMajor + self.versionMinor = versionMinor + + def echo(self): + """ + Prints an error indicating the python version is not supported and exits the program. + """ + echo( + "Error: This application requires Python 3.8 or higher.", + fg="red", + ) + echo( + "Current version: {sys.version_info.major}.{sys.version_info.minor}", + fg="red", + ) + sys.exit(1) From 12156c4eaf9943b5c0d6e91c41cd600b6f82d646 Mon Sep 17 00:00:00 2001 From: Oluwadamisi Ayinde Date: Wed, 15 Jan 2025 06:03:55 +0100 Subject: [PATCH 2/2] Fixing: issue #1501 --- ersilia/cli/create_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ersilia/cli/create_cli.py b/ersilia/cli/create_cli.py index f4acea061..6965fd4f6 100644 --- a/ersilia/cli/create_cli.py +++ b/ersilia/cli/create_cli.py @@ -29,7 +29,7 @@ def create_ersilia_cli(): """ # Check Python version if sys.version_info.major < 3 or sys.version_info.minor < 8: - VersionNotSupported(sys.version.major, sys.version.minor) + VersionNotSupported(sys.version.major, sys.version.minor).echo() is_contributor = Auth().is_contributor()