Skip to content

Commit 2413332

Browse files
committed
Python codestyle cleanups
1 parent 7caa3ed commit 2413332

File tree

4 files changed

+55
-39
lines changed

4 files changed

+55
-39
lines changed

lglpy/comms/service_gpu_timeline.py

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,22 @@ def map_renderpass_binding(type, index: int | None) -> str:
165165
Map the PB encoded render pass attachment type to a description.
166166
'''
167167
if type == timeline_pb2.RenderpassAttachmentType.undefined:
168-
assert ((index is None) or (index == 0))
168+
assert (index is None) or (index == 0)
169169
return "U"
170-
elif type == timeline_pb2.RenderpassAttachmentType.color:
171-
assert (index is not None)
170+
171+
if type == timeline_pb2.RenderpassAttachmentType.color:
172+
assert index is not None
172173
return f"C{index}"
173-
elif type == timeline_pb2.RenderpassAttachmentType.depth:
174-
assert ((index is None) or (index == 0))
174+
175+
if type == timeline_pb2.RenderpassAttachmentType.depth:
176+
assert (index is None) or (index == 0)
175177
return "D"
176-
elif type == timeline_pb2.RenderpassAttachmentType.stencil:
177-
assert ((index is None) or (index == 0))
178+
179+
if type == timeline_pb2.RenderpassAttachmentType.stencil:
180+
assert (index is None) or (index == 0)
178181
return "S"
179-
else:
180-
assert False
182+
183+
assert False
181184

182185

183186
def map_image_transfer_type(type) -> str:
@@ -186,16 +189,20 @@ def map_image_transfer_type(type) -> str:
186189
'''
187190
if type == timeline_pb2.ImageTransferType.unknown_image_transfer:
188191
return "Unknown"
189-
elif type == timeline_pb2.ImageTransferType.clear_image:
192+
193+
if type == timeline_pb2.ImageTransferType.clear_image:
190194
return "Clear image"
191-
elif type == timeline_pb2.ImageTransferType.copy_image:
195+
196+
if type == timeline_pb2.ImageTransferType.copy_image:
192197
return "Copy image"
193-
elif type == timeline_pb2.ImageTransferType.copy_buffer_to_image:
198+
199+
if type == timeline_pb2.ImageTransferType.copy_buffer_to_image:
194200
return "Copy buffer to image"
195-
elif type == timeline_pb2.ImageTransferType.copy_image_to_buffer:
201+
202+
if type == timeline_pb2.ImageTransferType.copy_image_to_buffer:
196203
return "Copy image to buffer"
197-
else:
198-
assert False
204+
205+
assert False
199206

200207

201208
def map_buffer_transfer_type(type) -> str:
@@ -204,12 +211,14 @@ def map_buffer_transfer_type(type) -> str:
204211
'''
205212
if type == timeline_pb2.BufferTransferType.unknown_buffer_transfer:
206213
return "Unknown"
207-
elif type == timeline_pb2.BufferTransferType.fill_buffer:
214+
215+
if type == timeline_pb2.BufferTransferType.fill_buffer:
208216
return "Fill buffer"
209-
elif type == timeline_pb2.BufferTransferType.copy_buffer:
217+
218+
if type == timeline_pb2.BufferTransferType.copy_buffer:
210219
return "Copy buffer"
211-
else:
212-
assert False
220+
221+
assert False
213222

214223

215224
def map_as_build_type(type) -> str:
@@ -218,29 +227,35 @@ def map_as_build_type(type) -> str:
218227
'''
219228
if type == timeline_pb2.AccelerationStructureBuildType.unknown_as_build:
220229
return "Unknown"
221-
elif type == timeline_pb2.AccelerationStructureTransferType.fast_build:
230+
231+
if type == timeline_pb2.AccelerationStructureTransferType.fast_build:
222232
return "Fast build"
223-
elif type == timeline_pb2.AccelerationStructureTransferType.fast_trace:
233+
234+
if type == timeline_pb2.AccelerationStructureTransferType.fast_trace:
224235
return "Fast trace"
225-
else:
226-
assert False
236+
237+
assert False
227238

228239

229240
def map_as_transfer_type(type) -> str:
230241
'''
231242
Map the PB encoded acceleration structure transfer to a description.
232243
'''
233244
base_type = timeline_pb2.AccelerationStructureTransferType
245+
234246
if type == base_type.unknown_as_transfer:
235247
return "Unknown"
236-
elif type == base_type.struct_to_struct:
248+
249+
if type == base_type.struct_to_struct:
237250
return "Copy acceleration structure"
238-
elif type == base_type.struct_to_mem:
251+
252+
if type == base_type.struct_to_mem:
239253
return "Copy acceleration structure to mem"
240-
elif type == base_type.mem_to_struct:
254+
255+
if type == base_type.mem_to_struct:
241256
return "Copy mem to acceleration structure"
242-
else:
243-
assert False
257+
258+
assert False
244259

