From cf374a5fadfcf27fbb59d1ade0d88df902554038 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Tue, 5 Nov 2024 17:32:21 +0100 Subject: [PATCH 1/4] build(python): :pushpin: update the minimum python version to 3.9.20 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 32a9c27..1193d2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ include = [ ] [tool.poetry.dependencies] -python = "^3.8.1" +python = "^3.9.20" rdflib = "^7.0.0" pyshacl = "^0.26.0" click = "^8.1.7" From bcf1f6f3d5fa636db11a847e970b794a39eb25bb Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Tue, 5 Nov 2024 17:38:27 +0100 Subject: [PATCH 2/4] build: :construction_worker: update poetry.lock --- poetry.lock | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/poetry.lock b/poetry.lock index 5ac8c40..fe38dce 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. [[package]] name = "appnope" @@ -1120,8 +1120,8 @@ astroid = ">=3.2.4,<=3.3.0-dev0" colorama = {version = ">=0.4.5", markers = "sys_platform == \"win32\""} dill = [ {version = ">=0.2", markers = "python_version < \"3.11\""}, - {version = ">=0.3.6", markers = "python_version >= \"3.11\" and python_version < \"3.12\""}, {version = ">=0.3.7", markers = "python_version >= \"3.12\""}, + {version = ">=0.3.6", markers = "python_version >= \"3.11\" and python_version < \"3.12\""}, ] isort = ">=4.2.5,<5.13.0 || >5.13.0,<6" mccabe = ">=0.6,<0.8" @@ -1496,7 +1496,6 @@ files = [ [package.dependencies] markdown-it-py = ">=2.2.0" pygments = ">=2.13.0,<3.0.0" -typing-extensions = {version = ">=4.0.0,<5.0", markers = "python_version < \"3.9\""} [package.extras] jupyter = ["ipywidgets (>=7.5.1,<9)"] @@ -1704,5 +1703,5 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" -python-versions = "^3.8.1" -content-hash = "3973b73c6ba7eed27a4ebe8ce3f43654a2752abd6681a96802c06321ff977057" +python-versions = "^3.9.20" +content-hash = "3d2178523411060222b49dcd3e54d922115ce5fe3075d4db85703e3c63e687d2" From d5ad7ff08116f336be906477caeb03fcd3bd5b95 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Tue, 5 Nov 2024 18:13:07 +0100 Subject: [PATCH 3/4] feat(utils): :sparkles: add utility functions to read and check the minimum required Python version --- rocrate_validator/utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/rocrate_validator/utils.py b/rocrate_validator/utils.py index 552b3a5..353ca6e 100644 --- a/rocrate_validator/utils.py +++ b/rocrate_validator/utils.py @@ -142,6 +142,29 @@ def get_version() -> str: return f"{version}-dirty" if dirty else version +def get_min_python_version() -> tuple[int, int, Optional[int]]: + """ + Get the minimum Python version required by the package + + :return: The minimum Python version + """ + min_version_str = config["tool"]["poetry"]["dependencies"]["python"] + assert min_version_str, "The minimum Python version is required" + # remove any non-digit characters + min_version_str = re.sub(r'[^\d.]+', '', min_version_str) + # convert the version string to a tuple + min_version = tuple(map(int, min_version_str.split("."))) + logger.debug(f"Minimum Python version: {min_version}") + return min_version + + +def check_python_version() -> bool: + """ + Check if the current Python version meets the minimum requirements + """ + return sys.version_info >= get_min_python_version() + + def get_config(property: Optional[str] = None) -> dict: """ Get the configuration for the package or a specific property From 02497bb7a06fb0b1e7d2ed6fbe1d3c71d79888c6 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Tue, 5 Nov 2024 18:15:07 +0100 Subject: [PATCH 4/4] feat(cli): :sparkles: check the minimum required Python version --- rocrate_validator/cli/main.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rocrate_validator/cli/main.py b/rocrate_validator/cli/main.py index c3876e1..01e8655 100644 --- a/rocrate_validator/cli/main.py +++ b/rocrate_validator/cli/main.py @@ -18,7 +18,8 @@ import rocrate_validator.log as logging from rocrate_validator.cli.utils import Console, SystemPager -from rocrate_validator.utils import get_version +from rocrate_validator.utils import (check_python_version, + get_min_python_version, get_version) # set up logging logger = logging.getLogger(__name__) @@ -68,6 +69,13 @@ def cli(ctx: click.Context, debug: bool, version: bool, disable_color: bool, no_ ctx.obj['interactive'] = interactive try: + # Check the python version + if not check_python_version(): + console.print( + "\n[bold][red]ERROR:[/red] A Python version " + f"{'.'.join([str(_) for _ in get_min_python_version()])} or newer is required ! [/bold]") + sys.exit(1) + # If the version flag is set, print the version and exit if version: console.print(