Skip to content

Commit

Permalink
chore: resolve ruff config deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
boidolr committed Feb 4, 2024
1 parent ae065b5 commit 3d69498
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pre_commit_msg/format_message.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python3
import argparse
import pathlib
import sys
from collections.abc import Sequence


def _ensure_message_format(commit_msg_filepath: str, capitalize: bool) -> None:
# ensure there are always two empty lines between short description and description
with open(commit_msg_filepath, "r+") as fh:
with pathlib.Path(commit_msg_filepath).open("r+") as fh:
lines = fh.read().splitlines()
if len(lines) > 0 and capitalize:
lines[0] = lines[0].capitalize()
Expand Down
4 changes: 2 additions & 2 deletions pre_commit_msg/prepare_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _get_branch_name() -> str | None:


def _is_wrong_message_prefix(commit_msg_filepath: str, prefix_pattern: Pattern[str]) -> bool:
with open(commit_msg_filepath) as fh:
with Path(commit_msg_filepath).open() as fh:
commit_msg_start = fh.readline()
return prefix_pattern.match(commit_msg_start) is None

Expand All @@ -51,7 +51,7 @@ def _update_message(

issue = branch_match.group(1)
prefix = f"{issue}: "
with open(commit_msg_filepath, "r+") as fh:
with Path(commit_msg_filepath).open("r+") as fh:
commit_msg = fh.read()
if not commit_msg.startswith((prefix, "Merge", "Revert", "fixup!", "squash!")):
msg = prefix_pattern.sub("", commit_msg, count=1)
Expand Down
14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ packages = ["pre_commit_msg"]
[tool.ruff]
line-length = 120
fix = true

[tool.ruff.lint]
select = [
# Pyflakes
"F",
Expand All @@ -56,6 +58,8 @@ select = [
"W",
# pyupgrade
"UP",
# refurb
"FURB",
# flake8-bandit
"S",
# flake8-comprehensions
Expand All @@ -68,6 +72,10 @@ select = [
"SIM",
# flake8-pytest-style
"PT",
# flake8-return
"RET",
# flake8-use-pathlib
"PTH",
# flake8-tidy-imports (relative-imports)
"TID252",
# Perflint
Expand All @@ -80,13 +88,13 @@ select = [
"RUF100"
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/*.py" = ["S101"]

[tool.ruff.flake8-annotations]
[tool.ruff.lint.flake8-annotations]
ignore-fully-untyped = true

[tool.ruff.isort]
[tool.ruff.lint.isort]
force-single-line = true
order-by-type = false

Expand Down

0 comments on commit 3d69498

Please sign in to comment.