From c72963dfc5da55f70054aa26f04cf34aedbe5869 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 29 Mar 2024 13:23:09 +0530 Subject: [PATCH] Use requires-python in pyproject.toml to specify python requirement --- pyproject.toml | 4 +++- setup.py | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6eb87dc2e..e4720ca72 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,6 @@ +[project] +requires-python = ">=3.8" + [tool.mypy] files = 'kitty,kittens,glfw,*.py,docs/conf.py,gen' no_implicit_optional = true @@ -23,7 +26,6 @@ report_progress = true [tool.ruff] line-length = 160 -target-version = 'py38' select = ['E', 'F', 'I', 'RUF100'] [tool.ruff.per-file-ignores] diff --git a/setup.py b/setup.py index f5ffe488e..a66fbe80d 100755 --- a/setup.py +++ b/setup.py @@ -25,10 +25,25 @@ from typing import Callable, Dict, FrozenSet, Iterable, Iterator, List, Optional from glfw import glfw from glfw.glfw import ISA, BinaryArch, Command, CompileKey, CompilerType -if sys.version_info[:2] < (3, 8): - raise SystemExit('kitty requires python >= 3.8') src_base = os.path.dirname(os.path.abspath(__file__)) +def check_version_info() -> None: + import tomllib + with open(os.path.join(src_base, 'pyproject.toml'), 'rb') as f: + m = tomllib.load(f) + minver = m['project']['requires-python'] + match = re.match(r'(>=?)(\d+)\.(\d+)', minver) + assert match is not None + q = int(match.group(2)), int(match.group(3)) + if match.group(1) == '>=': + is_ok = sys.version_info >= q + else: + is_ok = sys.version_info > q + if not is_ok: + exit(f'calibre requires Python {minver}. Current Python version: {".".join(map(str, sys.version_info[:3]))}') + + +check_version_info() verbose = False build_dir = 'build' constants = os.path.join('kitty', 'constants.py')