From 26800e24e3115ac2e27eeb2303535ea059414da8 Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Fri, 9 May 2025 12:20:56 +0200 Subject: [PATCH 1/2] Mimic major-minor behavior --- rsconnect/pyproject.py | 5 ++++- tests/test_pyproject.py | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/rsconnect/pyproject.py b/rsconnect/pyproject.py index e52c6b7e..36c53e2d 100644 --- a/rsconnect/pyproject.py +++ b/rsconnect/pyproject.py @@ -149,7 +149,10 @@ def _adapt_contraint(constraints: typing.List[str]) -> typing.Generator[str, Non if "*" in constraint: yield f"=={constraint}" else: - yield f"~={constraint.rstrip('0').rstrip('.')}" # Remove trailing zeros and dots + # only major specified “3” → ~=3.0 → >=3.0,<4.0 + # major and minor specified “3.8” or “3.8.11” → ~=3.8.0 → >=3.8.0,<3.9.0 + constraint = '.'.join(constraint.split(".")[:2] + ["0"]) + yield f"~={constraint}" return ",".join(_adapt_contraint(current_contraints)) diff --git a/tests/test_pyproject.py b/tests/test_pyproject.py index 58e3f643..2863de0c 100644 --- a/tests/test_pyproject.py +++ b/tests/test_pyproject.py @@ -149,8 +149,10 @@ def test_detect_python_version_requirement(): @pytest.mark.parametrize( # type: ignore ["content", "expected"], [ - ("3.8", "~=3.8"), - ("3.8.0", "~=3.8"), + ("3", "~=3.0"), + ("3.8", "~=3.8.0"), + ("3.8.0", "~=3.8.0"), + ("3.8.11", "~=3.8.0"), ("3.8.0b1", InvalidVersionConstraintError("pre-release versions are not supported: 3.8.0b1")), ("3.8.0rc1", InvalidVersionConstraintError("pre-release versions are not supported: 3.8.0rc1")), ("3.8.0a1", InvalidVersionConstraintError("pre-release versions are not supported: 3.8.0a1")), From 8c3506ddcb084a1cd0e7215838cb2ef09ee40dbc Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Fri, 9 May 2025 12:27:07 +0200 Subject: [PATCH 2/2] lint --- rsconnect/pyproject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rsconnect/pyproject.py b/rsconnect/pyproject.py index 36c53e2d..6252ddd9 100644 --- a/rsconnect/pyproject.py +++ b/rsconnect/pyproject.py @@ -151,7 +151,7 @@ def _adapt_contraint(constraints: typing.List[str]) -> typing.Generator[str, Non else: # only major specified “3” → ~=3.0 → >=3.0,<4.0 # major and minor specified “3.8” or “3.8.11” → ~=3.8.0 → >=3.8.0,<3.9.0 - constraint = '.'.join(constraint.split(".")[:2] + ["0"]) + constraint = ".".join(constraint.split(".")[:2] + ["0"]) yield f"~={constraint}" return ",".join(_adapt_contraint(current_contraints))