Skip to content

Commit 62a4930

Browse files
MatiissMyreMylar
andauthored
Use ruff to also sort imports (#3237)
* sort imports with ruff * sorted imports (that's a lot of modified files) * some more dev.py alling ig * reconfigure the hooks to be more concise * future-proofing? ruff lint config, sth like that * combine as imports for ruff isort * rerun import sorting after configuration update * Select only the I rule * Update pyproject.toml * add the missing import and rewrite the method as how it is typically written elsewhere (e.g., the CPython repository) * add spaces around [] for consistency * some more unformatted files * exclude python files in buildconfig only * format and sort imports for buildconfig/stubs/pygame * ignore .ruff_cache * ignore typing.pyi explicitly since it's supposed to be an exact copy of typing.py * ignore import sorting in stubs __init__.py only as it's auto-generated --------- Co-authored-by: Dan Lawrence <[email protected]>
1 parent 1ebf3c4 commit 62a4930

File tree

137 files changed

+422
-416
lines changed

Some content is hidden

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

137 files changed

+422
-416
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
# mypy
3333
.mypy_cache/
3434

35+
# Ruff
36+
.ruff_cache
37+
3538
# Other
3639
envdev*
3740
.virtualenv*

.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ repos:
2828
- repo: https://github.com/astral-sh/ruff-pre-commit
2929
rev: v0.4.2
3030
hooks: # See pyproject.toml for configuration options.
31+
- id: ruff
32+
name: ruff-sort-imports
33+
args: [ --select, I, --fix ]
3134
- id: ruff-format # Run the formatter
3235
types_or: [ python, pyi, jupyter ]
3336

buildconfig/stubs/gen_stubs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def get_all(mod: Any):
128128
# write the module docstring of this file in the generated file, so that
129129
# people know this file exists
130130
f.write(info_header)
131+
f.write("# ruff: noqa: I001\n")
131132
f.write(misc_stubs)
132133

133134
for mod, items in pygame_all_imports.items():

buildconfig/stubs/pygame/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# buildconfig/stubs/gen_stubs.py
22
# A script to auto-generate locals.pyi, constants.pyi and __init__.pyi typestubs
33
# IMPORTANT NOTE: Do not edit this file by hand!
4+
# ruff: noqa: I001
45

56
from . import (
67
display as display,
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from collections.abc import Callable
2-
from typing import Union, Optional
2+
from typing import Optional, Union
33

44
ImportResult = tuple[str, bool, Optional[Callable]]
55

66
def str_from_tuple(version_tuple: Union[tuple[int, int, int], None]) -> str: ...
7-
def attempt_import(module: str, function_name: str, output_str: str = "") -> ImportResult: ...
7+
def attempt_import(
8+
module: str, function_name: str, output_str: str = ""
9+
) -> ImportResult: ...
810
def print_debug_info(filename: Optional[str] = None) -> None: ...

buildconfig/stubs/pygame/_sdl2/controller.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from typing import final
2+
23
from pygame.joystick import JoystickType
34

45
def init() -> None: ...
56
def get_init() -> bool: ...
67
def quit() -> None: ...
78
def is_controller(device_index: int) -> bool: ...
89
def get_count() -> int: ...
9-
1010
@final
1111
class Controller:
1212
def __new__(cls, device_index: int) -> Controller: ...

buildconfig/stubs/pygame/_sdl2/touch.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TypedDict, Optional
1+
from typing import Optional, TypedDict
22

33
class _FingerDict(TypedDict):
44
id: int

buildconfig/stubs/pygame/_sdl2/video.pyi

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ from typing import Any, Optional, Union
44
from pygame.color import Color
55
from pygame.rect import Rect
66
from pygame.surface import Surface
7+
from pygame.typing import ColorLike, Point, RectLike
78
from pygame.window import Window as Window
89

9-
from pygame.typing import ColorLike, RectLike, Point
10-
1110
WINDOWPOS_UNDEFINED: int
1211
WINDOWPOS_CENTERED: int
1312

@@ -160,18 +159,10 @@ class Renderer:
160159
def draw_point(self, point: Point) -> None: ...
161160
def draw_rect(self, rect: RectLike) -> None: ...
162161
def fill_rect(self, rect: RectLike) -> None: ...
163-
def draw_triangle(
164-
self, p1: Point, p2: Point, p3: Point
165-
) -> None: ...
166-
def fill_triangle(
167-
self, p1: Point, p2: Point, p3: Point
168-
) -> None: ...
169-
def draw_quad(
170-
self, p1: Point, p2: Point, p3: Point, p4: Point
171-
) -> None: ...
172-
def fill_quad(
173-
self, p1: Point, p2: Point, p3: Point, p4: Point
174-
) -> None: ...
162+
def draw_triangle(self, p1: Point, p2: Point, p3: Point) -> None: ...
163+
def fill_triangle(self, p1: Point, p2: Point, p3: Point) -> None: ...
164+
def draw_quad(self, p1: Point, p2: Point, p3: Point, p4: Point) -> None: ...
165+
def fill_quad(self, p1: Point, p2: Point, p3: Point, p4: Point) -> None: ...
175166
def to_surface(
176167
self, surface: Optional[Surface] = None, area: Optional[RectLike] = None
177168
) -> Surface: ...

buildconfig/stubs/pygame/camera.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from abc import ABC, abstractmethod
2-
from typing import Optional, Union, Literal
3-
4-
from pygame.typing import IntPoint
2+
from typing import Literal, Optional, Union
53

64
from pygame.surface import Surface
5+
from pygame.typing import IntPoint
76

87
def get_backends() -> list[str]: ...
98
def init(backend: Optional[str] = None) -> None: ...

buildconfig/stubs/pygame/color.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from collections.abc import Collection, Iterator
22
from typing import Any, ClassVar, SupportsIndex, Union, overload
3-
from typing_extensions import deprecated # added in 3.13
43

54
from pygame.typing import ColorLike
5+
from typing_extensions import deprecated # added in 3.13
66

77
THECOLORS: dict[str, tuple[int, int, int, int]]
88

0 commit comments

Comments
 (0)