Skip to content

Commit

Permalink
Upgrade linters and switch to Ruff (realpython#530)
Browse files Browse the repository at this point in the history
* Update Python, Black, and Flake8 versions

* Black 24 updates

* Switch from Flake8 to Ruff for linting

* Ruff fixes

* Add information about Ruff in README

* Black

---------

Co-authored-by: Dan Bader <mail@dbader.org>
  • Loading branch information
gahjelle and dbader authored May 6, 2024
1 parent 06af2c7 commit 762eaee
Show file tree
Hide file tree
Showing 543 changed files with 822 additions and 801 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dircheck.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Linter to ensure standard folder structure
"""

import pathlib
import re
import sys
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
include:
- {name: Linux311, python: '3.11.5', os: ubuntu-latest}
- {name: Linux312, python: '3.12.3', os: ubuntu-latest}
steps:
- name: Check out repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Check code style
run: |
. venv/bin/activate
python -m flake8
python -m ruff check .
python -m black --check .
- name: Check directory layout
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Due to time constraints, we cannot provide 1:1 support via GitHub. See you on Sl

### Running Code Style Checks

We use [flake8](http://flake8.pycqa.org/en/latest/) and [black](https://black.readthedocs.io/) to ensure a consistent code style for all of our sample code in this repository.
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.

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

```sh
$ flake8
$ ruff check .
$ black --check .
```

Expand Down
3 changes: 2 additions & 1 deletion arcade-a-primer/arcade_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#

# Imports
import arcade
import random

import arcade

# Constants
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/02_open_game_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/03_read_level_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/04_define_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/05_update_and_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/06_keyboard_movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/07_scrolling_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/08_on_screen_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/09_joystick_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/10_view_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/11_title_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/12_instructions_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/13_pause_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/14_enemies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/15_moving_platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade

# Game constants
# Window dimensions
SCREEN_WIDTH = 1000
Expand Down
3 changes: 2 additions & 1 deletion arcade-platformer/arcade_platformer/arcade_platformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
Game sounds and tile maps by author
"""

import arcade
import pathlib

import arcade
import constants as game

# Assets path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from game import SpaceRocks


if __name__ == "__main__":
space_rocks = SpaceRocks()
space_rocks.main_loop()
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pygame

from models import Asteroid, Spaceship
from utils import get_random_position, load_sprite, print_text

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pygame.math import Vector2
from pygame.transform import rotozoom

from utils import get_random_velocity, load_sound, load_sprite, wrap_position

UP = Vector2(0, -1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from game import SpaceRocks


if __name__ == "__main__":
space_rocks = SpaceRocks()
space_rocks.main_loop()
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from game import SpaceRocks


if __name__ == "__main__":
space_rocks = SpaceRocks()
space_rocks.main_loop()
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pygame

from models import Asteroid, Spaceship
from utils import get_random_position, load_sprite, print_text

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pygame.math import Vector2
from pygame.transform import rotozoom

from utils import get_random_velocity, load_sound, load_sprite, wrap_position

UP = Vector2(0, -1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from game import SpaceRocks


if __name__ == "__main__":
space_rocks = SpaceRocks()
space_rocks.main_loop()
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from game import SpaceRocks


if __name__ == "__main__":
space_rocks = SpaceRocks()
space_rocks.main_loop()
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pygame

from utils import load_sprite


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from game import SpaceRocks


if __name__ == "__main__":
space_rocks = SpaceRocks()
space_rocks.main_loop()
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pygame

from models import GameObject
from utils import load_sprite

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from game import SpaceRocks


if __name__ == "__main__":
space_rocks = SpaceRocks()
space_rocks.main_loop()
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pygame

from models import Spaceship
from utils import load_sprite

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pygame.math import Vector2
from pygame.transform import rotozoom

from utils import load_sprite, wrap_position

UP = Vector2(0, -1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from game import SpaceRocks


if __name__ == "__main__":
space_rocks = SpaceRocks()
space_rocks.main_loop()
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pygame

from models import Asteroid, Spaceship
from utils import get_random_position, load_sprite

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pygame.math import Vector2
from pygame.transform import rotozoom

from utils import get_random_velocity, load_sprite, wrap_position

UP = Vector2(0, -1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from game import SpaceRocks


if __name__ == "__main__":
space_rocks = SpaceRocks()
space_rocks.main_loop()
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pygame

from models import Asteroid, Spaceship
from utils import get_random_position, load_sprite

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pygame.math import Vector2
from pygame.transform import rotozoom

from utils import get_random_velocity, load_sprite, wrap_position

UP = Vector2(0, -1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from game import SpaceRocks


if __name__ == "__main__":
space_rocks = SpaceRocks()
space_rocks.main_loop()
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pygame

from models import Asteroid, Spaceship
from utils import get_random_position, load_sprite

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pygame.math import Vector2
from pygame.transform import rotozoom

from utils import get_random_velocity, load_sprite, wrap_position

UP = Vector2(0, -1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from game import SpaceRocks


if __name__ == "__main__":
space_rocks = SpaceRocks()
space_rocks.main_loop()
Loading

0 comments on commit 762eaee

Please sign in to comment.