Skip to content
New issue

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

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

Already on GitHub? # to your account

build(python): 📌 update the minimum python version to 3.9.20 #32

Merged
merged 4 commits into from
Nov 6, 2024
Merged
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
9 changes: 4 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion rocrate_validator/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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(
Expand Down
23 changes: 23 additions & 0 deletions rocrate_validator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down