Skip to content

Commit 520b090

Browse files
refactor: use fallback versions and next_breaking_version for build system config
- Add FALLBACK_HATCHLING_VERSION = "1.29.0" to _fallback.py - Extract next_breaking_version() generic helper into _fallback.py - Refactor next_breaking_uv_version() to delegate to next_breaking_version() - Update _BUILD_SYSTEM_CONFIG to use FALLBACK_UV_VERSION, FALLBACK_HATCHLING_VERSION and next_breaking_version() instead of hard-coded version bounds - Add TestFallbackHatchlingVersion and TestNextBreakingVersion tests Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/0ab118f5-5448-457b-a6aa-6740f6b46a5d
1 parent d1f6ce6 commit 520b090

4 files changed

Lines changed: 69 additions & 9 deletions

File tree

src/usethis/_backend/uv/version.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import json
22

3-
from packaging.version import Version
4-
53
from usethis._backend.uv.call import call_uv_subprocess
64
from usethis._backend.uv.errors import UVSubprocessFailedError
7-
from usethis._fallback import FALLBACK_UV_VERSION
5+
from usethis._fallback import FALLBACK_UV_VERSION, next_breaking_version
86

97

108
def get_uv_version() -> str:
@@ -26,7 +24,4 @@ def next_breaking_uv_version(version: str) -> str:
2624
For versions with major >= 1, bumps the major version (e.g. 1.0.2 -> 2.0.0).
2725
For versions with major == 0, bumps the minor version (e.g. 0.10.2 -> 0.11.0).
2826
"""
29-
v = Version(version)
30-
if v.major >= 1:
31-
return f"{v.major + 1}.0.0"
32-
return f"0.{v.minor + 1}.0"
27+
return next_breaking_version(version)

src/usethis/_fallback.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@
55
``tests/usethis/test_fallback.py``.
66
"""
77

8+
from packaging.version import Version
9+
810
FALLBACK_UV_VERSION = "0.10.12"
11+
FALLBACK_HATCHLING_VERSION = "1.29.0"
912
FALLBACK_PRE_COMMIT_VERSION = "4.5.1"
1013
FALLBACK_RUFF_VERSION = "v0.15.7"
1114
FALLBACK_SYNC_WITH_UV_VERSION = "v0.5.0"
1215
FALLBACK_PYPROJECT_FMT_VERSION = "v2.20.0"
1316
FALLBACK_CODESPELL_VERSION = "v2.4.2"
17+
18+
19+
def next_breaking_version(version: str) -> str:
20+
"""Get the next breaking version for a version string, following semver.
21+
22+
For versions with major >= 1, bumps the major version (e.g. 1.0.2 -> 2.0.0).
23+
For versions with major == 0, bumps the minor version (e.g. 0.10.2 -> 0.11.0).
24+
"""
25+
v = Version(version)
26+
if v.major >= 1:
27+
return f"{v.major + 1}.0.0"
28+
return f"0.{v.minor + 1}.0"

src/usethis/_init.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,29 @@
1010
from usethis._config import usethis_config
1111
from usethis._console import tick_print
1212
from usethis._deps import get_project_deps
13+
from usethis._fallback import (
14+
FALLBACK_HATCHLING_VERSION,
15+
FALLBACK_UV_VERSION,
16+
next_breaking_version,
17+
)
1318
from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager
1419
from usethis._integrations.project.name import get_project_name
1520
from usethis._types.backend import BackendEnum
1621
from usethis._types.build_backend import BuildBackendEnum
1722

1823
_BUILD_SYSTEM_CONFIG: dict[BuildBackendEnum, tuple[list[str], str]] = {
19-
BuildBackendEnum.hatch: (["hatchling"], "hatchling.build"),
20-
BuildBackendEnum.uv: (["uv_build>=0.10.12,<0.11.0"], "uv_build"),
24+
BuildBackendEnum.hatch: (
25+
[
26+
f"hatchling>={FALLBACK_HATCHLING_VERSION},<{next_breaking_version(FALLBACK_HATCHLING_VERSION)}"
27+
],
28+
"hatchling.build",
29+
),
30+
BuildBackendEnum.uv: (
31+
[
32+
f"uv_build>={FALLBACK_UV_VERSION},<{next_breaking_version(FALLBACK_UV_VERSION)}"
33+
],
34+
"uv_build",
35+
),
2136
}
2237

2338

tests/usethis/test_fallback.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
from usethis._config import usethis_config
66
from usethis._fallback import (
77
FALLBACK_CODESPELL_VERSION,
8+
FALLBACK_HATCHLING_VERSION,
89
FALLBACK_PRE_COMMIT_VERSION,
910
FALLBACK_PYPROJECT_FMT_VERSION,
1011
FALLBACK_RUFF_VERSION,
1112
FALLBACK_SYNC_WITH_UV_VERSION,
1213
FALLBACK_UV_VERSION,
14+
next_breaking_version,
1315
)
1416
from usethis._integrations.ci.github.errors import GitHubTagError
1517
from usethis._integrations.ci.github.tags import get_github_latest_tag
@@ -40,6 +42,22 @@ def test_latest_version(self):
4042
raise err
4143

4244

45+
class TestFallbackHatchlingVersion:
46+
@pytest.mark.usefixtures("_vary_network_conn")
47+
def test_latest_version(self):
48+
if os.getenv("CI"):
49+
pytest.skip("Avoid flaky pipelines by testing version bumps manually")
50+
51+
try:
52+
assert (
53+
get_github_latest_tag(owner="pypa", repo="hatch")
54+
== f"hatchling-v{FALLBACK_HATCHLING_VERSION}"
55+
)
56+
except GitHubTagError as err:
57+
_skip_on_github_error(err)
58+
raise err
59+
60+
4361
class TestPreCommitVersion:
4462
@pytest.mark.usefixtures("_vary_network_conn")
4563
def test_latest_version(self):
@@ -120,3 +138,20 @@ def test_latest_version(self):
120138
except GitHubTagError as err:
121139
_skip_on_github_error(err)
122140
raise err
141+
142+
143+
class TestNextBreakingVersion:
144+
def test_pre_one_bumps_minor(self):
145+
assert next_breaking_version("0.10.2") == "0.11.0"
146+
147+
def test_post_one_bumps_major(self):
148+
assert next_breaking_version("1.0.2") == "2.0.0"
149+
150+
def test_pre_one_zero_minor(self):
151+
assert next_breaking_version("0.0.5") == "0.1.0"
152+
153+
def test_exact_one(self):
154+
assert next_breaking_version("1.0.0") == "2.0.0"
155+
156+
def test_high_major(self):
157+
assert next_breaking_version("3.2.1") == "4.0.0"

0 commit comments

Comments
 (0)