Skip to content

Commit 30ad054

Browse files
authored
Merge pull request #396 from thenewboston-developers/367-migrate-to-ruff-for-formatting-and-linting
Ruff introduction
2 parents e146bdb + d1c7f52 commit 30ad054

File tree

124 files changed

+1712
-1383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1712
-1383
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ root = true
44
charset = utf-8
55
indent_size = 4
66
indent_style = space
7-
max_line_length = 119
7+
max_line_length = 120

.flake8

Lines changed: 0 additions & 18 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/pycqa/isort
5-
rev: 5.12.0
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v6.0.0
66
hooks:
7-
- id: isort
8-
name: isort (python)
9-
- repo: https://github.com/google/yapf
10-
rev: v0.40.2
7+
- id: check-toml
8+
alias: common
9+
- id: end-of-file-fixer
10+
alias: common
11+
- id: trailing-whitespace
12+
alias: common
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.12.8
1115
hooks:
12-
- id: yapf
13-
additional_dependencies: [ toml ]
14-
- repo: https://github.com/pre-commit/mirrors-mypy
15-
rev: 'v1.16.1'
16-
hooks:
17-
- id: mypy
18-
additional_dependencies: [ types-requests, types-PyYAML, types-toml ]
19-
- repo: https://github.com/PyCQA/flake8
20-
rev: 7.0.0
21-
hooks:
22-
- id: flake8
23-
additional_dependencies:
24-
- flake8-bugbear
25-
- flake8-builtins
26-
- flake8-coding
27-
- flake8-isort
28-
- flake8-polyfill
29-
- flake8-quotes
16+
- id: ruff
17+
name: 'ruff fix imports'
18+
args: ["--select", "I", "--fix"]
19+
- id: ruff
20+
name: 'ruff (standard)'
21+
- id: ruff-format

DEPLOY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ ssh ubuntu@thenewboston.network
9696

9797
sudo vim /etc/thenewboston/.env
9898
```
99-
99+
100100
10. Install docker as described at https://docs.docker.com/engine/install/ on thenewboston.network
101101
11. Setup and check docker installation:
102102

@@ -107,7 +107,7 @@ exit
107107

108108
ssh ubuntu@thenewboston.network
109109

110-
# Known working versions described in the comments below
110+
# Known working versions described in the comments below
111111
docker --version # Docker version 26.0.1, build d260a54
112112

113113
# (!!!) At least Docker Compose version v2.24.0 is required

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**SECTIONS**
44
1. [Initial Project Setup](#initial-project-setup)
5-
2. [Essential Developer Guidelines](#essential-developer-guidelines)
5+
2. [Essential Developer Guidelines](#essential-developer-guidelines)
66

77

88
# Initial Project Setup
@@ -37,7 +37,7 @@ cp thenewboston/project/settings/templates/settings.unittests.py ./local/setting
3737

3838
5. Install / upgrade docker as described at https://docs.docker.com/engine/install/
3939
```bash
40-
# Known working versions described in the comments below
40+
# Known working versions described in the comments below
4141

4242
docker --version # Docker version 26.0.1, build d260a54
4343

pyproject.toml

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ pytest-parametrize-cases = "^0.1.2"
4646
pytest-asyncio = "^0.26.0"
4747
diff-cover = "^9.6.0"
4848

49-
[tool.isort]
50-
line_length = 119
51-
multi_line_output = 5
52-
5349
[tool.pytest.ini_options]
5450
DJANGO_SETTINGS_MODULE = "thenewboston.project.settings"
5551
django_find_project = false
@@ -64,13 +60,41 @@ env = [
6460
"THENEWBOSTON_SETTING_SECRET_KEY = dummy",
6561
]
6662

67-
[tool.yapf]
68-
align_closing_bracket_with_visual_indent = true
69-
based_on_style = "google"
70-
coalesce_brackets = true
71-
column_limit = 119
72-
dedent_closing_brackets = true
63+
[tool.ruff]
64+
line-length = 120
65+
indent-width = 4
66+
target-version = "py313"
67+
include = ["*.py"]
68+
exclude = [
69+
".git",
70+
".mypy_cache",
71+
"__pycache__",
72+
"venv"
73+
]
74+
75+
[tool.ruff.lint]
76+
# TODO(dmu) MEDIUM: Consider enabling all rules (`select = ["ALL"]`), but this will require
77+
# adding plenty of ignores manually
78+
ignore = ["A005", "D403", "F403", "F405"]
79+
80+
[tool.ruff.lint.mccabe]
81+
max-complexity = 12
82+
83+
[tool.ruff.lint.per-file-ignores]
84+
"thenewboston/project/settings/templates/settings.dev.py" = ["F821"]
85+
"thenewboston/project/settings/templates/settings.unittests.py" = ["F821"]
86+
87+
[tool.ruff.lint.isort]
88+
combine-as-imports = true
89+
relative-imports-order = "closest-to-furthest"
90+
known-first-party = ["app", "tests"]
91+
92+
[tool.ruff.format]
93+
quote-style = "single"
94+
indent-style = "space"
95+
skip-magic-trailing-comma = false
96+
line-ending = "auto"
7397

7498
[build-system]
7599
requires = ["poetry-core"]
76-
build-backend = "poetry.core.masonry.api"
100+
build-backend = "poetry.core.masonry.api"

thenewboston/authentication/views/login.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
class LoginView(APIView):
11-
1211
@staticmethod
1312
def post(request):
1413
serializer = LoginSerializer(data=request.data)

thenewboston/currencies/filters/currency.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class Meta:
1414

1515
def filter_no_wallet(self, queryset, name, value):
1616
if value and self.request.user.is_authenticated:
17-
user_wallet_currencies = Wallet.objects.filter(owner=self.request.user
18-
).values_list('currency_id', flat=True)
17+
user_wallet_currencies = Wallet.objects.filter(owner=self.request.user).values_list(
18+
'currency_id', flat=True
19+
)
1920
return queryset.exclude(id__in=user_wallet_currencies)
2021
return queryset

thenewboston/currencies/migrations/0001_initial.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
class Migration(migrations.Migration):
9-
109
initial = True
1110

1211
dependencies: List[Tuple[str, str]] = []

thenewboston/currencies/migrations/0002_initial.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
class Migration(migrations.Migration):
9-
109
initial = True
1110

1211
dependencies = [

0 commit comments

Comments
 (0)