From b19bf7b6fc18e042c146706a75ca8292c116ec5c Mon Sep 17 00:00:00 2001 From: Victor Garcia Reolid Date: Mon, 10 Feb 2025 16:11:38 +0100 Subject: [PATCH] fix: use semantic version instead of python version format. This avoids 0.0.2-beta to be converted into 0.0.2b0 Signed-off-by: Victor Garcia Reolid --- setup.cfg | 4 +++- src/flexmeasures_client/s2/utils.py | 9 ++++++--- tests/s2/test_utils.py | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7417c6f..b199262 100644 --- a/setup.cfg +++ b/setup.cfg @@ -61,7 +61,9 @@ exclude = [options.extras_require] # Add here additional requirements for extra features, to install with: # `pip install flexmeasures-client[s2]` like: -s2=s2-python>=0.4.1 # reason: be compatible with constraint pydantic>=2.8.2 +s2= + s2-python>=0.4.1 # reason: be compatible with constraint pydantic>=2.8.2 + semver # Add here test requirements (semicolon/line-separated) testing = diff --git a/src/flexmeasures_client/s2/utils.py b/src/flexmeasures_client/s2/utils.py index 63880bd..50eabaa 100644 --- a/src/flexmeasures_client/s2/utils.py +++ b/src/flexmeasures_client/s2/utils.py @@ -5,6 +5,7 @@ from uuid import uuid4 import pydantic +import semver from packaging.version import Version try: @@ -83,7 +84,7 @@ def get_reception_status( ) -def is_version_supported(v1: Version, v2: Version) -> bool: +def is_version_supported(v1: semver.Version, v2: semver.Version) -> bool: return v1 >= v2 @@ -104,8 +105,10 @@ def get_latest_compatible_version(supported_versions, current_version, logger): return Version(current_version) # Convert supported versions to Version objects and sort in descending order - rm_versions = sorted((Version(v) for v in supported_versions), reverse=True) - cem_version = Version(current_version) + rm_versions = sorted( + (semver.Version.parse(v) for v in supported_versions), reverse=True + ) + cem_version = semver.Version.parse(current_version) # Find the latest compatible version latest_compatible_version = next( diff --git a/tests/s2/test_utils.py b/tests/s2/test_utils.py index 3f1d9bd..ef51a19 100644 --- a/tests/s2/test_utils.py +++ b/tests/s2/test_utils.py @@ -1,7 +1,7 @@ import logging import pytest -from packaging.version import Version +import semver from flexmeasures_client.s2.utils import get_latest_compatible_version @@ -52,5 +52,5 @@ def test_get_latest_compatible_version( if not supported_versions: assert "RM didn't provide any supported version" in caplog.text - elif latest_version == Version(current_version): + elif latest_version == semver.Version.parse(current_version): assert "There are no compatible S2 versions" in caplog.text