Skip to content

Commit 26715f9

Browse files
committed
fix: use packaging for version comparision
1 parent d6c1249 commit 26715f9

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ classifiers = [
1919
"Typing :: Typed",
2020
]
2121
dynamic = ["version"]
22-
dependencies = ["requests>=2.31.0,<3"]
22+
dependencies = [
23+
"requests>=2.31.0,<3",
24+
"packaging"
25+
]
2326

2427
[project.urls]
2528
Source = "https://github.com/posit-dev/posit-sdk-py"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
requests==2.32.2
2+
packaging==24.1

src/posit/connect/context.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import functools
22
from typing import Optional, Protocol
33

4+
from packaging.version import Version
5+
46

57
def requires(version: str):
68
def decorator(func):
79
@functools.wraps(func)
810
def wrapper(instance: ContextManager, *args, **kwargs):
911
ctx = instance.ctx
10-
if ctx.version and ctx.version < version:
12+
if ctx.version and Version(ctx.version) < Version(version):
1113
raise RuntimeError(
1214
f"This API is not available in Connect version {ctx.version}. Please upgrade to version {version} or later.",
1315
)

0 commit comments

Comments
 (0)