Skip to content

Commit

Permalink
Add validator to check compat between Plone and Python version
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Jan 12, 2025
1 parent f345fb1 commit 3df6519
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cookieplone/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
#
# 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",
"3.9",
"3.10",
"3.11",
"3.12",
"3.13",
]

DEFAULT_NODE = 22
Expand Down
18 changes: 18 additions & 0 deletions cookieplone/utils/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: MIT
import re
import sys
from typing import Any
from urllib.parse import urlparse

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions news/54.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Python 3.13, and add a validator to check compatibility between Plone and Python version. @davisagli
9 changes: 9 additions & 0 deletions tests/utils/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 3df6519

Please sign in to comment.