Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ruff to also sort imports #3237

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.2
hooks: # See pyproject.toml for configuration options.
- id: ruff
name: ruff-sort-imports
args: [--select, I, --fix]
Matiiss marked this conversation as resolved.
Show resolved Hide resolved
- id: ruff-format # Run the formatter
types_or: [ python, pyi, jupyter ]

Expand Down
5 changes: 2 additions & 3 deletions buildconfig/stubs/pygame/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ __all__ = [
from abc import abstractmethod
from collections.abc import Callable
from os import PathLike as _PathProtocol
from typing import IO, Union, TypeVar, Protocol
from typing import IO, Protocol, TypeVar, Union

from pygame.color import Color
from pygame.rect import Rect, FRect

from pygame.rect import FRect, Rect

# For functions that take a file name
_PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
Expand Down
2 changes: 1 addition & 1 deletion dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import re
import subprocess
import sys
from enum import Enum
from pathlib import Path
from typing import Any, Union
from enum import Enum

MOD_NAME = "pygame-ce"
DIST_DIR = "dist"
Expand Down
1 change: 0 additions & 1 deletion docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from pathlib import Path


PKG_DIR = Path(__file__).absolute().parent / "generated"


Expand Down
2 changes: 1 addition & 1 deletion docs/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
import webbrowser
from http.server import ThreadingHTTPServer, SimpleHTTPRequestHandler
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer

# use relative import here and not absolute, so that `python -m docs` works at
# development time
Expand Down
2 changes: 1 addition & 1 deletion examples/aliens.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

"""

import random
import os
import random

# import basic pygame modules
import pygame
Expand Down
8 changes: 4 additions & 4 deletions examples/audiocapture.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
* play back the recorded sound
"""

import pygame
import time

import pygame
from pygame._sdl2 import (
get_audio_device_names,
AudioDevice,
AUDIO_F32,
AUDIO_ALLOW_FORMAT_CHANGE,
AUDIO_F32,
AudioDevice,
get_audio_device_names,
)
from pygame._sdl2.mixer import set_post_mix

Expand Down
1 change: 1 addition & 0 deletions examples/blend_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""

import os

import pygame
from pygame import K_1, K_2, K_3, K_4, K_5, K_6, K_7, K_8, K_9

Expand Down
5 changes: 3 additions & 2 deletions examples/blit_blends.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
"""

import os
import pygame
import time

import pygame

main_dir = os.path.split(os.path.abspath(__file__))[0]
data_dir = os.path.join(main_dir, "data")

try:
import pygame.surfarray
import numpy
import pygame.surfarray
except ImportError:
print("no surfarray for you! install numpy")

Expand Down
1 change: 1 addition & 0 deletions examples/chimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# Import Modules
import os

import pygame

if not pygame.font:
Expand Down
2 changes: 1 addition & 1 deletion examples/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*How to make a simple button
"""

import pygame
import os

import pygame

# Create a system cursor

Expand Down
2 changes: 1 addition & 1 deletion examples/font_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* Press escape to exit
"""

import sys
import os
import sys

import pygame

Expand Down
1 change: 1 addition & 0 deletions examples/freetype_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"""

import os

import pygame
import pygame.freetype as freetype

Expand Down
4 changes: 2 additions & 2 deletions examples/glcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

"""

import math
import ctypes
import math

import pygame

Expand All @@ -37,7 +37,7 @@
raise SystemExit

try:
from numpy import array, dot, eye, zeros, float32, uint32
from numpy import array, dot, eye, float32, uint32, zeros
except ImportError:
print("numpy missing. The GLCUBE example requires: pyopengl numpy")
raise SystemExit
Expand Down
3 changes: 2 additions & 1 deletion examples/go_over_there.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
* Press R to restart the demo
"""

import pygame
import random

import pygame

MIN_SPEED = 0.25
MAX_SPEED = 5
MAX_BALLS = 1600
Expand Down
1 change: 1 addition & 0 deletions examples/headless_no_windows_needed.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import os
import sys

import pygame

# set SDL to use the NULL video driver,
Expand Down
3 changes: 2 additions & 1 deletion examples/liquid.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
sound stuff, that's an easy enough challenge for the reader :]
"""

import pygame
import os
from math import sin

import pygame

main_dir = os.path.split(os.path.abspath(__file__))[0]


Expand Down
2 changes: 1 addition & 1 deletion examples/midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
python -m pygame.examples.midi --input
"""

import sys
import os
import sys

import pygame
import pygame.midi
Expand Down
1 change: 1 addition & 0 deletions examples/moveit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""

import os

import pygame

main_dir = os.path.split(os.path.abspath(__file__))[0]
Expand Down
1 change: 1 addition & 0 deletions examples/multiplayer_joystick.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

import pygame

WIDTH, HEIGHT = 500, 500
Expand Down
3 changes: 2 additions & 1 deletion examples/music_drop_fade.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
* Press any other button to skip to the next music file in the list
"""

import pygame
import os
import sys

import pygame

VOLUME_CHANGE_AMOUNT = 0.02 # how fast should up and down arrows change the volume?
SCREEN_SIZE = (640, 480)

Expand Down
1 change: 1 addition & 0 deletions examples/ninepatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

import os

import pygame

SCREEN_SIZE = pygame.Vector2(600, 500)
Expand Down
2 changes: 1 addition & 1 deletion examples/pixelarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"""

import os
import pygame

import pygame

main_dir = os.path.split(os.path.abspath(__file__))[0]
data_dir = os.path.join(main_dir, "data")
Expand Down
3 changes: 2 additions & 1 deletion examples/prevent_display_stretching.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
if os.name != "nt" or sys.getwindowsversion()[0] < 6:
raise NotImplementedError("this script requires Windows Vista or newer")

import pygame
import ctypes

import pygame


def main():
# Determine whether or not the user would like to prevent stretching
Expand Down
1 change: 1 addition & 0 deletions examples/retro_scaling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math

import pygame


Expand Down
1 change: 1 addition & 0 deletions examples/scaletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import sys
import time

import pygame


Expand Down
2 changes: 1 addition & 1 deletion examples/scroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
to quit.
"""

import sys
import os
import sys

import pygame
from pygame.transform import scale
Expand Down
3 changes: 2 additions & 1 deletion examples/setmodescale.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
on desktop size and the graphics are scaled.
"""

import pygame
import sys

import pygame

RES = (160, 120)
FPS = 30

Expand Down
1 change: 1 addition & 0 deletions examples/sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import os
import sys

import pygame

main_dir = os.path.split(os.path.abspath(__file__))[0]
Expand Down
4 changes: 2 additions & 2 deletions examples/sound_array_demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"""

import os
import pygame
from numpy import zeros, int32, int16
import time

import pygame
from numpy import int16, int32, zeros

# pygame.mixer.init(44100, -16, 0)
pygame.mixer.init()
Expand Down
6 changes: 2 additions & 4 deletions examples/sprite_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
"""

import os
import pygame


from pygame._sdl2 import Window, Texture, Image, Renderer

import pygame
from pygame._sdl2 import Image, Renderer, Texture, Window

data_dir = os.path.join(os.path.split(os.path.abspath(__file__))[0], "data")

Expand Down
4 changes: 1 addition & 3 deletions examples/testsprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
See pygame.examples.aliens for some prettier code.
"""

import sys
import os

import sys
from random import randint
from time import time

import pygame


main_dir = os.path.split(os.path.abspath(__file__))[0]
data_dir = os.path.join(main_dir, "data")

Expand Down
2 changes: 1 addition & 1 deletion examples/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
Shows how to use the TEXTEDITING and TEXTINPUT events.
"""

import sys
import os
import sys

import pygame

Expand Down
1 change: 1 addition & 0 deletions examples/vgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"""

import os

import pygame

try:
Expand Down
4 changes: 2 additions & 2 deletions examples/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"""

import os
import pygame

from pygame._sdl2 import Window, Texture, Image, Renderer, get_drivers
import pygame
from pygame._sdl2 import Image, Renderer, Texture, Window, get_drivers

data_dir = os.path.join(os.path.split(os.path.abspath(__file__))[0], "data")

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ exclude = [
"setup.py",
]

[tool.ruff.lint]
fixable = ["I"]
Matiiss marked this conversation as resolved.
Show resolved Hide resolved

Matiiss marked this conversation as resolved.
Show resolved Hide resolved
[tool.ruff.format]
quote-style = "preserve"

Expand Down
Loading
Loading