summaryrefslogtreecommitdiff
path: root/rules
diff options
context:
space:
mode:
authorPierre Le Marre <dev@wismill.eu>2024-06-12 19:01:07 +0200
committerMarge Bot <emma+marge@anholt.net>2024-06-13 04:18:38 +0000
commit6993e6953deb5ce00647553b18e5273f15596b0b (patch)
tree8cebef40558dd71542ee8689d0414ba2165d3999 /rules
parentce0112d5698068874541a16906cba17d006c82b7 (diff)
Require Python >=3.9 + optional strenum fallback
Fallback with package `strenum` is required for Python < 3.11. Part-of: <https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/merge_requests/702>
Diffstat (limited to 'rules')
-rwxr-xr-xrules/generate-options-symbols.py10
-rw-r--r--rules/meson.build13
2 files changed, 17 insertions, 6 deletions
diff --git a/rules/generate-options-symbols.py b/rules/generate-options-symbols.py
index b29b9253..5eec9b7d 100755
--- a/rules/generate-options-symbols.py
+++ b/rules/generate-options-symbols.py
@@ -7,14 +7,20 @@
from __future__ import annotations
import argparse
-from enum import StrEnum, unique
+from enum import unique
import sys
import xml.etree.ElementTree as ET
-
from typing import Generator, Iterable
from dataclasses import dataclass
from pathlib import Path
+try:
+ # Available from Python 3.11
+ from enum import StrEnum
+except ImportError:
+ # Fallback to external package
+ from strenum import StrEnum
+
def error(msg):
print(f"ERROR: {msg}", file=sys.stderr)
diff --git a/rules/meson.build b/rules/meson.build
index 0978150e..414ea5f2 100644
--- a/rules/meson.build
+++ b/rules/meson.build
@@ -127,13 +127,18 @@ if get_option('compat-rules')
endif # compat-rules
MINIMUM_PYTHON_VERSION = '3.11'
+MINIMUM_PYTHON_VERSION_WITH_MODULE_FALLBACK = '3.9'
pymod = import('python')
python = pymod.find_installation('python3')
if python.language_version().version_compare('<@0@'.format(MINIMUM_PYTHON_VERSION))
- error('Minimum required Python version: @0@, but got: @1@'.format(
- MINIMUM_PYTHON_VERSION,
- python.language_version()
- ))
+ # Now require strenum module as fallback
+ python = pymod.find_installation('python3', modules: ['strenum'])
+ if python.language_version().version_compare('<@0@'.format(MINIMUM_PYTHON_VERSION_WITH_MODULE_FALLBACK))
+ error('Minimum required Python version: @0@, but got: @1@'.format(
+ MINIMUM_PYTHON_VERSION_WITH_MODULE_FALLBACK,
+ python.language_version()
+ ))
+ endif
endif
merge_py = find_program('merge.py')
xml2lst = find_program('xml2lst.pl')