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
32 changes: 27 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,37 @@ repos:
rev: v0.4.0
hooks:
- id: sync-with-uv
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.9.1
- repo: local
hooks:
- id: uv-lock
name: uv-lock
entry: uv lock --offline
files: ^(uv\.lock|pyproject\.toml|uv\.toml)$
language: system
always_run: true
pass_filenames: false
- id: uv-sync
name: uv-sync
entry: uv sync --no-active --offline
args: [--locked]
language: system
always_run: true
pass_filenames: false
stages: [manual, pre-commit, pre-push, post-checkout, post-merge, post-rewrite]
- id: uv-export
- id: uv-export
name: uv-export
files: ^uv\.lock$
entry: uv export --frozen --offline --quiet -o=requirements.txt
language: system
pass_filenames: false
require_serial: true
- id: uv-export-docs
name: uv-export-docs
args: [--only-group, doc, -o=docs/requirements.txt]
- id: uv-sync
files: ^uv\.lock$
entry: uv export --frozen --offline --quiet --only-group doc -o='docs/requirements.txt'
language: system
pass_filenames: false
require_serial: true
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file was autogenerated by uv via the following command:
# uv export --only-group doc -o=docs/requirements.txt
# uv export --frozen --offline --only-group doc -o=docs/requirements.txt
babel==2.17.0 \
--hash=sha256:0c54cffb19f690cdcc52a3b50bcbf71e07a808d1c80d549f2459b9d2cf0afb9d \
--hash=sha256:4d0b53093fdfb4b21c92b5213dba5a1b23885afa8383709427046b21c366e5f2
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ dev = [
"prek>=0.2.4",
"pyright[nodejs]>=1.1.399",
"ruff>=0.11.5",
"uv>=0.9.1",
]
test = [
"click>=8.1.8",
Expand Down
22 changes: 1 addition & 21 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file was autogenerated by uv via the following command:
# uv export --frozen --output-file=requirements.txt
# uv export --frozen --offline -o=requirements.txt
-e .
annotated-types==0.7.0 \
--hash=sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53 \
Expand Down Expand Up @@ -950,26 +950,6 @@ urllib3==2.5.0 \
--hash=sha256:3fc47733c7e419d4bc3f6b3dc2b4f890bb743906a30d56ba4a5bfa4bbff92760 \
--hash=sha256:e6b01673c0fa6a13e374b50871808eb3bf7046c4b125b216f6bf1cc604cff0dc
# via requests
uv==0.9.1 \
--hash=sha256:0a0ef25f76889ce115d761e411f895edc11198dc480cf8897d169c548617cc9e \
--hash=sha256:0fbc6314a9466cb3205e99cd8ce74b247a21d4a669fd68948a343882423a644b \
--hash=sha256:21901c8e1450e8b8e5261e1bd0f70b4e6e177befe7b4c45195e29e7c933dc7a9 \
--hash=sha256:2b066c3a8cd5ae6836e703ace02973d1180fbfdc359eed37d7009e691f82a631 \
--hash=sha256:2b483d8a5c184b425ecc750b1a7299ab3f35a0ce0d23d71dbc936a15d53cc171 \
--hash=sha256:341ddf77399665b5bff418a2ba6f28b8aa2adf5214a4a0eb117ce9fa54b2146f \
--hash=sha256:549e2df5f9bf89d1c89f0c7e47cfac3f7f91ca29cade8163a5e3d7caeb21cd22 \
--hash=sha256:5fa03e40598ca86ce5bd1d50de764bfd2617758dfc45a80652385c53d4d4bb3c \
--hash=sha256:61c336460532a9a484478021985f13dd8b2d8d79eae6cf9c5eec40e1a588363c \
--hash=sha256:6afc4ac065a4128fe59de71f51cee1cca6bd4191e236a996aaf3956312cccf18 \
--hash=sha256:6b96da925a8cd573d7c48fe281d7980e7dd2f14ea16fd2c781642a1eaf95d0cf \
--hash=sha256:6de817ee4e2e8d69a84f335d83ac26e4abb8fecf063f0b332da4d1826cab82b8 \
--hash=sha256:6fa81bdd8bb1e98d5c6cb0df82a5114a69a444c2243fdf6ee8f7bf2bcd59024e \
--hash=sha256:7bd675feba773de5b4252ac152a0641c4ee6357f101adf57205168d93a325359 \
--hash=sha256:ba781dfe5cd33f12bf332d582d0c31c8c97cecc022605c3fa2d7a1166f98581d \
--hash=sha256:bdf3cc509a5ccef4edf776beac72d50718ff900fb55a5a9b6411f87bad972857 \
--hash=sha256:c49a71cb22db8e3ba80c2b417bef8c0ad05ef41b5222ededc000f4dcb48bab92 \
--hash=sha256:c9e1418972a70d2aec065015b76977cce2d1ee8e36bbe659ca5e376a773a4231 \
--hash=sha256:f315a6068c5dc99aa4f50aaa52af3a1f38ea3d3ee03342d5f8439299e2d402ca
watchdog==6.0.0 \
--hash=sha256:07df1fdd701c5d4c8e55ef6cf55b8f0120fe1aef7ef39a1c6fc6bc2e606d517a \
--hash=sha256:20ffe5b202af80ab4266dcd3e91aae72bf2da48c0d33bdb15c66658e685e94e2 \
Expand Down
12 changes: 9 additions & 3 deletions src/usethis/_integrations/pre_commit/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"validate-pyproject",
"uv-export",
"pyproject-fmt",
"ruff", # ruff followed by ruff-format seems to be the recommended way by Astral
"ruff", # Alias used for ruff-check
"ruff-check", # ruff-check followed by ruff-format seems to be the recommended way by Astral
"ruff-format",
"deptry",
"import-linter",
Expand Down Expand Up @@ -246,7 +247,7 @@ def extract_hook_ids(model: JsonSchemaForPreCommitConfigYaml) -> list[str]:
return hook_ids


def _hooks_are_equivalent(hook: HookDefinition, other: HookDefinition) -> bool:
def hooks_are_equivalent(hook: HookDefinition, other: HookDefinition) -> bool:
"""Check if two hooks are equivalent."""
if hook_ids_are_equivalent(hook.id, other.id):
return True
Expand All @@ -265,6 +266,11 @@ def hook_ids_are_equivalent(hook_id: str | None, other: str | None) -> bool:

# Same name up to case differences
if isinstance(hook_id, str) and isinstance(other, str):
return hook_id.lower() == other.lower()
hook_id_str = hook_id.lower()
other_str = other.lower()
if hook_id_str == other_str:
return True
if {hook_id_str, other_str} == {"ruff", "ruff-check"}:
return True

return False
7 changes: 5 additions & 2 deletions src/usethis/_tool/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,11 @@ def remove_pre_commit_repo_configs(self) -> None:

# Remove the config for this specific tool.
for hook in repo_config.hooks:
if hook.id in get_hook_ids():
remove_hook(hook.id)
for other_hook_id in get_hook_ids():
if hook.id is not None and hook_ids_are_equivalent(
hook.id, other_hook_id
):
remove_hook(hook.id)

def migrate_config_to_pre_commit(self) -> None:
"""Migrate the tool's configuration to pre-commit."""
Expand Down
4 changes: 3 additions & 1 deletion src/usethis/_tool/impl/codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
if TYPE_CHECKING:
from usethis._io import KeyValueFileManager

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


class CodespellTool(Tool):
# https://github.com/codespell-project/codespell
Expand Down Expand Up @@ -127,7 +129,7 @@ def get_pre_commit_config(self) -> PreCommitConfig:
return PreCommitConfig.from_single_repo(
UriRepo(
repo="https://github.com/codespell-project/codespell",
rev="v2.4.1", # Manually bump this version when necessary
rev=_CODESPELL_VERSION,
hooks=[
HookDefinition(id="codespell", additional_dependencies=["tomli"])
],
Expand Down
61 changes: 15 additions & 46 deletions src/usethis/_tool/impl/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
from usethis._integrations.ci.bitbucket.schema import Step as BitbucketStep
from usethis._integrations.file.pyproject_toml.io_ import PyprojectTOMLManager
from usethis._integrations.pre_commit.schema import (
FileType,
FileTypes,
HookDefinition,
Language,
LocalRepo,
UriRepo,
)
from usethis._tool.base import Tool
from usethis._tool.config import (
Expand All @@ -38,6 +35,8 @@
from usethis._io import KeyValueFileManager
from usethis._tool.rule import Rule, RuleConfig

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


class RuffTool(Tool):
# https://github.com/astral-sh/ruff
Expand Down Expand Up @@ -243,54 +242,24 @@ def get_pre_commit_config(self) -> PreCommitConfig:
if self.is_linter_used():
repo_configs.append(
PreCommitRepoConfig(
repo=LocalRepo(
repo="local",
hooks=[
HookDefinition(
id="ruff",
name="ruff",
entry="uv run --frozen --offline ruff check --fix --force-exclude",
language=Language("system"),
types_or=FileTypes(
[
FileType("python"),
FileType("pyi"),
FileType("jupyter"),
]
),
always_run=True,
require_serial=True,
),
],
repo=UriRepo(
repo="https://github.com/astral-sh/ruff-pre-commit",
rev=_RUFF_VERSION,
hooks=[HookDefinition(id="ruff-check")],
),
requires_venv=True,
)
requires_venv=False,
),
)
if self.is_formatter_used():
repo_configs.append(
PreCommitRepoConfig(
repo=LocalRepo(
repo="local",
hooks=[
HookDefinition(
id="ruff-format",
name="ruff-format",
entry="uv run --frozen --offline ruff format --force-exclude",
language=Language("system"),
types_or=FileTypes(
[
FileType("python"),
FileType("pyi"),
FileType("jupyter"),
]
),
always_run=True,
require_serial=True,
),
],
repo=UriRepo(
repo="https://github.com/astral-sh/ruff-pre-commit",
rev=_RUFF_VERSION,
hooks=[HookDefinition(id="ruff-format")],
),
requires_venv=True,
)
requires_venv=False,
),
)
return PreCommitConfig(
repo_configs=repo_configs,
Expand Down
Loading