Skip to content

Commit 59bb89d

Browse files
authored
Mimic major-minor Connect behavior (#666)
1 parent 4299657 commit 59bb89d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

rsconnect/pyproject.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ def _adapt_contraint(constraints: typing.List[str]) -> typing.Generator[str, Non
149149
if "*" in constraint:
150150
yield f"=={constraint}"
151151
else:
152-
yield f"~={constraint.rstrip('0').rstrip('.')}" # Remove trailing zeros and dots
152+
# only major specified “3” → ~=3.0 → >=3.0,<4.0
153+
# major and minor specified “3.8” or “3.8.11” → ~=3.8.0 → >=3.8.0,<3.9.0
154+
constraint = ".".join(constraint.split(".")[:2] + ["0"])
155+
yield f"~={constraint}"
153156

154157
return ",".join(_adapt_contraint(current_contraints))
155158

tests/test_pyproject.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ def test_detect_python_version_requirement():
149149
@pytest.mark.parametrize( # type: ignore
150150
["content", "expected"],
151151
[
152-
("3.8", "~=3.8"),
153-
("3.8.0", "~=3.8"),
152+
("3", "~=3.0"),
153+
("3.8", "~=3.8.0"),
154+
("3.8.0", "~=3.8.0"),
155+
("3.8.11", "~=3.8.0"),
154156
("3.8.0b1", InvalidVersionConstraintError("pre-release versions are not supported: 3.8.0b1")),
155157
("3.8.0rc1", InvalidVersionConstraintError("pre-release versions are not supported: 3.8.0rc1")),
156158
("3.8.0a1", InvalidVersionConstraintError("pre-release versions are not supported: 3.8.0a1")),

0 commit comments

Comments
 (0)