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
2 changes: 1 addition & 1 deletion .importlinter
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ layers =
_file
_subprocess | _console | _python
_config
_types | errors
_types | errors | _fallback
_pipeweld
exhaustive = true
exhaustive_ignores =
Expand Down
3 changes: 1 addition & 2 deletions src/usethis/_backend/uv/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

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

FALLBACK_UV_VERSION = "0.10.12"
from usethis._fallback import FALLBACK_UV_VERSION


def get_uv_version() -> str:
Expand Down
13 changes: 13 additions & 0 deletions src/usethis/_fallback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Central module for hard-coded fallback version constants.

These versions are manually bumped when necessary. Each constant corresponds to a
recent release of the respective tool. Associated up-to-dateness tests are in
``tests/usethis/test_fallback.py``.
"""

FALLBACK_UV_VERSION = "0.10.12"
FALLBACK_PRE_COMMIT_VERSION = "4.5.1"
FALLBACK_RUFF_VERSION = "v0.15.7"
FALLBACK_SYNC_WITH_UV_VERSION = "v0.5.0"
FALLBACK_PYPROJECT_FMT_VERSION = "v2.20.0"
FALLBACK_CODESPELL_VERSION = "v2.4.2"
7 changes: 3 additions & 4 deletions src/usethis/_integrations/pre_commit/version.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
from usethis._config import usethis_config
from usethis._fallback import FALLBACK_PRE_COMMIT_VERSION
from usethis._integrations.pre_commit.yaml import PreCommitConfigYAMLManager

PRE_COMMIT_VERSION = "4.5.1"


def get_pre_commit_version() -> str:
"""Get an inferred pre-commit version for usethis to target.