245260

246261
def map_debug_label(labels: list[str] | None) -> list[str]:
@@ -249,7 +264,8 @@ def map_debug_label(labels: list[str] | None) -> list[str]:
249264
'''
250265
if labels is None:
251266
return []
252-
# need to convert it to a list from a RepeatedScalarContainer
267+
268+
# Need to convert it to a list from a RepeatedScalarContainer
253269
return [str(label) for label in labels]
254270

255271

@@ -292,7 +308,7 @@ def __init__(self, file_path: str, verbose: bool = False):
292308
file_path: File to write on the filesystem
293309
verbose: Should this use verbose logging?
294310
'''
295-
self.devices: dict[int, GPUDeviceState] = dict()
311+
self.devices: dict[int, GPUDeviceState] = {}
296312
self.last_submit: SubmitMetadataType | None = None
297313
self.last_render_pass: RenderpassMetadataType | None = None
298314
# pylint: disable=consider-using-with

lglpy/timeline/data/processed_trace.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class GPUWorkload:
6161
PARENS = re.compile(r'(\(.*\))')
6262
RESOLUTION = re.compile(r'\d+x\d+')
6363
WHITESPACE = re.compile(r'\s\s+')
64-
MEMO: dict[str, str] = dict()
64+
MEMO: dict[str, str] = {}
6565

6666
@classmethod
6767
def memoize(cls, string: str) -> str:
@@ -760,7 +760,7 @@ def get_transfer_size_str(self) -> str:
760760
'''
761761
# If indirect then show a placeholder
762762
if self.pixel_count == -1:
763-
return f'? pixels'
763+
return '? pixels'
764764

765765
s = 's' if self.pixel_count != 1 else ''
766766
label = f'{self.pixel_count} pixel{s}'
@@ -844,7 +844,7 @@ def get_transfer_size_str(self) -> str:
844844
'''
845845
# If indirect then show a placeholder
846846
if self.byte_count == -1:
847-
return f'? bytes'
847+
return '? bytes'
848848

849849
s = 's' if self.byte_count != 1 else ''
850850
label = f'{self.byte_count} byte{s}'
@@ -933,7 +933,7 @@ def get_transfer_size_str(self) -> str:
933933
'''
934934
# If indirect then show a placeholder
935935
if self.primitive_count == -1:
936-
return f'? primitives'
936+
return '? primitives'
937937

938938
s = 's' if self.primitive_count != 1 else ''
939939
label = f'{self.primitive_count} primitive{s}'
@@ -1014,7 +1014,7 @@ def get_transfer_size_str(self) -> str:
10141014
'''
10151015
# If indirect then show a placeholder
10161016
if self.byte_count == -1:
1017-
return f'? bytes'
1017+
return '? bytes'
10181018

10191019
s = 's' if self.byte_count != 1 else ''
10201020
label = f'{self.byte_count} byte{s}'

lglpy/timeline/data/raw_trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class MetadataWorkload:
300300
label_stack: Debug label stack, or None if no user labels.
301301
'''
302302

303-
MEMO: dict[str, str] = dict()
303+
MEMO: dict[str, str] = {}
304304

305305
@classmethod
306306
def memoize(cls, string: str) -> str:

lglpy/timeline/drawable/timeline_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def remove_multiple_from_active_objects(self, old_objects):
285285
Args:
286286
old_objects: the sequence of objects to remove.
287287
'''
288-
removed_objects = {x for x in old_objects}
288+
removed_objects = set(old_objects)
289289
new_active_objects = self.active_objects - removed_objects
290290

291291
# If nothing left then reset the active state
@@ -575,12 +575,12 @@ def on_mouse_single_click(self, button, x, y, mod):
575575
return True
576576

577577
# If 'c' modifier then append selection to highlighted region
578-
elif mod == 'c':
578+
if mod == 'c':
579579
self.add_to_active_objects(clicked_object)
580580
return True
581581

582582
# If 's' modifier then subtract selection to highlighted region
583-
elif mod == 's':
583+
if mod == 's':
584584
self.remove_from_active_objects(clicked_object)
585585
return True
586586

0 commit comments

Comments
 (0)