Skip to content

Commit

Permalink
fix: use semantic version instead of python version format. This avoi…
Browse files Browse the repository at this point in the history
…ds 0.0.2-beta to be converted into 0.0.2b0

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
  • Loading branch information
victorgarcia98 committed Feb 10, 2025
1 parent 69be5c0 commit b19bf7b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
9 changes: 6 additions & 3 deletions src/flexmeasures_client/s2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from uuid import uuid4

import pydantic
import semver
from packaging.version import Version

try:
Expand Down Expand Up @@ -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


Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tests/s2/test_utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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

0 comments on commit b19bf7b

Please sign in to comment.