Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use semantic versioning format for handshake version check #106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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