Skip to content
Merged
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
14 changes: 14 additions & 0 deletions src/usethis/_backend/uv/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

from packaging.version import Version

from usethis._backend.uv.call import call_uv_subprocess
from usethis._backend.uv.errors import UVSubprocessFailedError

Expand All @@ -17,3 +19,15 @@ def get_uv_version() -> str:

json_dict: dict = json.loads(json_str)
return json_dict.get("version", FALLBACK_UV_VERSION)


def next_breaking_uv_version(version: str) -> str:
"""Get the next breaking version for a uv version string, following semver.

For versions with major >= 1, bumps the major version (e.g. 1.0.2 -> 2.0.0).
For versions with major == 0, bumps the minor version (e.g. 0.10.2 -> 0.11.0).
"""
v = Version(version)
if v.major >= 1:
return f"{v.major + 1}.0.0"
return f"0.{v.minor + 1}.0"
43 changes: 42 additions & 1 deletion tests/usethis/_backend/uv/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import pytest

from usethis._backend.uv.errors import UVSubprocessFailedError
from usethis._backend.uv.version import FALLBACK_UV_VERSION, get_uv_version
from usethis._backend.uv.version import (
FALLBACK_UV_VERSION,
get_uv_version,
next_breaking_uv_version,
)
from usethis._config import usethis_config
from usethis._integrations.ci.github.errors import GitHubTagError
from usethis._integrations.ci.github.tags import get_github_latest_tag
Expand Down Expand Up @@ -61,3 +65,40 @@ def mock_call_uv_subprocess(*_, **__) -> str:

# Assert
assert version == FALLBACK_UV_VERSION


class TestNextBreakingUVVersion:
def test_pre_one_bumps_minor(self):
# Act
result = next_breaking_uv_version("0.10.2")

# Assert
assert result == "0.11.0"

def test_post_one_bumps_major(self):
# Act
result = next_breaking_uv_version("1.0.2")

# Assert
assert result == "2.0.0"

def test_pre_one_zero_minor(self):
# Act
result = next_breaking_uv_version("0.0.5")

# Assert
assert result == "0.1.0"

def test_exact_one(self):
# Act
result = next_breaking_uv_version("1.0.0")

# Assert
assert result == "2.0.0"

def test_high_major(self):
# Act
result = next_breaking_uv_version("3.2.1")

# Assert
assert result == "4.0.0"
Loading