Skip to content

Commit 748c4c6

Browse files
authored
Merge pull request #137 from stefanv/update-pre-commit
Update pre-commit to use Ruff; update versions and add a few rules
2 parents 40f0335 + ace66c2 commit 748c4c6

File tree

5 files changed

+36
-36
lines changed

5 files changed

+36
-36
lines changed

.pre-commit-config.yaml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,45 @@
1010
#
1111
repos:
1212
# Autoformat: Python code
13-
- repo: https://github.com/ambv/black
14-
rev: 23.1.0
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: f0fe93c067104b76ffb58852abe79673a8429bd1 # frozen: v0.11.8
1515
hooks:
16-
- id: black
16+
- id: ruff
17+
args: ["--fix", "--show-fixes", "--exit-non-zero-on-fix"]
18+
- id: ruff-format
1719

1820
# Autoformat: markdown, yaml
1921
- repo: https://github.com/pre-commit/mirrors-prettier
20-
rev: v3.0.0-alpha.4
22+
rev: 787fb9f542b140ba0b2aced38e6a3e68021647a3 # frozen: v3.5.3
2123
hooks:
2224
- id: prettier
2325
exclude: tests/.*
2426

25-
# Autoformat: https://github.com/asottile/reorder_python_imports
26-
- repo: https://github.com/asottile/reorder_python_imports
27-
rev: v3.9.0
28-
hooks:
29-
- id: reorder-python-imports
30-
3127
# Misc...
3228
- repo: https://github.com/pre-commit/pre-commit-hooks
33-
rev: v4.4.0
29+
rev: 3e8a8703264a2f4a69428a0aa4dcb512790b2c8c # v6.0.0
3430
# ref: https://github.com/pre-commit/pre-commit-hooks#hooks-available
3531
hooks:
36-
# Autoformat: Makes sure files end in a newline and only a newline.
37-
- id: end-of-file-fixer
38-
exclude: tests/.*
39-
40-
# Autoformat: Sorts entries in requirements.txt.
41-
- id: requirements-txt-fixer
42-
43-
# Lint: Check for files with names that would conflict on a
44-
# case-insensitive filesystem like MacOS HFS+ or Windows FAT.
32+
# Sanity checks
33+
- id: check-added-large-files
4534
- id: check-case-conflict
46-
47-
# Lint: Checks that non-binary executables have a proper shebang.
4835
- id: check-executables-have-shebangs
36+
- id: check-illegal-windows-names
37+
- id: check-merge-conflict
4938

50-
# Lint: Python code
51-
- repo: https://github.com/pycqa/flake8
52-
rev: "6.0.0"
53-
hooks:
54-
- id: flake8
39+
# Checks based on file type
40+
- id: check-toml
41+
- id: check-yaml
42+
43+
# Detect mistakes
44+
- id: debug-statements
45+
- id: detect-private-key
46+
- id: forbid-submodules
47+
48+
# Automatic fixes
49+
- id: mixed-line-ending
50+
args: [--fix=lf]
51+
- id: trailing-whitespace
52+
- id: requirements-txt-fixer
53+
- id: end-of-file-fixer
54+
exclude: tests/.*

github_activity/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
__version__ = "1.0.3"
2+
__all__ = ["get_activity", "generate_activity_md"]
23

34
from .github_activity import get_activity, generate_activity_md

github_activity/github_activity.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Use the GraphQL api to grab issues/PRs that match a query."""
2+
23
import dataclasses
34
import datetime
45
import fnmatch
@@ -7,10 +8,8 @@
78
import shlex
89
import subprocess
910
import sys
10-
import urllib
1111
from collections import OrderedDict
1212
from json import loads
13-
from pathlib import Path
1413
from subprocess import CalledProcessError
1514
from subprocess import PIPE
1615
from subprocess import run
@@ -567,8 +566,6 @@ def filter_ignored(userlist):
567566
return
568567

569568
# Separate into closed and opened
570-
until_dt_str = data.until_dt_str
571-
since_dt_str = data.since_dt_str
572569
closed = data.query("closedAt >= @since_dt_str and closedAt <= @until_dt_str")
573570
opened = data.query("createdAt >= @since_dt_str and createdAt <= @until_dt_str")
574571

@@ -691,7 +688,7 @@ def filter_ignored(userlist):
691688
items["md"].append("")
692689

693690
for irow, irowdata in items["data"].iterrows():
694-
author = irowdata["author"]
691+
# author = irowdata["author"]
695692
ititle = irowdata["title"]
696693
if strip_brackets and ititle.strip().startswith("[") and "]" in ititle:
697694
ititle = ititle.split("]", 1)[-1].strip()
@@ -855,11 +852,11 @@ def _get_datetime_and_type(org, repo, datetime_or_git_ref, auth):
855852
try:
856853
dt = _get_datetime_from_git_ref(org, repo, datetime_or_git_ref, auth)
857854
return (dt, True)
858-
except Exception as ref_error:
855+
except Exception:
859856
try:
860857
dt = dateutil.parser.parse(datetime_or_git_ref)
861858
return (dt, False)
862-
except Exception as datetime_error:
859+
except Exception:
863860
raise ValueError(
864861
"{0} not found as a ref or valid date format".format(
865862
datetime_or_git_ref

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@ search = 'version = "{current_version}"'
8181
[[tool.tbump.file]]
8282
src = "github_activity/__init__.py"
8383
search = '__version__ = "{current_version}"'
84+
85+
[tool.ruff.lint.per-file-ignores]
86+
"docs/conf.py" = ["E402"]

tests/test_cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import shutil
32
from pathlib import Path
43
from subprocess import run
@@ -126,7 +125,7 @@ def test_cli_ignore_user(tmpdir):
126125
cmd = f"github-activity executablebooks/github-activity --ignore-contributor choldgraf -s v1.0.2 -o {path_output}"
127126
run(cmd.split(), check=True)
128127
md = path_output.read_text()
129-
assert not "@choldgraf" in md
128+
assert "@choldgraf" not in md
130129

131130

132131
def test_contributor_sorting(tmpdir, file_regression):

0 commit comments

Comments
 (0)