Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task: Add a warning message when Ersilia found running in a Python env less than 3.8 #1501 #1517

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions ersilia/cli/create_cli.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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).echo()

is_contributor = Auth().is_contributor()

cmd = Command()
Expand Down
36 changes: 36 additions & 0 deletions ersilia/cli/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)