Skip to content

Commit f53bbe9

Browse files
authored
feat: Switch to Ruff (#96)
* feat: Switch to Ruff - Use `ruff` instead of `black`, `isort` and `flake8` - Switch to pre-commit for linting in CI - Infer Python version from `pyproject.toml` * fix: Formatting
1 parent 24da1f0 commit f53bbe9

File tree

8 files changed

+27
-118
lines changed

8 files changed

+27
-118
lines changed

.flake8

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

.github/workflows/pull-request.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,22 @@ jobs:
1717
FLAGSMITH_API_TOKEN: test_token
1818
ENVIRONMENT_API_KEYS: placeholder_key1
1919

20-
strategy:
21-
max-parallel: 4
22-
matrix:
23-
python-version: ["3.12"]
24-
2520
steps:
2621
- name: Cloning repo
2722
uses: actions/checkout@v4
2823

29-
- name: Set up Python ${{ matrix.python-version }}
24+
- name: Set up Python
3025
uses: actions/setup-python@v5
3126
with:
32-
python-version: ${{ matrix.python-version }}
27+
python-version-file: pyproject.toml
28+
29+
- name: Check linting
30+
uses: pre-commit/action@v3.0.1
3331

3432
- name: Install Dependencies
3533
run: |
3634
python -m pip install --upgrade pip
3735
pip install -r requirements.txt -r requirements-dev.txt
3836
39-
- name: Check black formatting
40-
run: black --check .
41-
42-
- name: Check flake8 linting
43-
run: flake8 --config=.flake8 .
44-
45-
- name: Check import order
46-
run: isort --check .
47-
4837
- name: Run Tests
4938
run: pytest -p no:warnings

.pre-commit-config.yaml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
repos:
2-
- repo: https://github.com/PyCQA/isort
3-
rev: 5.12.0
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.3.5
44
hooks:
5-
- id: isort
6-
name: isort (python)
7-
- repo: https://github.com/psf/black
8-
rev: 22.6.0
9-
hooks:
10-
- id: black
11-
language_version: python3
12-
exclude: migrations
13-
- repo: https://github.com/pycqa/flake8
14-
rev: '4.0.1'
15-
hooks:
16-
- id: flake8
17-
name: flake8
18-
entry: bash -c 'git diff --staged -- "$@" | flake8 --diff' --
5+
- id: ruff
6+
- id: ruff-format

fastapi_utils/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def repeat_every( # noqa: C901
4242
"""
4343

4444
def decorator(
45-
func: Union[NoArgsNoReturnAsyncFuncT, NoArgsNoReturnFuncT]
45+
func: Union[NoArgsNoReturnAsyncFuncT, NoArgsNoReturnFuncT],
4646
) -> NoArgsNoReturnAsyncFuncT:
4747
"""
4848
Converts the decorated function into a repeated, periodically-called version of itself.

pyproject.toml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,12 @@
33
# verbose regular expressions by Black. Use [ ] to denote a significant space
44
# character.
55

6-
[tool.black]
6+
[tool.ruff]
7+
target-version = 'py312'
78
line-length = 88
8-
target-version = ['py312']
9-
include = '\.pyi?$'
10-
exclude = '''
11-
/(
12-
\.eggs
13-
| \.git
14-
| \.hg
15-
| \.mypy_cache
16-
| \.tox
17-
| \.venv
18-
| _build
19-
| buck-out
20-
| build
21-
| dist
22-
| migrations
23-
)/
24-
'''
259

26-
[tool.isort]
27-
use_parentheses=true
28-
multi_line_output=3
29-
include_trailing_comma=true
30-
line_length=79
31-
known_first_party=['fastapi_utils']
10+
[tool.ruff.lint.isort]
11+
known-first-party = ['fastapi_utils']
12+
13+
[tool.ruff.lint.mccabe]
14+
max-complexity = 10

requirements-dev.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
pylint
2-
pep8
3-
autopep8
4-
black
51
pre-commit
6-
isort
7-
flake8
82
pytest
93
pytest-asyncio
104
pytest-mock

requirements-dev.txt

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,37 @@
11
#
2-
# This file is autogenerated by pip-compile with Python 3.12
2+
# This file is autogenerated by pip-compile with Python 3.10
33
# by the following command:
44
#
55
# pip-compile requirements-dev.in
66
#
7-
astroid==2.15.8
8-
# via pylint
9-
autopep8==2.0.4
10-
# via -r requirements-dev.in
11-
black==24.3.0
12-
# via -r requirements-dev.in
137
certifi==2023.7.22
148
# via -r requirements-dev.in
159
cfgv==3.4.0
1610
# via pre-commit
1711
classify-imports==4.2.0
1812
# via reorder-python-imports
19-
click==8.1.7
20-
# via black
21-
dill==0.3.7
22-
# via pylint
2313
distlib==0.3.7
2414
# via virtualenv
15+
exceptiongroup==1.2.0
16+
# via pytest
2517
filelock==3.12.4
2618
# via virtualenv
27-
flake8==6.1.0
28-
# via -r requirements-dev.in
2919
freezegun==1.4.0
3020
# via pytest-freezegun
3121
identify==2.5.29
3222
# via pre-commit
3323
iniconfig==2.0.0
3424
# via pytest
35-
isort==5.12.0
36-
# via
37-
# -r requirements-dev.in
38-
# pylint
39-
lazy-object-proxy==1.9.0
40-
# via astroid
41-
mccabe==0.7.0
42-
# via
43-
# flake8
44-
# pylint
45-
mypy-extensions==1.0.0
46-
# via black
4725
nodeenv==1.8.0
4826
# via pre-commit
4927
packaging==23.1
50-
# via
51-
# black
52-
# pytest
53-
pathspec==0.11.2
54-
# via black
55-
pep8==1.7.1
56-
# via -r requirements-dev.in
28+
# via pytest
5729
platformdirs==3.10.0
58-
# via
59-
# black
60-
# pylint
61-
# virtualenv
30+
# via virtualenv
6231
pluggy==1.3.0
6332
# via pytest
6433
pre-commit==3.4.0
6534
# via -r requirements-dev.in
66-
pycodestyle==2.11.0
67-
# via
68-
# autopep8
69-
# flake8
70-
pyflakes==3.1.0
71-
# via flake8
72-
pylint==2.17.6
73-
# via -r requirements-dev.in
7435
pytest==7.4.2
7536
# via
7637
# -r requirements-dev.in
@@ -91,12 +52,10 @@ reorder-python-imports==3.11.0
9152
# via -r requirements-dev.in
9253
six==1.16.0
9354
# via python-dateutil
94-
tomlkit==0.12.1
95-
# via pylint
55+
tomli==2.0.1
56+
# via pytest
9657
virtualenv==20.24.5
9758
# via pre-commit
98-
wrapt==1.15.0
99-
# via astroid
10059

10160
# The following packages are considered to be unsafe in a requirements file:
10261
# setuptools

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def environment_1_feature_states_response_list() -> typing.List[dict]:
3030
def environment_1_feature_states_response_list_response_with_segment_override(
3131
environment_1_feature_states_response_list,
3232
):
33-
environment_1_feature_states_response_list[1][
34-
"feature_state_value"
35-
] = "segment_override"
33+
environment_1_feature_states_response_list[1]["feature_state_value"] = (
34+
"segment_override"
35+
)
3636
return environment_1_feature_states_response_list
3737

3838

0 commit comments

Comments
 (0)