From 3df65194fd2c7beb9214d1513e4d7bc6b3ea8961 Mon Sep 17 00:00:00 2001 From: David Glick Date: Sat, 11 Jan 2025 18:06:34 -0800 Subject: [PATCH] Add validator to check compat between Plone and Python version --- cookieplone/settings.py | 5 +++++ cookieplone/utils/validators.py | 18 ++++++++++++++++++ news/54.bugfix | 1 + tests/utils/test_validators.py | 9 +++++++++ 4 files changed, 33 insertions(+) create mode 100644 news/54.bugfix diff --git a/cookieplone/settings.py b/cookieplone/settings.py index baafd54..784307c 100644 --- a/cookieplone/settings.py +++ b/cookieplone/settings.py @@ -2,6 +2,10 @@ # # SPDX-License-Identifier: MIT PLONE_MIN_VERSION = "6" +PLONE_PYTHON_VERSIONS = { + (6, 0): ["3.8", "3.9", "3.10", "3.11", "3.12"], + (6, 1): ["3.10", "3.11", "3.12", "3.13"], +} SUPPORTED_PYTHON_VERSIONS = [ "3.8", @@ -9,6 +13,7 @@ "3.10", "3.11", "3.12", + "3.13", ] DEFAULT_NODE = 22 diff --git a/cookieplone/utils/validators.py b/cookieplone/utils/validators.py index 16fc213..d07d480 100644 --- a/cookieplone/utils/validators.py +++ b/cookieplone/utils/validators.py @@ -2,6 +2,7 @@ # # SPDX-License-Identifier: MIT import re +import sys from typing import Any from urllib.parse import urlparse @@ -88,6 +89,23 @@ def validate_plone_version(value: str) -> str: return "" if status else f"{value} is not a valid Plone version." +def validate_python_version(plone_version: str) -> str: + """Validate current Python is compatible with specified Plone version.""" + plone_version_tuple = tuple(_version_from_str(plone_version).release[:2]) + supported_python_versions = ( + settings.PLONE_PYTHON_VERSIONS.get(plone_version_tuple) or [] + ) + if not supported_python_versions: + return f"Cookieplone doesn't support Plone version {plone_version}" + python_version = f"{sys.version_info.major}.{sys.version_info.minor}" + return ( + "" + if python_version in supported_python_versions + else f"You have Python {python_version} but Plone {plone_version} " + f"requires one of the following Pythons: {', '.join(supported_python_versions)}" + ) + + def validate_volto_version(value: str) -> str: """Validate Volto Version.""" version = _version_from_str(value) diff --git a/news/54.bugfix b/news/54.bugfix new file mode 100644 index 0000000..a316af5 --- /dev/null +++ b/news/54.bugfix @@ -0,0 +1 @@ +Add support for Python 3.13, and add a validator to check compatibility between Plone and Python version. @davisagli diff --git a/tests/utils/test_validators.py b/tests/utils/test_validators.py index e8973bf..55106b9 100644 --- a/tests/utils/test_validators.py +++ b/tests/utils/test_validators.py @@ -192,3 +192,12 @@ def test_validate_plone_version(version: str, expected: str): def test_validate_volto_version(version: str, expected: str): func = validators.validate_volto_version assert func(version) == expected + + +def test_validate_python_version(): + assert validators.validate_python_version("6.0.14") == "" + assert validators.validate_python_version("6.1.0b2") == "" + assert ( + validators.validate_python_version("5.2") + == "Cookieplone doesn't support Plone version 5.2" + )