Skip to content

Commit 955929a

Browse files
Move all hard-coded version constants into a central _fallback module (#1481)
* Initial plan * Move all hard-coded version constants into central _versions module Create src/usethis/_versions.py consolidating all version constants: - FALLBACK_UV_VERSION (from _backend/uv/version.py) - PRE_COMMIT_VERSION (from _integrations/pre_commit/version.py) - _RUFF_VERSION (from _tool/impl/base/ruff.py) - _SYNC_WITH_UV_VERSION (from _tool/impl/spec/pre_commit.py) - _PYPROJECT_FMT_VERSION (from _tool/impl/spec/pyproject_fmt.py) - _CODESPELL_VERSION (from _tool/impl/spec/codespell.py) Move all version up-to-dateness tests to tests/usethis/test_versions.py. Update all imports across source and test files. Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/8d9c42f4-daba-4906-ad52-a2db630360ff * Rename version constants to public names, fix import order and formatting Remove leading underscores from version constants (now in _versions module): - _RUFF_VERSION → RUFF_VERSION - _SYNC_WITH_UV_VERSION → SYNC_WITH_UV_VERSION - _PYPROJECT_FMT_VERSION → PYPROJECT_FMT_VERSION - _CODESPELL_VERSION → CODESPELL_VERSION Add _versions to import-linter layer configuration. Apply auto-formatting fixes from ruff. Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/8d9c42f4-daba-4906-ad52-a2db630360ff * Rename version constants to use FALLBACK_ prefix consistently Rename all version constants to have the FALLBACK_ prefix: - PRE_COMMIT_VERSION → FALLBACK_PRE_COMMIT_VERSION - RUFF_VERSION → FALLBACK_RUFF_VERSION - SYNC_WITH_UV_VERSION → FALLBACK_SYNC_WITH_UV_VERSION - PYPROJECT_FMT_VERSION → FALLBACK_PYPROJECT_FMT_VERSION - CODESPELL_VERSION → FALLBACK_CODESPELL_VERSION FALLBACK_UV_VERSION already had the prefix. Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/c3521af3-873e-4d25-bdfe-0f6462a5461b * Rename _versions module to _fallback Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/cd749360-0035-4dad-81ab-87660c87081d --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> Co-authored-by: Nathan McDougall <nathan.j.mcdougall@gmail.com>
1 parent 62f392c commit 955929a

16 files changed

Lines changed: 170 additions & 212 deletions

File tree

.importlinter

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ layers =
2727
_file
2828
_subprocess | _console | _python
2929
_config
30-
_types | errors
30+
_types | errors | _fallback
3131
_pipeweld
3232
exhaustive = true
3333
exhaustive_ignores =

src/usethis/_backend/uv/version.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
from usethis._backend.uv.call import call_uv_subprocess
66
from usethis._backend.uv.errors import UVSubprocessFailedError
7-
8-
FALLBACK_UV_VERSION = "0.10.12"
7+
from usethis._fallback import FALLBACK_UV_VERSION
98

109

1110
def get_uv_version() -> str:

src/usethis/_fallback.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Central module for hard-coded fallback version constants.
2+
3+
These versions are manually bumped when necessary. Each constant corresponds to a
4+
recent release of the respective tool. Associated up-to-dateness tests are in
5+
``tests/usethis/test_fallback.py``.
6+
"""
7+
8+
FALLBACK_UV_VERSION = "0.10.12"
9+
FALLBACK_PRE_COMMIT_VERSION = "4.5.1"
10+
FALLBACK_RUFF_VERSION = "v0.15.7"
11+
FALLBACK_SYNC_WITH_UV_VERSION = "v0.5.0"
12+
FALLBACK_PYPROJECT_FMT_VERSION = "v2.20.0"
13+
FALLBACK_CODESPELL_VERSION = "v2.4.2"

src/usethis/_integrations/pre_commit/version.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
from usethis._config import usethis_config
2+
from usethis._fallback import FALLBACK_PRE_COMMIT_VERSION
23
from usethis._integrations.pre_commit.yaml import PreCommitConfigYAMLManager
34

4-
PRE_COMMIT_VERSION = "4.5.1"
5-
65

76
def get_pre_commit_version() -> str:
87
"""Get an inferred pre-commit version for usethis to target.
98
109
If no version can be inferred, a hard-coded version is used, corresponding to a
11-
recent release (see `PRE_COMMIT_VERSION`).
10+
recent release (see `FALLBACK_PRE_COMMIT_VERSION`).
1211
"""
1312
version = get_minimum_pre_commit_version()
1413
if version is not None:
1514
return version
16-
return PRE_COMMIT_VERSION
15+
return FALLBACK_PRE_COMMIT_VERSION
1716

1817

1918
def get_minimum_pre_commit_version() -> str | None:

src/usethis/_tool/impl/base/ruff.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from usethis._config import usethis_config
1212
from usethis._config_file import DotRuffTOMLManager, RuffTOMLManager
1313
from usethis._console import how_print, tick_print
14+
from usethis._fallback import FALLBACK_RUFF_VERSION
1415
from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager
1516
from usethis._integrations.ci.bitbucket import schema as bitbucket_schema
1617
from usethis._integrations.ci.bitbucket.anchor import (
@@ -35,8 +36,6 @@
3536
from usethis._file.manager import KeyValueFileManager
3637
from usethis._tool.rule import RuleConfig
3738

38-
_RUFF_VERSION = "v0.15.7" # Manually bump this version when necessary
39-
4039

4140
@final
4241
class RuffTool(RuffToolSpec, Tool):
@@ -110,7 +109,7 @@ def pre_commit_config(self) -> PreCommitConfig:
110109
PreCommitRepoConfig(
111110
repo=pre_commit_schema.UriRepo(
112111
repo="https://github.com/astral-sh/ruff-pre-commit",
113-
rev=_RUFF_VERSION,
112+
rev=FALLBACK_RUFF_VERSION,
114113
hooks=[pre_commit_schema.HookDefinition(id="ruff-check")],
115114
),
116115
requires_venv=False,
@@ -121,7 +120,7 @@ def pre_commit_config(self) -> PreCommitConfig:
121120
PreCommitRepoConfig(
122121
repo=pre_commit_schema.UriRepo(
123122
repo="https://github.com/astral-sh/ruff-pre-commit",
124-
rev=_RUFF_VERSION,
123+
rev=FALLBACK_RUFF_VERSION,
125124
hooks=[pre_commit_schema.HookDefinition(id="ruff-format")],
126125
),
127126
requires_venv=False,

src/usethis/_tool/impl/spec/codespell.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from usethis._config import usethis_config
99
from usethis._config_file import DotCodespellRCManager
10+
from usethis._fallback import FALLBACK_CODESPELL_VERSION
1011
from usethis._file.pyproject_toml.errors import PyprojectTOMLNotFoundError
1112
from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager
1213
from usethis._file.pyproject_toml.requires_python import (
@@ -24,8 +25,6 @@
2425
if TYPE_CHECKING:
2526
from usethis._file.manager import KeyValueFileManager
2627

27-
_CODESPELL_VERSION = "v2.4.2" # Manually bump this version when necessary
28-
2928

3029
class CodespellToolSpec(ToolSpec):
3130
@final
@@ -77,7 +76,7 @@ def pre_commit_config(self) -> PreCommitConfig:
7776
return PreCommitConfig.from_single_repo(
7877
pre_commit_schema.UriRepo(
7978
repo="https://github.com/codespell-project/codespell",
80-
rev=_CODESPELL_VERSION,
79+
rev=FALLBACK_CODESPELL_VERSION,
8180
hooks=[
8281
pre_commit_schema.HookDefinition(
8382
id="codespell", additional_dependencies=["tomli"]

src/usethis/_tool/impl/spec/pre_commit.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
from typing_extensions import assert_never, override
77

88
from usethis._backend.dispatch import get_backend
9+
from usethis._fallback import FALLBACK_SYNC_WITH_UV_VERSION
910
from usethis._integrations.pre_commit import schema as pre_commit_schema
1011
from usethis._integrations.pre_commit.cmd_ import pre_commit_raw_cmd
1112
from usethis._tool.base import ToolMeta, ToolSpec
1213
from usethis._tool.pre_commit import PreCommitConfig
1314
from usethis._types.backend import BackendEnum
1415
from usethis._types.deps import Dependency
1516

16-
_SYNC_WITH_UV_VERSION = "v0.5.0" # Manually bump this version when necessary
17-
1817

1918
class PreCommitToolSpec(ToolSpec):
2019
@final
@@ -47,7 +46,7 @@ def pre_commit_config(self) -> PreCommitConfig:
4746
return PreCommitConfig.from_single_repo(
4847
pre_commit_schema.UriRepo(
4948
repo="https://github.com/tsvikas/sync-with-uv",
50-
rev=_SYNC_WITH_UV_VERSION,
49+
rev=FALLBACK_SYNC_WITH_UV_VERSION,
5150
hooks=[pre_commit_schema.HookDefinition(id="sync-with-uv")],
5251
),
5352
requires_venv=False,

src/usethis/_tool/impl/spec/pyproject_fmt.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55

66
from typing_extensions import override
77

8+
from usethis._fallback import FALLBACK_PYPROJECT_FMT_VERSION
89
from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager
910
from usethis._integrations.pre_commit import schema as pre_commit_schema
1011
from usethis._tool.base import ToolMeta, ToolSpec
1112
from usethis._tool.config import ConfigEntry, ConfigItem, ConfigSpec
1213
from usethis._tool.pre_commit import PreCommitConfig
1314
from usethis._types.deps import Dependency
1415

15-
_PYPROJECT_FMT_VERSION = "v2.20.0" # Manually bump this version when necessary
16-
1716

1817
class PyprojectFmtToolSpec(ToolSpec):
1918
@final
@@ -42,7 +41,7 @@ def pre_commit_config(self) -> PreCommitConfig:
4241
return PreCommitConfig.from_single_repo(
4342
pre_commit_schema.UriRepo(
4443
repo="https://github.com/tox-dev/pyproject-fmt",
45-
rev=_PYPROJECT_FMT_VERSION,
44+
rev=FALLBACK_PYPROJECT_FMT_VERSION,
4645
hooks=[pre_commit_schema.HookDefinition(id="pyproject-fmt")],
4746
),
4847
requires_venv=False,

tests/usethis/_backend/uv/test_version.py

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,14 @@
1-
import os
21
from pathlib import Path
32

43
import pytest
54

65
from usethis._backend.uv.errors import UVSubprocessFailedError
7-
from usethis._backend.uv.version import (
8-
FALLBACK_UV_VERSION,
9-
get_uv_version,
10-
next_breaking_uv_version,
11-
)
12-
from usethis._config import usethis_config
13-
from usethis._integrations.ci.github.errors import GitHubTagError
14-
from usethis._integrations.ci.github.tags import get_github_latest_tag
6+
from usethis._backend.uv.version import get_uv_version, next_breaking_uv_version
7+
from usethis._fallback import FALLBACK_UV_VERSION
158
from usethis._test import change_cwd
169

1710

1811
class TestGetUVVersion:
19-
@pytest.mark.usefixtures("_vary_network_conn")
20-
def test_latest_version(self):
21-
if os.getenv("CI"):
22-
pytest.skip("Avoid flaky pipelines by testing version bumps manually")
23-
24-
try:
25-
assert (
26-
get_github_latest_tag(owner="astral-sh", repo="uv")
27-
== FALLBACK_UV_VERSION
28-
)
29-
except GitHubTagError as err:
30-
if (
31-
usethis_config.offline
32-
or "rate limit exceeded for url" in str(err)
33-
or "Read timed out." in str(err)
34-
):
35-
pytest.skip(
36-
"Failed to fetch GitHub tags (connection issues); skipping test"
37-
)
38-
raise err
39-
4012
def test_matches_pattern(self, tmp_path: Path):
4113
# Act
4214
with change_cwd(tmp_path):

tests/usethis/_core/test_core_tool.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
use_ty,
3232
)
3333
from usethis._deps import add_deps_to_group, get_deps_from_group, is_dep_satisfied_in
34+
from usethis._fallback import FALLBACK_RUFF_VERSION, FALLBACK_SYNC_WITH_UV_VERSION
3435
from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager
3536
from usethis._integrations.pre_commit.hooks import _HOOK_ORDER, get_hook_ids
3637
from usethis._integrations.pre_commit.yaml import PreCommitConfigYAMLManager
3738
from usethis._python.version import PythonVersion
3839
from usethis._test import change_cwd
3940
from usethis._tool.all_ import ALL_TOOLS
40-
from usethis._tool.impl.base.ruff import _RUFF_VERSION, RuffTool
41-
from usethis._tool.impl.spec.pre_commit import _SYNC_WITH_UV_VERSION
41+
from usethis._tool.impl.base.ruff import RuffTool
4242
from usethis._types.backend import BackendEnum
4343
from usethis._types.deps import Dependency
4444

@@ -725,7 +725,7 @@ def test_pre_commit_after(
725725
f"""\
726726
repos:
727727
- repo: https://github.com/tsvikas/sync-with-uv
728-
rev: {_SYNC_WITH_UV_VERSION}
728+
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
729729
hooks:
730730
- id: sync-with-uv
731731
- repo: local
@@ -893,7 +893,7 @@ def test_pre_commit_first(
893893
f"""\
894894
repos:
895895
- repo: https://github.com/tsvikas/sync-with-uv
896-
rev: {_SYNC_WITH_UV_VERSION}
896+
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
897897
hooks:
898898
- id: sync-with-uv
899899
- repo: local
@@ -1907,7 +1907,7 @@ def test_fresh(self, uv_init_dir: Path, capfd: pytest.CaptureFixture[str]):
19071907
f"""\
19081908
repos:
19091909
- repo: https://github.com/tsvikas/sync-with-uv
1910-
rev: {_SYNC_WITH_UV_VERSION}
1910+
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
19111911
hooks:
19121912
- id: sync-with-uv
19131913
"""
@@ -1985,7 +1985,7 @@ def test_config_file_already_exists(self, uv_init_repo_dir: Path):
19851985
entry: uv run --isolated --frozen --offline python -c "print('hello world!')"
19861986
language: system
19871987
- repo: https://github.com/tsvikas/sync-with-uv
1988-
rev: {_SYNC_WITH_UV_VERSION}
1988+
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
19891989
hooks:
19901990
- id: sync-with-uv
19911991
"""
@@ -3435,7 +3435,7 @@ def test_pre_commit(
34353435
f"""\
34363436
repos:
34373437
- repo: https://github.com/tsvikas/sync-with-uv
3438-
rev: {_SYNC_WITH_UV_VERSION}
3438+
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
34393439
hooks:
34403440
- id: sync-with-uv
34413441
- repo: local
@@ -3985,11 +3985,11 @@ def test_add_only_linter(
39853985
f"""\
39863986
repos:
39873987
- repo: https://github.com/tsvikas/sync-with-uv
3988-
rev: {_SYNC_WITH_UV_VERSION}
3988+
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
39893989
hooks:
39903990
- id: sync-with-uv
39913991
- repo: https://github.com/astral-sh/ruff-pre-commit
3992-
rev: {_RUFF_VERSION}
3992+
rev: {FALLBACK_RUFF_VERSION}
39933993
hooks:
39943994
- id: ruff-check
39953995
"""
@@ -4023,15 +4023,15 @@ def test_add_only_linter_to_existing_formatter(
40234023
f"""\
40244024
repos:
40254025
- repo: https://github.com/tsvikas/sync-with-uv
4026-
rev: {_SYNC_WITH_UV_VERSION}
4026+
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
40274027
hooks:
40284028
- id: sync-with-uv
40294029
- repo: https://github.com/astral-sh/ruff-pre-commit
4030-
rev: {_RUFF_VERSION}
4030+
rev: {FALLBACK_RUFF_VERSION}
40314031
hooks:
40324032
- id: ruff-check
40334033
- repo: https://github.com/astral-sh/ruff-pre-commit
4034-
rev: {_RUFF_VERSION}
4034+
rev: {FALLBACK_RUFF_VERSION}
40354035
hooks:
40364036
- id: ruff-format
40374037
"""
@@ -4064,11 +4064,11 @@ def test_add_only_formatter(
40644064
f"""\
40654065
repos:
40664066
- repo: https://github.com/tsvikas/sync-with-uv
4067-
rev: {_SYNC_WITH_UV_VERSION}
4067+
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
40684068
hooks:
40694069
- id: sync-with-uv
40704070
- repo: https://github.com/astral-sh/ruff-pre-commit
4071-
rev: {_RUFF_VERSION}
4071+
rev: {FALLBACK_RUFF_VERSION}
40724072
hooks:
40734073
- id: ruff-format
40744074
"""
@@ -4102,11 +4102,11 @@ def test_remove_only_linter(
41024102
f"""\
41034103
repos:
41044104
- repo: https://github.com/tsvikas/sync-with-uv
4105-
rev: {_SYNC_WITH_UV_VERSION}
4105+
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
41064106
hooks:
41074107
- id: sync-with-uv
41084108
- repo: https://github.com/astral-sh/ruff-pre-commit
4109-
rev: {_RUFF_VERSION}
4109+
rev: {FALLBACK_RUFF_VERSION}
41104110
hooks:
41114111
- id: ruff-format
41124112
"""

0 commit comments

Comments
 (0)