If no version can be inferred, a hard-coded version is used, corresponding to a
recent release (see `PRE_COMMIT_VERSION`).
recent release (see `FALLBACK_PRE_COMMIT_VERSION`).
"""
version = get_minimum_pre_commit_version()
if version is not None:
return version
return PRE_COMMIT_VERSION
return FALLBACK_PRE_COMMIT_VERSION


def get_minimum_pre_commit_version() -> str | None:
Expand Down
7 changes: 3 additions & 4 deletions src/usethis/_tool/impl/base/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from usethis._config import usethis_config
from usethis._config_file import DotRuffTOMLManager, RuffTOMLManager
from usethis._console import how_print, tick_print
from usethis._fallback import FALLBACK_RUFF_VERSION
from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager
from usethis._integrations.ci.bitbucket import schema as bitbucket_schema
from usethis._integrations.ci.bitbucket.anchor import (
Expand All @@ -35,8 +36,6 @@
from usethis._file.manager import KeyValueFileManager
from usethis._tool.rule import RuleConfig

_RUFF_VERSION = "v0.15.7" # Manually bump this version when necessary


@final
class RuffTool(RuffToolSpec, Tool):
Expand Down Expand Up @@ -110,7 +109,7 @@ def pre_commit_config(self) -> PreCommitConfig:
PreCommitRepoConfig(
repo=pre_commit_schema.UriRepo(
repo="https://github.com/astral-sh/ruff-pre-commit",
rev=_RUFF_VERSION,
rev=FALLBACK_RUFF_VERSION,
hooks=[pre_commit_schema.HookDefinition(id="ruff-check")],
),
requires_venv=False,
Expand All @@ -121,7 +120,7 @@ def pre_commit_config(self) -> PreCommitConfig:
PreCommitRepoConfig(
repo=pre_commit_schema.UriRepo(
repo="https://github.com/astral-sh/ruff-pre-commit",
rev=_RUFF_VERSION,
rev=FALLBACK_RUFF_VERSION,
hooks=[pre_commit_schema.HookDefinition(id="ruff-format")],
),
requires_venv=False,
Expand Down
5 changes: 2 additions & 3 deletions src/usethis/_tool/impl/spec/codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from usethis._config import usethis_config
from usethis._config_file import DotCodespellRCManager
from usethis._fallback import FALLBACK_CODESPELL_VERSION
from usethis._file.pyproject_toml.errors import PyprojectTOMLNotFoundError
from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager
from usethis._file.pyproject_toml.requires_python import (
Expand All @@ -24,8 +25,6 @@
if TYPE_CHECKING:
from usethis._file.manager import KeyValueFileManager

_CODESPELL_VERSION = "v2.4.2" # Manually bump this version when necessary


class CodespellToolSpec(ToolSpec):
@final
Expand Down Expand Up @@ -77,7 +76,7 @@ def pre_commit_config(self) -> PreCommitConfig:
return PreCommitConfig.from_single_repo(
pre_commit_schema.UriRepo(
repo="https://github.com/codespell-project/codespell",
rev=_CODESPELL_VERSION,
rev=FALLBACK_CODESPELL_VERSION,
hooks=[
pre_commit_schema.HookDefinition(
id="codespell", additional_dependencies=["tomli"]
Expand Down
5 changes: 2 additions & 3 deletions src/usethis/_tool/impl/spec/pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
from typing_extensions import assert_never, override

from usethis._backend.dispatch import get_backend
from usethis._fallback import FALLBACK_SYNC_WITH_UV_VERSION
from usethis._integrations.pre_commit import schema as pre_commit_schema
from usethis._integrations.pre_commit.cmd_ import pre_commit_raw_cmd
from usethis._tool.base import ToolMeta, ToolSpec
from usethis._tool.pre_commit import PreCommitConfig
from usethis._types.backend import BackendEnum
from usethis._types.deps import Dependency

_SYNC_WITH_UV_VERSION = "v0.5.0" # Manually bump this version when necessary


class PreCommitToolSpec(ToolSpec):
@final
Expand Down Expand Up @@ -47,7 +46,7 @@ def pre_commit_config(self) -> PreCommitConfig:
return PreCommitConfig.from_single_repo(
pre_commit_schema.UriRepo(
repo="https://github.com/tsvikas/sync-with-uv",
rev=_SYNC_WITH_UV_VERSION,
rev=FALLBACK_SYNC_WITH_UV_VERSION,
hooks=[pre_commit_schema.HookDefinition(id="sync-with-uv")],
),
requires_venv=False,
Expand Down
5 changes: 2 additions & 3 deletions src/usethis/_tool/impl/spec/pyproject_fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

from typing_extensions import override

from usethis._fallback import FALLBACK_PYPROJECT_FMT_VERSION
from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager
from usethis._integrations.pre_commit import schema as pre_commit_schema
from usethis._tool.base import ToolMeta, ToolSpec
from usethis._tool.config import ConfigEntry, ConfigItem, ConfigSpec
from usethis._tool.pre_commit import PreCommitConfig
from usethis._types.deps import Dependency

_PYPROJECT_FMT_VERSION = "v2.20.0" # Manually bump this version when necessary


class PyprojectFmtToolSpec(ToolSpec):
@final
Expand Down Expand Up @@ -42,7 +41,7 @@ def pre_commit_config(self) -> PreCommitConfig:
return PreCommitConfig.from_single_repo(
pre_commit_schema.UriRepo(
repo="https://github.com/tox-dev/pyproject-fmt",
rev=_PYPROJECT_FMT_VERSION,
rev=FALLBACK_PYPROJECT_FMT_VERSION,
hooks=[pre_commit_schema.HookDefinition(id="pyproject-fmt")],
),
requires_venv=False,
Expand Down
32 changes: 2 additions & 30 deletions tests/usethis/_backend/uv/test_version.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@
import os
from pathlib import Path

import pytest

from usethis._backend.uv.errors import UVSubprocessFailedError
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
from usethis._backend.uv.version import get_uv_version, next_breaking_uv_version
from usethis._fallback import FALLBACK_UV_VERSION
from usethis._test import change_cwd


class TestGetUVVersion:
@pytest.mark.usefixtures("_vary_network_conn")
def test_latest_version(self):
if os.getenv("CI"):
pytest.skip("Avoid flaky pipelines by testing version bumps manually")

try:
assert (
get_github_latest_tag(owner="astral-sh", repo="uv")
== FALLBACK_UV_VERSION
)
except GitHubTagError as err:
if (
usethis_config.offline
or "rate limit exceeded for url" in str(err)
or "Read timed out." in str(err)
):
pytest.skip(
"Failed to fetch GitHub tags (connection issues); skipping test"
)
raise err

def test_matches_pattern(self, tmp_path: Path):
# Act
with change_cwd(tmp_path):
Expand Down
32 changes: 16 additions & 16 deletions tests/usethis/_core/test_core_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
use_ty,
)
from usethis._deps import add_deps_to_group, get_deps_from_group, is_dep_satisfied_in
from usethis._fallback import FALLBACK_RUFF_VERSION, FALLBACK_SYNC_WITH_UV_VERSION
from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager
from usethis._integrations.pre_commit.hooks import _HOOK_ORDER, get_hook_ids
from usethis._integrations.pre_commit.yaml import PreCommitConfigYAMLManager
from usethis._python.version import PythonVersion
from usethis._test import change_cwd
from usethis._tool.all_ import ALL_TOOLS
from usethis._tool.impl.base.ruff import _RUFF_VERSION, RuffTool
from usethis._tool.impl.spec.pre_commit import _SYNC_WITH_UV_VERSION
from usethis._tool.impl.base.ruff import RuffTool
from usethis._types.backend import BackendEnum
from usethis._types.deps import Dependency

Expand Down Expand Up @@ -725,7 +725,7 @@ def test_pre_commit_after(
f"""\
repos:
- repo: https://github.com/tsvikas/sync-with-uv
rev: {_SYNC_WITH_UV_VERSION}
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
hooks:
- id: sync-with-uv
- repo: local
Expand Down Expand Up @@ -893,7 +893,7 @@ def test_pre_commit_first(
f"""\
repos:
- repo: https://github.com/tsvikas/sync-with-uv
rev: {_SYNC_WITH_UV_VERSION}
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
hooks:
- id: sync-with-uv
- repo: local
Expand Down Expand Up @@ -1907,7 +1907,7 @@ def test_fresh(self, uv_init_dir: Path, capfd: pytest.CaptureFixture[str]):
f"""\
repos:
- repo: https://github.com/tsvikas/sync-with-uv
rev: {_SYNC_WITH_UV_VERSION}
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
hooks:
- id: sync-with-uv
"""
Expand Down Expand Up @@ -1985,7 +1985,7 @@ def test_config_file_already_exists(self, uv_init_repo_dir: Path):
entry: uv run --isolated --frozen --offline python -c "print('hello world!')"
language: system
- repo: https://github.com/tsvikas/sync-with-uv
rev: {_SYNC_WITH_UV_VERSION}
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
hooks:
- id: sync-with-uv
"""
Expand Down Expand Up @@ -3435,7 +3435,7 @@ def test_pre_commit(
f"""\
repos:
- repo: https://github.com/tsvikas/sync-with-uv
rev: {_SYNC_WITH_UV_VERSION}
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
hooks:
- id: sync-with-uv
- repo: local
Expand Down Expand Up @@ -3985,11 +3985,11 @@ def test_add_only_linter(
f"""\
repos:
- repo: https://github.com/tsvikas/sync-with-uv
rev: {_SYNC_WITH_UV_VERSION}
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
hooks:
- id: sync-with-uv
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: {_RUFF_VERSION}
rev: {FALLBACK_RUFF_VERSION}
hooks:
- id: ruff-check
"""
Expand Down Expand Up @@ -4023,15 +4023,15 @@ def test_add_only_linter_to_existing_formatter(
f"""\
repos:
- repo: https://github.com/tsvikas/sync-with-uv
rev: {_SYNC_WITH_UV_VERSION}
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
hooks:
- id: sync-with-uv
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: {_RUFF_VERSION}
rev: {FALLBACK_RUFF_VERSION}
hooks:
- id: ruff-check
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: {_RUFF_VERSION}
rev: {FALLBACK_RUFF_VERSION}
hooks:
- id: ruff-format
"""
Expand Down Expand Up @@ -4064,11 +4064,11 @@ def test_add_only_formatter(
f"""\
repos:
- repo: https://github.com/tsvikas/sync-with-uv
rev: {_SYNC_WITH_UV_VERSION}
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
hooks:
- id: sync-with-uv
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: {_RUFF_VERSION}
rev: {FALLBACK_RUFF_VERSION}
hooks:
- id: ruff-format
"""
Expand Down Expand Up @@ -4102,11 +4102,11 @@ def test_remove_only_linter(
f"""\
repos:
- repo: https://github.com/tsvikas/sync-with-uv
rev: {_SYNC_WITH_UV_VERSION}
rev: {FALLBACK_SYNC_WITH_UV_VERSION}
hooks:
- id: sync-with-uv
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: {_RUFF_VERSION}
rev: {FALLBACK_RUFF_VERSION}
hooks:
- id: ruff-format
"""
Expand Down
6 changes: 3 additions & 3 deletions tests/usethis/_integrations/pre_commit/test_version.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pathlib import Path

from usethis._config_file import files_manager
from usethis._fallback import FALLBACK_PRE_COMMIT_VERSION
from usethis._integrations.pre_commit.version import (
PRE_COMMIT_VERSION,
get_minimum_pre_commit_version,
get_pre_commit_version,
)
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_falls_back_to_hardcoded_when_config_doesnt_exist(self, tmp_path: Path):
result = get_pre_commit_version()

# Assert
assert result == PRE_COMMIT_VERSION
assert result == FALLBACK_PRE_COMMIT_VERSION

def test_falls_back_to_hardcoded_when_minimum_not_declared(self, tmp_path: Path):
# Arrange
Expand All @@ -96,4 +96,4 @@ def test_falls_back_to_hardcoded_when_minimum_not_declared(self, tmp_path: Path)
result = get_pre_commit_version()

# Assert
assert result == PRE_COMMIT_VERSION
assert result == FALLBACK_PRE_COMMIT_VERSION
Loading
Loading