Use requires-python in pyproject.toml to specify python requirement

This commit is contained in:
Kovid Goyal
2024-03-29 13:23:09 +05:30
parent 4fe65f75bc
commit c72963dfc5
2 changed files with 20 additions and 3 deletions

View File

@@ -1,3 +1,6 @@
[project]
requires-python = ">=3.8"
[tool.mypy] [tool.mypy]
files = 'kitty,kittens,glfw,*.py,docs/conf.py,gen' files = 'kitty,kittens,glfw,*.py,docs/conf.py,gen'
no_implicit_optional = true no_implicit_optional = true
@@ -23,7 +26,6 @@ report_progress = true
[tool.ruff] [tool.ruff]
line-length = 160 line-length = 160
target-version = 'py38'
select = ['E', 'F', 'I', 'RUF100'] select = ['E', 'F', 'I', 'RUF100']
[tool.ruff.per-file-ignores] [tool.ruff.per-file-ignores]

View File

@@ -25,10 +25,25 @@ from typing import Callable, Dict, FrozenSet, Iterable, Iterator, List, Optional
from glfw import glfw from glfw import glfw
from glfw.glfw import ISA, BinaryArch, Command, CompileKey, CompilerType 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__)) 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 verbose = False
build_dir = 'build' build_dir = 'build'
constants = os.path.join('kitty', 'constants.py') constants = os.path.join('kitty', 'constants.py')