Skip to content

Commit 16ad784

Browse files
Update linters (#704)
* Update linters * Migrate from Black to Ruff * Update GitHub Action --------- Co-authored-by: Bartosz Zaczyński <[email protected]>
1 parent 9dc3312 commit 16ad784

File tree

370 files changed

+883
-1127
lines changed

Some content is hidden

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

370 files changed

+883
-1127
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ updates:
66
interval: monthly
77
open-pull-requests-limit: 10
88
allow:
9-
- dependency-name: flake8
10-
- dependency-name: black
9+
- dependency-name: ruff

.github/workflows/linters.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json
55

66
name: linters
7-
on:
7+
on:
88
push:
99
branches:
1010
- master
@@ -18,12 +18,12 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
include:
21-
- {name: Linux312, python: '3.12.3', os: ubuntu-latest}
21+
- {name: Linux313, python: '3.13.7', os: ubuntu-latest}
2222
steps:
2323
- name: Check out repository
2424
uses: actions/checkout@v2
2525

26-
- name: Set up Python
26+
- name: Set up Python
2727
uses: actions/setup-python@v2
2828
with:
2929
python-version: ${{ matrix.python }}
@@ -48,8 +48,8 @@ jobs:
4848
- name: Check code style
4949
run: |
5050
. venv/bin/activate
51-
python -m ruff check .
52-
python -m black --check .
51+
python -m ruff format --check
52+
python -m ruff check
5353
5454
- name: Check directory layout
5555
run: |

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@ Due to time constraints, we cannot provide 1:1 support via GitHub. See you on Sl
1515

1616
### Running Code Style Checks
1717

18-
We use [ruff](https://docs.astral.sh/ruff/) and [black](https://black.readthedocs.io/) to ensure a consistent code style for all of our sample code in this repository.
18+
We use [Ruff](https://realpython.com/ruff-python/) to ensure a consistent code style and formatting for all of our sample code in this repository.
1919

2020
Run the following commands to validate your code against the linters:
2121

2222
```sh
23-
$ ruff check .
24-
$ black --check .
23+
$ ruff format --check
24+
$ ruff check
2525
```
2626

27+
Make sure you're using the exact Ruff version specified in [`requirements.txt`](https://github.com/realpython/materials/blob/master/requirements.txt).
28+
2729
### Running Python Code Formatter
2830

29-
We're using a tool called [black](https://black.readthedocs.io/) on this repo to ensure consistent formatting. On CI it runs in "check" mode to ensure any new files added to the repo follow PEP 8. If you see linter warnings that say something like "would reformat some_file.py" it means that black disagrees with your formatting.
31+
Ruff can automatically ensure a consistent code formatting in this repository. On CI, it runs in "check" mode to ensure any new files added to the repo follow [PEP 8](https://realpython.com/python-pep8/). If you see linter warnings that say something like "would reformat some_file.py", then it means that Ruff disagrees with your formatting.
3032

31-
**The easiest way to resolve these errors is to run Black locally on the code and then commit those changes, as explained below.**
33+
The easiest way to resolve these errors is to run Ruff locally on the code and then commit those changes, as explained below.
3234

33-
To automatically re-format your code to be consistent with our code style guidelines, run [black](https://black.readthedocs.io/) in the repository root folder:
35+
To automatically reformat your code to be consistent with our code style guidelines, run [Ruff](https://pypi.org/project/ruff/) in the repository root folder:
3436

3537
```sh
36-
$ black .
38+
$ ruff format
39+
$ ruff check --fix
3740
```

advent-of-code/solutions/2021/05_hydrothermal_venture/aoc202105.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ def points(line):
6363
case (x1, y1, x2, y2) if y1 == y2:
6464
return [(x, y1) for x in coords(x1, x2)]
6565
case (x1, y1, x2, y2):
66-
return [(x, y) for x, y in zip(coords(x1, x2), coords(y1, y2))]
66+
return [
67+
(x, y)
68+
for x, y in zip(coords(x1, x2), coords(y1, y2), strict=False)
69+
]
6770

6871

6972
def coords(start, stop):

arcade-platformer/arcade_platformer/11_title_view.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def on_update(self, delta_time: float) -> None:
7474

7575
# If the timer has run out, we toggle the instructions
7676
if self.display_timer < 0:
77-
7877
# Toggle whether to show the instructions
7978
self.show_instructions = not self.show_instructions
8079

arcade-platformer/arcade_platformer/12_instructions_view.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def on_update(self, delta_time: float) -> None:
7474

7575
# If the timer has run out, we toggle the instructions
7676
if self.display_timer < 0:
77-
7877
# Toggle whether to show the instructions
7978
self.show_instructions = not self.show_instructions
8079

arcade-platformer/arcade_platformer/13_pause_view.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def on_update(self, delta_time: float) -> None:
7474

7575
# If the timer has run out, we toggle the instructions
7676
if self.display_timer < 0:
77-
7877
# Toggle whether to show the instructions
7978
self.show_instructions = not self.show_instructions
8079

arcade-platformer/arcade_platformer/14_enemies.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ def on_update(self, delta_time: float) -> None:
116116

117117
# If the timer has run out, we toggle the instructions
118118
if self.display_timer < 0:
119-
120119
# Toggle whether to show the instructions
121120
self.show_instructions = not self.show_instructions
122121

arcade-platformer/arcade_platformer/15_moving_platforms.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ def on_update(self, delta_time: float) -> None:
116116

117117
# If the timer has run out, we toggle the instructions
118118
if self.display_timer < 0:
119-
120119
# Toggle whether to show the instructions
121120
self.show_instructions = not self.show_instructions
122121

arcade-platformer/arcade_platformer/arcade_platformer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def on_update(self, delta_time: float) -> None:
9191

9292
# If the timer has run out, we toggle the instructions
9393
if self.display_timer < 0:
94-
9594
# Toggle whether to show the instructions
9695
self.show_instructions = not self.show_instructions
9796

0 commit comments

Comments
 (0)