diff --git a/scripts/pylib/twister/twisterlib/environment.py b/scripts/pylib/twister/twisterlib/environment.py index c81b03355ce5e9..2b330caf2ab334 100644 --- a/scripts/pylib/twister/twisterlib/environment.py +++ b/scripts/pylib/twister/twisterlib/environment.py @@ -51,6 +51,17 @@ def _get_installed_packages() -> Generator[str, None, None]: yield dist.metadata['Name'] +def python_version_guard(): + min_ver = (3, 10) + if sys.version_info < min_ver: + min_ver_str = '.'.join([str(v) for v in min_ver]) + cur_ver_line = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}" + print(f"Unsupported Python version {cur_ver_line}.") + print(f"Currently, Twister requires at least Python {min_ver_str}.") + print("Install a newer Python version and retry.") + sys.exit(1) + + installed_packages: List[str] = list(_get_installed_packages()) PYTEST_PLUGIN_INSTALLED = 'pytest-twister-harness' in installed_packages diff --git a/scripts/twister b/scripts/twister index c6382f9a9e3379..db692ceb1cdb87 100755 --- a/scripts/twister +++ b/scripts/twister @@ -203,12 +203,15 @@ if not ZEPHYR_BASE: sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister/")) sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/build_helpers")) -from twisterlib.environment import add_parse_arguments, parse_arguments +from twisterlib.environment import add_parse_arguments, parse_arguments, python_version_guard from twisterlib.twister_main import main + if __name__ == "__main__": ret = 0 try: + python_version_guard() + parser = add_parse_arguments() options = parse_arguments(parser, sys.argv[1:]) default_options = parse_arguments(parser, [], on_init=False) diff --git a/scripts/west_commands/twister_cmd.py b/scripts/west_commands/twister_cmd.py index 266b60d2bf2ec7..d9616c4e614d85 100644 --- a/scripts/west_commands/twister_cmd.py +++ b/scripts/west_commands/twister_cmd.py @@ -18,7 +18,7 @@ sys.path.insert(0, str(twister_path)) sys.path.insert(0, str(twister_path / "pylib" / "twister")) -from twisterlib.environment import add_parse_arguments, parse_arguments +from twisterlib.environment import add_parse_arguments, parse_arguments, python_version_guard from twisterlib.twister_main import main TWISTER_DESCRIPTION = """\ @@ -37,6 +37,7 @@ def __init__(self): TWISTER_DESCRIPTION, accepts_unknown_args=True, ) + python_version_guard() def do_add_parser(self, parser_adder): parser = parser_adder.add_parser(