Skip to content

Commit 0012765

Browse files
authored
Bump pylinalg & ruff format (#931)
* Bump pylinalg * ruff format
1 parent 4cc763b commit 0012765

File tree

16 files changed

+56
-54
lines changed

16 files changed

+56
-54
lines changed

examples/other/hirez_screenshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def animate():
259259
print("full resolution:", full_im.shape)
260260
filename = os.path.join(tempfile.gettempdir(), "hirez_pygfx.png")
261261
iio.imwrite(filename, full_im)
262-
print(f"{os.stat(filename).st_size/2**20:0.3f} MiB")
262+
print(f"{os.stat(filename).st_size / 2**20:0.3f} MiB")
263263

264264
# Show the image
265265
webbrowser.open("file://" + filename)

examples/other/integration_pytorch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ def _on_batch_end(
720720
self._queue.put(obj=mesh_data)
721721

722722
# print current loss
723-
print(f'Loss: {outputs["loss"]}')
723+
print(f"Loss: {outputs['loss']}")
724724

725725
def on_train_batch_end(self, *args, **kwargs) -> None:
726726
self._on_batch_end(*args)

pygfx/helpers/_box.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ def set_transform_by_object(self, object: WorldObject, space="world", scale=1.0)
131131
aabb = None
132132
if space not in {"world", "local"}:
133133
raise ValueError(
134-
'Space argument must be either "world"'
135-
f'or "local". Given value: {space}'
134+
f'Space argument must be either "world"or "local". Given value: {space}'
136135
)
137136
if space == "world":
138137
aabb = object.get_world_bounding_box()

pygfx/renderers/wgpu/engine/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def get_cached_shader_module(device, shader, shader_kwargs):
8888
# PYGFX_PRINT_WGSL_ON_COMPILATION_ERROR
8989
if PRINT_WGSL_ON_ERROR:
9090
wgsl_with_line_numbers = "\n".join(
91-
f"{i+1:5d}: {line}" for i, line in enumerate(wgsl.splitlines())
91+
f"{i + 1:5d}: {line}" for i, line in enumerate(wgsl.splitlines())
9292
)
9393
print(wgsl_with_line_numbers, file=sys.stderr)
9494
raise

pygfx/renderers/wgpu/engine/renderer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def flush(self, target=None):
578578
now = time.perf_counter()
579579
if self._show_fps:
580580
if self._fps["count"] == 0:
581-
print(f"Time to first draw: {now-self._fps['start']:0.2f}")
581+
print(f"Time to first draw: {now - self._fps['start']:0.2f}")
582582
self._fps["start"] = now
583583
self._fps["count"] = 1
584584
elif now > self._fps["start"] + 1:

pygfx/renderers/wgpu/shader/bindings.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ def _define_uniform(self, bindgroup, index, binding):
6666
structname = self._uniform_struct_names[struct_hash]
6767
if binding.structname is not None:
6868
# Do we need to ensure that a dtype corresponds to only one struct?
69-
assert (
70-
structname == binding.structname
71-
), "dtype[{struct_hash}] has been defined as struct[{structname}]"
69+
assert structname == binding.structname, (
70+
"dtype[{struct_hash}] has been defined as struct[{structname}]"
71+
)
7272
except KeyError:
7373
# sometimes, we need a meaningful alias for the struct name.
7474
if binding.structname is not None:
7575
structname = binding.structname
76-
assert (
77-
structname not in self._uniform_struct_names.values()
78-
), "structname has been used for another dtype"
76+
assert structname not in self._uniform_struct_names.values(), (
77+
"structname has been used for another dtype"
78+
)
7979
else:
8080
# auto generate struct name
81-
structname = f"Struct_u_{len(self._uniform_struct_names)+1}"
81+
structname = f"Struct_u_{len(self._uniform_struct_names) + 1}"
8282

8383
self._uniform_struct_names[struct_hash] = structname
8484

pygfx/renderers/wgpu/shaders/meshshader.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -385,27 +385,27 @@ def _encode_morph_texture(self, geometry):
385385
for i in range(morph_count):
386386
if morph_positions:
387387
morph_position = morph_positions[i]
388-
assert (
389-
len(morph_position) == vertice_count
390-
), f"Morph target {i} has {len(morph_position)} vertices, expected {vertice_count}"
388+
assert len(morph_position) == vertice_count, (
389+
f"Morph target {i} has {len(morph_position)} vertices, expected {vertice_count}"
390+
)
391391
morph_position = np.pad(morph_position, ((0, 0), (0, 1)), "constant")
392392
else:
393393
morph_position = np.zeros((vertice_count, 4), dtype=np.float32)
394394

395395
if morph_normals:
396396
morph_normal = morph_normals[i]
397-
assert (
398-
len(morph_normal) == vertice_count
399-
), f"Morph normal {i} has {len(morph_normal)} vertices, expected {vertice_count}"
397+
assert len(morph_normal) == vertice_count, (
398+
f"Morph normal {i} has {len(morph_normal)} vertices, expected {vertice_count}"
399+
)
400400
morph_normal = np.pad(morph_normal, ((0, 0), (0, 1)), "constant")
401401
else:
402402
morph_normal = np.zeros((vertice_count, 4), dtype=np.float32)
403403

404404
if morph_colors:
405405
morph_color = morph_colors[i]
406-
assert (
407-
len(morph_color) == vertice_count
408-
), f"Morph color {i} has {len(morph_colors[i])} vertices, expected {vertice_count}"
406+
assert len(morph_color) == vertice_count, (
407+
f"Morph color {i} has {len(morph_colors[i])} vertices, expected {vertice_count}"
408+
)
409409
else:
410410
morph_color = np.zeros((vertice_count, 4), dtype=np.float32)
411411

@@ -487,22 +487,22 @@ def _check_texture(self, t, geometry, view_dim):
487487
texcoords = getattr(geometry, f"texcoords{uv_channel}", None)
488488
else:
489489
texcoords = getattr(geometry, "texcoords", None)
490-
assert (
491-
texcoords is not None
492-
), f"Texture {t} requires geometry.texcoords{uv_channel or ''}"
490+
assert texcoords is not None, (
491+
f"Texture {t} requires geometry.texcoords{uv_channel or ''}"
492+
)
493493

494494
if view_dim == "1d":
495-
assert (
496-
texcoords.data.ndim == 1 or texcoords.data.shape[-1] == 1
497-
), f"Texture {t} requires 1D texcoords"
495+
assert texcoords.data.ndim == 1 or texcoords.data.shape[-1] == 1, (
496+
f"Texture {t} requires 1D texcoords"
497+
)
498498
elif view_dim == "2d" or view_dim == "2d-array":
499-
assert (
500-
texcoords.data.ndim == 2 and texcoords.data.shape[-1] == 2
501-
), f"Texture {t} requires 2D texcoords"
499+
assert texcoords.data.ndim == 2 and texcoords.data.shape[-1] == 2, (
500+
f"Texture {t} requires 2D texcoords"
501+
)
502502
elif view_dim == "cube" or view_dim == "3d" or view_dim == "cube-array":
503-
assert (
504-
texcoords.data.ndim == 2 and texcoords.data.shape[-1] == 3
505-
), f"Texture {t} requires 3D texcoords"
503+
assert texcoords.data.ndim == 2 and texcoords.data.shape[-1] == 3, (
504+
f"Texture {t} requires 3D texcoords"
505+
)
506506
else:
507507
raise ValueError(f"Unknown view_dim: {view_dim}")
508508

pygfx/utils/color.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,11 @@ def css(self):
301301
"""The CSS color string, e.g. "rgba(0,255,0,0.5)"."""
302302
r, g, b, a = self.rgba
303303
if a == 1:
304-
return f"rgb({int(255*r+0.5)},{int(255*g+0.5)},{int(255*b+0.5)})"
304+
return (
305+
f"rgb({int(255 * r + 0.5)},{int(255 * g + 0.5)},{int(255 * b + 0.5)})"
306+
)
305307
else:
306-
return f"rgba({int(255*r+0.5)},{int(255*g+0.5)},{int(255*b+0.5)},{a:0.3f})"
308+
return f"rgba({int(255 * r + 0.5)},{int(255 * g + 0.5)},{int(255 * b + 0.5)},{a:0.3f})"
307309

308310
def clip(self):
309311
"""Return a new Color with the values clipped between 0 and 1."""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ requires-python = ">= 3.9"
2020
dependencies = [
2121
"rendercanvas >= 2",
2222
"wgpu >=0.19.0,<0.20.0",
23-
"pylinalg >=0.6.2,<0.7.0",
23+
"pylinalg >=0.6.3,<0.7.0",
2424
"numpy",
2525
"freetype-py",
2626
"uharfbuzz",

tests/geometries/test_text_geometry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def test_check_speed():
340340
dt = time.perf_counter() - t0
341341
print(
342342
f"\ngenerate_glyph: {n_iter * dt:0.1f} ms total",
343-
f"{1E6 * dt / (n_iter * n_glyphs):0.2f} us per glyph",
343+
f"{1e6 * dt / (n_iter * n_glyphs):0.2f} us per glyph",
344344
)
345345

346346

tests/objects/test_events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ def test_pointer_event_copy():
248248
if not attr.startswith("_") and not callable(getattr(other, attr))
249249
]:
250250
if attr not in ["type", "clicks"]:
251-
assert getattr(other, attr) == getattr(
252-
event, attr
253-
), f"'{attr}' attribute not equal"
251+
assert getattr(other, attr) == getattr(event, attr), (
252+
f"'{attr}' attribute not equal"
253+
)
254254

255255
assert other.type != event.type
256256
assert other.type == "click"

tests/objects/test_materials.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def test_uniform_types_uniform_type():
2222
else:
2323
for key, val in super_cls.uniform_type.items():
2424
assert key in ob.uniform_type, f"{cls.__name__}:{key} missing"
25-
assert (
26-
val == ob.uniform_type[key]
27-
), f"{cls.__name__}:{key} different"
25+
assert val == ob.uniform_type[key], (
26+
f"{cls.__name__}:{key} different"
27+
)
2828

2929

3030
if __name__ == "__main__":

tests/renderers/test_environment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def test_environment_reuse2():
5858

5959
assert env1 is not env2, "env1 and env2 have different number of lights"
6060
assert env2 is env3, "env2 and env3 have same number of lights"
61-
assert (
62-
env2 is env4
63-
), "env2 and env4 have same number of lights, ambient lights dont count"
61+
assert env2 is env4, (
62+
"env2 and env4 have same number of lights, ambient lights dont count"
63+
)
6464
assert env2 is not env5, "env2 and env5 have different number of lights"
6565

6666

tests/utils/test_text_fontmanager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ def check_speed():
316316
font_manager.select_font(text, FontProps())
317317
dt = time.perf_counter() - t0
318318
print(
319-
f"select_font: {1000*dt:0.1f} ms total", f"{1000*dt/(10000):0.3f} ms per char"
319+
f"select_font: {1000 * dt:0.1f} ms total",
320+
f"{1000 * dt / (10000):0.3f} ms per char",
320321
)
321322

322323
# About 0.00 ms (0.3 us), so this negligible.

tests/utils/test_text_sdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def check_speed():
5454
generate_glyph(indices, font.filename)
5555
dt = time.perf_counter() - t0
5656
print(
57-
f"generate_glyph: {1000*dt:0.1f} ms total",
58-
f"{1000*dt/(10000):0.3f} ms per glyph",
57+
f"generate_glyph: {1000 * dt:0.1f} ms total",
58+
f"{1000 * dt / (10000):0.3f} ms per glyph",
5959
)
6060

6161
# If I tweak generate_glyph() to include the time in the hash,

tests/utils/test_text_shaping.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,17 @@ def check_speed():
217217
shape_text_hb(text, font.filename)
218218
dt = time.perf_counter() - t0
219219
print(
220-
f"shape_text_hb: {1000*dt:0.1f} ms total",
221-
f"{1000*dt/(10000):0.3f} ms per glyph",
220+
f"shape_text_hb: {1000 * dt:0.1f} ms total",
221+
f"{1000 * dt / (10000):0.3f} ms per glyph",
222222
)
223223

224224
t0 = time.perf_counter()
225225
for _i in range(1000):
226226
shape_text_ft(text, font.filename)
227227
dt = time.perf_counter() - t0
228228
print(
229-
f"shape_text_ft: {1000*dt:0.1f} ms total",
230-
f"{1000*dt/(10000):0.3f} ms per glyph",
229+
f"shape_text_ft: {1000 * dt:0.1f} ms total",
230+
f"{1000 * dt / (10000):0.3f} ms per glyph",
231231
)
232232

233233
# No cache: about 0.03 and 0.02 ms per glyph for Harfbuzz and FreeType, respectively.

0 commit comments

Comments
 (0)