Skip to content

Commit cd96b71

Browse files
authored
Replace formatting tools and pylint with ruff (#786)
* Also, remove superfluous rules from `.yamllint`
1 parent d367774 commit cd96b71

File tree

14 files changed

+137
-291
lines changed

14 files changed

+137
-291
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ repos:
1616
- id: trailing-whitespace
1717
- repo: local
1818
hooks:
19-
- id: pylint
20-
name: pylint
21-
entry: bin/lint.sh pylint
19+
- id: lint
20+
name: lint
21+
entry: bin/lint.sh lint
2222
language: script
2323
types: [python]
2424
- repo: local
@@ -43,16 +43,9 @@ repos:
4343
language: script
4444
- repo: local
4545
hooks:
46-
- id: isort
47-
name: isort
48-
entry: bin/lint.sh isort
49-
language: script
50-
types: [python]
51-
- repo: local
52-
hooks:
53-
- id: black
54-
name: black
55-
entry: bin/lint.sh black
46+
- id: format
47+
name: format
48+
entry: bin/lint.sh format
5649
language: script
5750
types: [python]
5851
- repo: local

.yamllint

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
---
2-
32
extends: default
43

5-
ignore: |
6-
jbi/
7-
tests/
8-
bin/
9-
.github/
10-
docker-compose.yaml
11-
.pre-commit-config.yaml
12-
13-
144
rules:
155
key-duplicates: enable
166

17-
18-
yaml-files:
19-
- 'config/*.yaml'
20-
- '.yamllint'

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ help:
1616
@echo ""
1717
@echo "Local"
1818
@echo " clean - clean local cache folders"
19-
@echo " format - run formatters (black, isort), fix in place"
20-
@echo " lint - run linters"
19+
@echo " format - run linting checks, fix in place"
20+
@echo " lint - run linting checks"
2121
@echo " start - run the API service locally"
2222
@echo " test - run test suite"
2323
@echo ""
@@ -31,7 +31,7 @@ help:
3131
.PHONY: clean
3232
clean:
3333
find . -name "__pycache__" | xargs rm -rf
34-
rm -rf .mypy_cache .pytest_cache .coverage .venv
34+
rm -rf .mypy_cache .ruff_cache .coverage .venv
3535

3636
$(VENV)/bin/python:
3737
python3 -m venv $(VENV)
@@ -49,8 +49,8 @@ build:
4949

5050
.PHONY: format
5151
format: $(INSTALL_STAMP)
52-
bin/lint.sh black --fix
53-
bin/lint.sh isort --fix
52+
bin/lint.sh lint --fix
53+
bin/lint.sh format --fix
5454

5555
.PHONY: lint
5656
lint: $(INSTALL_STAMP)

asgi.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import uvicorn
22

33
from jbi.environment import get_settings
4-
from jbi.log import CONFIG as LOGGING_CONFIG
54

65
settings = get_settings()
76

bin/lint.sh

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,83 +4,83 @@ set -e
44

55
POETRY_RUN="poetry run"
66

7-
bandit () {
8-
$POETRY_RUN bandit -lll --recursive jbi
9-
}
10-
black () {
11-
$POETRY_RUN black ${check:+--check} jbi tests
12-
}
13-
detect_secrets () {
14-
# Scan only files fixed into the repo, omit poetry.lock
15-
FILES_TO_SCAN=`git ls-tree --full-tree -r --name-only HEAD | grep -v poetry.lock`
16-
$POETRY_RUN detect-secrets-hook $FILES_TO_SCAN --baseline .secrets.baseline
17-
}
18-
isort () {
19-
$POETRY_RUN isort ${check:+--check-only} .
20-
}
21-
pylint () {
22-
$POETRY_RUN pylint jbi tests
23-
}
24-
mypy () {
25-
$POETRY_RUN mypy jbi
26-
}
27-
yamllint () {
28-
$POETRY_RUN yamllint -c .yamllint config/*.yaml
29-
}
7+
BANDIT_CMD="$POETRY_RUN bandit -lll --recursive jbi"
8+
9+
FORMAT_CMD="$POETRY_RUN ruff format ."
10+
11+
# Scan only files fixed into the repo, omit poetry.lock
12+
DETECT_SECRETS_FILES="$(git ls-tree --full-tree -r --name-only HEAD | grep -v poetry.lock)"
13+
DETECT_SECRETS_CMD="$POETRY_RUN detect-secrets-hook $DETECT_SECRETS_FILES --baseline .secrets.baseline"
14+
15+
LINT_CMD="$POETRY_RUN ruff ."
16+
17+
MYPY_CMD="$POETRY_RUN mypy jbi"
18+
19+
YAMLLINT_CMD="$POETRY_RUN yamllint -c .yamllint config/*.yaml"
20+
3021
all () {
31-
echo "running black"
32-
black
33-
echo "running isort"
34-
isort
22+
echo "running bandit"
23+
$BANDIT_CMD
24+
echo "running format"
25+
$FORMAT_CMD
26+
echo "running detect-secrets"
27+
$DETECT_SECRETS_CMD
28+
echo "running lint"
29+
$LINT_CMD
3530
echo "running mypy"
36-
mypy
37-
echo "running pylint"
38-
pylint
31+
$MYPY_CMD
3932
echo "running yamllint"
40-
yamllint
41-
echo "running bandit"
42-
bandit
43-
echo "running detect_secrets"
44-
detect_secrets
33+
$YAMLLINT_CMD
4534
}
4635

4736
usage () {
48-
echo "Usage: bin/lint.sh [OPTION]"
49-
echo " run linting checks"
50-
echo "Options":
37+
echo "Usage: bin/lint.sh [subcommand] [--fix]"
38+
echo " run linting checks, and optionally fix in place (if available)"
39+
echo "Subcommand":
5140
echo " bandit"
52-
echo " black [--fix]"
5341
echo " detect-secrets"
54-
echo " isort [--fix]"
42+
echo " format"
43+
echo " lint"
5544
echo " mypy"
56-
echo " pylint"
5745
echo " yamllint"
5846
}
5947

60-
subcommand='';
61-
check="true"
62-
if [ -z $1 ]; then
48+
if [ -z "$1" ]; then
6349
all
6450
else
6551
subcommand=$1; shift
6652
case $subcommand in
67-
"black" | "isort")
68-
case $1 in
69-
"--fix")
70-
check=""
71-
;;
72-
esac
73-
case $subcommand in
74-
"isort") isort;;
75-
"black") black;;
76-
esac
77-
;;
78-
79-
"pylint") pylint;;
80-
"yamllint") yamllint;;
81-
"mypy") mypy;;
82-
"bandit") bandit;;
83-
"detect-secrets") detect_secrets;;
84-
*) usage;;
53+
"format")
54+
if [ -n "$1" ] && [ "$1" != "--fix" ]; then
55+
usage
56+
else
57+
check_flag="--check"
58+
[ "$1" = "--fix" ] && check_flag=""
59+
$FORMAT_CMD ${check_flag:-}
60+
fi
61+
;;
62+
"lint")
63+
if [ -n "$1" ] && [ "$1" != "--fix" ]; then
64+
usage
65+
else
66+
$LINT_CMD ${1:-}
67+
fi
68+
;;
69+
"yamllint")
70+
$YAMLLINT_CMD
71+
;;
72+
"mypy")
73+
$MYPY_CMD
74+
;;
75+
"bandit")
76+
$BANDIT_CMD
77+
;;
78+
"detect-secrets")
79+
$DETECT_SECRETS_CMD
80+
;;
81+
*)
82+
usage
83+
;;
8584
esac
8685
fi
86+

jbi/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ class Actions(RootModel):
110110
@functools.cached_property
111111
def by_tag(self) -> Mapping[str, Action]:
112112
"""Build mapping of actions by lookup tag."""
113-
# pylint: disable-next=not-an-iterable
113+
114114
return {action.whiteboard_tag: action for action in self.root}
115115

116116
def __iter__(self):
117-
return iter(self.root) # pylint: disable=not-an-iterable
117+
return iter(self.root)
118118

119119
def __len__(self):
120120
return len(self.root)
@@ -129,7 +129,7 @@ def get(self, tag: Optional[str]) -> Optional[Action]:
129129
@functools.cached_property
130130
def configured_jira_projects_keys(self) -> set[str]:
131131
"""Return the list of Jira project keys from all configured actions"""
132-
# pylint: disable-next=not-an-iterable
132+
133133
return {action.jira_project_key for action in self.root}
134134

135135
@field_validator("root")
@@ -192,7 +192,7 @@ class BugzillaWebhookEvent(BaseModel):
192192

193193
def changed_fields(self) -> list[str]:
194194
"""Returns the names of changed fields in a bug"""
195-
# pylint: disable-next=not-an-iterable
195+
196196
return [c.field for c in self.changes] if self.changes else []
197197

198198

@@ -246,7 +246,7 @@ def extract_from_see_also(self, project_key):
246246
return None
247247

248248
candidates = []
249-
for url in self.see_also: # pylint: disable=not-an-iterable
249+
for url in self.see_also:
250250
try:
251251
parsed_url: ParseResult = urlparse(url=url)
252252
host_parts = parsed_url.hostname.split(".")

jbi/services/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
"""Exports the bugzilla and jira services modules for convenience"""
22

33
from . import bugzilla, jira
4+
5+
__all__ = ["bugzilla", "jira"]

0 commit comments

Comments
 (0)