Skip to content

Commit 79defbf

Browse files
cdeileinarf
andauthored
Switch from black to ruff format (#2550)
* Improve make.py a bit * ruff format changes on arcade * Switch from black to ruff format * Fix ruff-check in .github/workflows/test.yml --------- Co-authored-by: Einar Forselv <eforselv@gmail.com>
1 parent 5743504 commit 79defbf

34 files changed

+132
-216
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ jobs:
3636
id: wheel
3737
run: |
3838
python -m pip install -e .[dev]
39+
- name: "code-inspection: formatting"
40+
if: ${{ (success() || failure()) && steps.wheel.outcome == 'success' }}
41+
run: |
42+
python ./make.py format --check
43+
- name: "code-inspection: ruff-check"
44+
if: ${{ (success() || failure()) && steps.wheel.outcome == 'success' }}
45+
run: |
46+
python ./make.py ruff-check
3947
- name: "code-inspection: mypy"
4048
if: ${{ (success() || failure()) && steps.wheel.outcome == 'success' }}
4149
run: |
@@ -44,14 +52,6 @@ jobs:
4452
if: ${{ (success() || failure()) && steps.wheel.outcome == 'success' }}
4553
run: |
4654
python ./make.py pyright
47-
- name: "code-inspection: ruff"
48-
if: ${{ (success() || failure()) && steps.wheel.outcome == 'success' }}
49-
run: |
50-
python ./make.py ruff
51-
- name: "code-inspection: formatting"
52-
if: ${{ (success() || failure()) && steps.wheel.outcome == 'success' }}
53-
run: |
54-
python ./make.py format --check
5555
# Prepare the Pull Request Payload artifact. If this fails,
5656
# we fail silently using the `continue-on-error` option. It's
5757
# nice if this succeeds, but if it fails for any reason, it

CONTRIBUTING.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,20 @@ steps at the end of this document.
8181

8282
## Formatting
8383

84-
Arcade uses [Black](https://black.readthedocs.io/en/stable) for autoformatting our code.
84+
Arcade uses [ruff format](https://docs.astral.sh/ruff/formatter/) for autoformatting our code
85+
as well as sorting imports.
8586

8687
This can be run both with our `make.py` script, as well as setup for your editor to run it automatically.
87-
See [this link](https://black.readthedocs.io/en/stable/integrations/editors.html) for more information on
88-
Black integration for your specific editor.
88+
See [this link](https://docs.astral.sh/ruff/editors/) for more information on ruff editor integration.
8989

90-
The following command will run black for you if you do not want to configure your editor to do it. It can be
91-
a good idea to run this command when you are finished working anyway, as our CI will use this to check that
92-
the formatting is correct.
90+
The following command will run ``ruff format`` for you if you do not want to configure your editor to do it.
91+
It can be a good idea to run this command when you are finished working anyway,
92+
as our CI will use this to check that the formatting is correct.
9393

9494
```bash
9595
python make.py format
9696
```
9797

98-
In addition to Black, this will sort the imports using [Ruff](https://docs.astral.sh/ruff/). If you want to set up
99-
your editor to run this, please see [this link](https://docs.astral.sh/ruff/integrations/) for more information on
100-
Ruff integration for your specific editor.
101-
10298
Docstring should be formatted using [Google Style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html).
10399

104100
The minium for docstrings is covering all parameters in an `Args:` block.

arcade/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ def show_view(self, new_view: View) -> None:
962962
"""
963963
if not isinstance(new_view, View):
964964
raise TypeError(
965-
f"Window.show_view() takes an arcade.View," f"but it got a {type(new_view)}."
965+
f"Window.show_view() takes an arcade.View, but it got a {type(new_view)}."
966966
)
967967

968968
self._ctx.screen.use()

arcade/camera/camera_2d.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ def __init__(
124124
if projection is not None:
125125
if left == right:
126126
raise ZeroProjectionDimension(
127-
(f"projection width is 0 due to equal {left=}" f"and {right=} values")
127+
f"projection width is 0 due to equal {left=} and {right=} values"
128128
)
129129
if bottom == top:
130130
raise ZeroProjectionDimension(
131-
(f"projection height is 0 due to equal {bottom=}" f"and {top=}")
131+
f"projection height is 0 due to equal {bottom=} and {top=}"
132132
)
133133
if near == far:
134134
raise ZeroProjectionDimension(
135-
f"projection depth is 0 due to equal {near=}" f"and {far=} values"
135+
f"projection depth is 0 due to equal {near=} and {far=} values"
136136
)
137137

138138
pos_x = position[0] if position is not None else half_width
@@ -223,17 +223,17 @@ def from_camera_data(
223223
left, right = projection_data.left, projection_data.right
224224
if projection_data.left == projection_data.right:
225225
raise ZeroProjectionDimension(
226-
(f"projection width is 0 due to equal {left=}" f"and {right=} values")
226+
(f"projection width is 0 due to equal {left=}and {right=} values")
227227
)
228228
bottom, top = projection_data.bottom, projection_data.top
229229
if bottom == top:
230230
raise ZeroProjectionDimension(
231-
(f"projection height is 0 due to equal {bottom=}" f"and {top=}")
231+
(f"projection height is 0 due to equal {bottom=}and {top=}")
232232
)
233233
near, far = projection_data.near, projection_data.far
234234
if near == far:
235235
raise ZeroProjectionDimension(
236-
f"projection depth is 0 due to equal {near=}" f"and {far=} values"
236+
f"projection depth is 0 due to equal {near=}and {far=} values"
237237
)
238238

239239
# build a new camera with defaults and then apply the provided camera objects.

arcade/camera/data_types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def __init__(
8484
forward: Point3 = (0.0, 0.0, -1.0),
8585
zoom: float = 1.0,
8686
):
87-
8887
self.position: tuple[float, float, float] = position
8988
"""A 3D vector which describes where the camera is located."""
9089

@@ -260,9 +259,7 @@ def lrbt(self, new_lrbt: tuple[float, float, float, float]):
260259
self.rect = LRBT(*new_lrbt)
261260

262261
def __str__(self):
263-
return (
264-
f"OrthographicProjection<" f"LRBT={self.rect.lrbt}, " f"{self.near=}, " f"{self.far=}"
265-
)
262+
return f"OrthographicProjection<LRBT={self.rect.lrbt}, {self.near=}, {self.far=}>"
266263

267264
def __repr__(self):
268265
return self.__str__()

arcade/camera/static.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828

2929
class _StaticCamera:
30-
3130
def __init__(
3231
self,
3332
view_matrix: Mat4,

arcade/draw/rect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ def draw_lrbt_rectangle_outline(
187187
ValueError: Raised if left > right or top < bottom.
188188
"""
189189
if left > right:
190-
raise ValueError("Left coordinate must be less than or equal to " "the right coordinate")
190+
raise ValueError("Left coordinate must be less than or equal to the right coordinate")
191191

192192
if bottom > top:
193-
raise ValueError("Bottom coordinate must be less than or equal to " "the top coordinate")
193+
raise ValueError("Bottom coordinate must be less than or equal to the top coordinate")
194194

195195
draw_rect_outline(LRBT(left, right, bottom, top), color, border_width)
196196

arcade/experimental/atlas_render_into.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111

1212
class AtlasRenderDemo(arcade.Window):
13-
1413
def __init__(self):
1514
super().__init__(1280, 720, "Atlas Render Demo")
1615
self.atlas = arcade.DefaultTextureAtlas((600, 600))

arcade/experimental/atlas_replace_image.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868

6969

7070
class AtlasReplaceImage(arcade.Window):
71-
7271
def __init__(self):
7372
super().__init__(800, 600, "Replacing images in atlas")
7473
self.sprite_1 = arcade.Sprite(TEXTURE_PATHS[-1], center_x=200, center_y=300)

arcade/experimental/geo_culling_check.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717

1818
class GeoCullingTest(arcade.Window):
19-
2019
def __init__(self):
2120
super().__init__(1280, 720, "Cull test", resizable=True)
2221
self.proj = 0, self.width, 0, self.height

arcade/experimental/perspective_parallax.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121

2222
class PerspectiveParallax(arcade.Window):
23-
2423
def __init__(self):
2524
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, "Perspective Parallax")
2625
self.t = 0.0

arcade/experimental/postprocessing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def resize(self, size: tuple[int, int]):
5454

5555

5656
class GaussianBlurPass(PostProcessing):
57-
5857
def __init__(self, size, kernel_size=5, sigma=2, multiplier=0, step=1):
5958
super().__init__(size)
6059
self._kernel_size = kernel_size

arcade/experimental/query_demo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
class MyGame(arcade.Window):
15-
1615
def __init__(self, width, height, title):
1716
super().__init__(width, height, title)
1817
# vsync must be off when measuring rendering calls

arcade/experimental/render_offscreen_animated.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def make_skyline(
6363
color_list = []
6464

6565
while building_center_x < width:
66-
6766
# Is there a gap between the buildings?
6867
if random.random() < gap_chance:
6968
gap_width = random.randrange(10, 50)

arcade/experimental/shadertoy_demo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class MyGame(arcade.Window):
10-
1110
def __init__(self, width, height, title):
1211
super().__init__(width, height, title, resizable=True)
1312
self.shadertoy = Shadertoy.create_from_file(

arcade/experimental/shadertoy_demo_simple.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111

1212
class MyGame(arcade.Window):
13-
1413
def __init__(self, width, height, title):
1514
super().__init__(width, height, title, resizable=True)
1615
self.shadertoy = Shadertoy(

arcade/experimental/shadertoy_textures.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616

1717
class MyGame(arcade.Window):
18-
1918
def __init__(self, width, height, title):
2019
super().__init__(width, height, title, resizable=True)
2120
self.shadertoy = Shadertoy(

arcade/experimental/shapes_perf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def random_radius(start=5, end=25):
7676

7777

7878
class GameWindow(arcade.Window):
79-
8079
def __init__(self, width, height, title):
8180
super().__init__(width, height, title, antialiasing=True, resizable=True)
8281
self.set_vsync(False)

arcade/experimental/texture_transforms.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919

2020
class App(arcade.Window):
21-
2221
def __init__(self):
2322
super().__init__(1200, 600, "Atlas Revamp Check")
2423
paths = [

arcade/future/background/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def background_from_file(
5555
shader: gl.Program | None = None,
5656
geometry: gl.Geometry | None = None,
5757
) -> Background:
58-
5958
texture = BackgroundTexture.from_file(tex_src, offset, scale, angle, filters)
6059
if size is None:
6160
size = texture.texture.size

arcade/future/input/input_manager_example.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626

2727
class Player(arcade.Sprite):
28-
2928
def __init__(
3029
self,
3130
texture,
@@ -58,7 +57,6 @@ def on_action(self, action: str, state: ActionState):
5857

5958

6059
class Game(arcade.Window):
61-
6260
def __init__(
6361
self,
6462
player_textures: Sequence[str] = DEFAULT_TEXTURES,
@@ -76,7 +74,7 @@ def __init__(
7674

7775
self._max_players = max_players
7876
self.key_to_player_index: dict[Keys, int] = {
79-
getattr(Keys, f"KEY_{i + 1 }"): i for i in range(0, max_players)
77+
getattr(Keys, f"KEY_{i + 1}"): i for i in range(0, max_players)
8078
}
8179

8280
self.players: list[Player | None] = []
@@ -201,7 +199,6 @@ def on_draw(self):
201199
self.device_labels_batch.draw()
202200

203201
def on_key_press(self, key, modifiers):
204-
205202
player_index = self.key_to_player_index.get(Keys(key), None)
206203
if player_index is None or player_index >= len(self.players):
207204
return

arcade/future/input/input_mapping.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class Action:
10-
1110
def __init__(self, name: str) -> None:
1211
self.name = name
1312
self._mappings: set[ActionMapping] = set()
@@ -20,7 +19,6 @@ def remove_mapping(self, mapping: ActionMapping) -> None:
2019

2120

2221
class Axis:
23-
2422
def __init__(self, name: str) -> None:
2523
self.name = name
2624
self._mappings: set[AxisMapping] = set()
@@ -51,7 +49,6 @@ def __init__(self, input: inputs.InputEnum):
5149

5250

5351
class ActionMapping(InputMapping):
54-
5552
def __init__(
5653
self,
5754
input: inputs.InputEnum,
@@ -71,7 +68,6 @@ def __init__(
7168

7269

7370
class AxisMapping(InputMapping):
74-
7571
def __init__(self, input: inputs.InputEnum, scale: float):
7672
super().__init__(input)
7773
self._scale = scale

arcade/future/input/manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class InputDevice(Enum):
6464

6565

6666
class InputManager:
67-
6867
def __init__(
6968
self,
7069
controller: Controller | None = None,

arcade/gl/buffer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def __init__(
5656
reserve: int = 0,
5757
usage: str = "static",
5858
):
59-
6059
self._ctx = ctx
6160
self._glo = glo = gl.GLuint()
6261
self._size = -1

arcade/isometric.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def screen_to_isometric_grid(
3333
def create_isometric_grid_lines(
3434
width: int, height: int, tile_width: int, tile_height: int, color: RGBA255, line_width: int
3535
) -> ShapeElementList:
36-
3736
# Grid lines 1
3837
shape_list: ShapeElementList = ShapeElementList()
3938

arcade/math.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,7 @@ def rescale_relative_to_point(source: Point2, target: Point2, factor: AsFloat |
388388
return target
389389
except ValueError:
390390
raise ValueError(
391-
"factor must be a float, int, or tuple-like "
392-
"which unpacks as two float-like values"
391+
"factor must be a float, int, or tuple-like which unpacks as two float-like values"
393392
)
394393
except TypeError:
395394
raise TypeError(

arcade/perf_graph.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ def update_graph(self, delta_time: float) -> None:
320320
# Render to the internal texture
321321
# This ugly spacing is intentional to make type checking work.
322322
with atlas.render_into(self.minimap_texture, projection=self.proj) as fbo: # type: ignore
323-
324323
# Set the background color
325324
fbo.clear(color=self.background_color)
326325

arcade/physics_engines.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,13 @@ def _move_sprite(
115115
# --- Rotate
116116
rotating_hit_list = []
117117
if moving_sprite.change_angle:
118-
119118
# Rotate
120119
moving_sprite.angle += moving_sprite.change_angle
121120

122121
# Resolve collisions caused by rotating
123122
rotating_hit_list = check_for_collision_with_lists(moving_sprite, can_collide)
124123

125124
if len(rotating_hit_list) > 0:
126-
127125
max_distance = (moving_sprite.width + moving_sprite.height) / 2
128126

129127
# Resolve any collisions by this weird kludge
@@ -199,7 +197,6 @@ def _move_sprite(
199197

200198
exit_loop = False
201199
while not exit_loop:
202-
203200
loop_count += 1
204201
# print(f"{cur_x_change=}, {upper_bound=}, {lower_bound=}, {loop_count=}")
205202

@@ -782,7 +779,6 @@ def update(self) -> list[BasicSprite]:
782779
for platform_list in self.platforms:
783780
for platform in platform_list:
784781
if platform.change_x != 0 or platform.change_y != 0:
785-
786782
# Check x boundaries and move the platform in x direction
787783
if platform.boundary_left and platform.left <= platform.boundary_left:
788784
platform.left = platform.boundary_left

0 commit comments

Comments
 (0)