Cleanup: Python script formatting

- Double quotes for strings.
- Trailing commas when wrapped lines.
This commit is contained in:
Campbell Barton 2024-06-06 11:26:28 +10:00
parent 1d894aa1a7
commit 949dfbfaa8
22 changed files with 57 additions and 54 deletions

@ -1651,7 +1651,7 @@ def pyrna2sphinx(basepath):
fw(" .. {:s}:: {:s}({:s})\n\n".format( fw(" .. {:s}:: {:s}({:s})\n\n".format(
"classmethod" if func.is_classmethod else "method", "classmethod" if func.is_classmethod else "method",
func.identifier, func.identifier,
args_str args_str,
)) ))
fw(" {:s}\n\n".format(func.description)) fw(" {:s}\n\n".format(func.description))

@ -435,7 +435,7 @@ def call_handle_checked(
fn: Callable[[bool, bool], Optional[str]], fn: Callable[[bool, bool], Optional[str]],
*, *,
do_register: bool, do_register: bool,
all_users: bool all_users: bool,
) -> Optional[str]: ) -> Optional[str]:
try: try:
result = fn(do_register, all_users) result = fn(do_register, all_users)

@ -390,7 +390,7 @@ def enable(module_name, *, default_set=False, persistent=False, handle_error=Non
"module loaded with no associated file, __path__={!r}, aborting!".format( "module loaded with no associated file, __path__={!r}, aborting!".format(
getattr(mod, "__path__", None) getattr(mod, "__path__", None)
), ),
name=module_name name=module_name,
) )
mod.__time__ = os.path.getmtime(mod_file) mod.__time__ = os.path.getmtime(mod_file)
mod.__addon_enabled__ = False mod.__addon_enabled__ = False

@ -31,7 +31,7 @@ def ui_draw_filter_register(
ui_ignore_operator=None, ui_ignore_operator=None,
ui_ignore_property=None, ui_ignore_property=None,
ui_ignore_menu=None, ui_ignore_menu=None,
ui_ignore_label=None ui_ignore_label=None,
): ):
import bpy import bpy

@ -564,7 +564,7 @@ def smpte_from_seconds(time, *, fps=None, fps_base=None):
return smpte_from_frame( return smpte_from_frame(
time_to_frame(time, fps=fps, fps_base=fps_base), time_to_frame(time, fps=fps, fps_base=fps_base),
fps=fps, fps=fps,
fps_base=fps_base fps_base=fps_base,
) )

@ -79,7 +79,7 @@ def bake_action(
obj, obj,
*, *,
action, frames, action, frames,
bake_options: BakeOptions bake_options: BakeOptions,
): ):
""" """
:arg obj: Object to bake. :arg obj: Object to bake.

@ -115,7 +115,7 @@ class ANIM_OT_keying_set_export(Operator):
if not found: if not found:
self.report( self.report(
{'WARN'}, {'WARN'},
rpt_("Could not find material or light using Shader Node Tree - {:s}").format(str(ksp.id)) rpt_("Could not find material or light using Shader Node Tree - {:s}").format(str(ksp.id)),
) )
elif ksp.id.bl_rna.identifier.startswith("CompositorNodeTree"): elif ksp.id.bl_rna.identifier.startswith("CompositorNodeTree"):
# Find compositor node-tree using this node tree. # Find compositor node-tree using this node tree.
@ -126,7 +126,7 @@ class ANIM_OT_keying_set_export(Operator):
else: else:
self.report( self.report(
{'WARN'}, {'WARN'},
rpt_("Could not find scene using Compositor Node Tree - {:s}").format(str(ksp.id)) rpt_("Could not find scene using Compositor Node Tree - {:s}").format(str(ksp.id)),
) )
elif ksp.id.bl_rna.name == "Key": elif ksp.id.bl_rna.name == "Key":
# "keys" conflicts with a Python keyword, hence the simple solution won't work # "keys" conflicts with a Python keyword, hence the simple solution won't work
@ -262,7 +262,7 @@ class NLA_OT_bake(Operator):
('ROTATION', "Rotation", "Bake rotation channels"), ('ROTATION', "Rotation", "Bake rotation channels"),
('SCALE', "Scale", "Bake scale channels"), ('SCALE', "Scale", "Bake scale channels"),
('BBONE', "B-Bone", "Bake B-Bone channels"), ('BBONE', "B-Bone", "Bake B-Bone channels"),
('PROPS', "Custom Properties", "Bake custom properties") ('PROPS', "Custom Properties", "Bake custom properties"),
), ),
default={'LOCATION', 'ROTATION', 'SCALE', 'BBONE', 'PROPS'}, default={'LOCATION', 'ROTATION', 'SCALE', 'BBONE', 'PROPS'},
) )
@ -282,7 +282,7 @@ class NLA_OT_bake(Operator):
do_rotation='ROTATION' in self.channel_types, do_rotation='ROTATION' in self.channel_types,
do_scale='SCALE' in self.channel_types, do_scale='SCALE' in self.channel_types,
do_bbone='BBONE' in self.channel_types, do_bbone='BBONE' in self.channel_types,
do_custom_props='PROPS' in self.channel_types do_custom_props='PROPS' in self.channel_types,
) )
if bake_options.do_pose and self.only_selected: if bake_options.do_pose and self.only_selected:
@ -308,7 +308,7 @@ class NLA_OT_bake(Operator):
actions = anim_utils.bake_action_objects( actions = anim_utils.bake_action_objects(
object_action_pairs, object_action_pairs,
frames=range(self.frame_start, self.frame_end + 1, self.step), frames=range(self.frame_start, self.frame_end + 1, self.step),
bake_options=bake_options bake_options=bake_options,
) )
if not any(actions): if not any(actions):

@ -260,7 +260,7 @@ class IMAGE_OT_open_images(Operator):
"prefix": file.name[:len(file.name) - len(match.group(0))], "prefix": file.name[:len(file.name) - len(match.group(0))],
"ext": match.group(2), "ext": match.group(2),
"frame_size": len(match.group(1)), "frame_size": len(match.group(1)),
"files": [file.name] "files": [file.name],
} }
for test_seq in sequences: for test_seq in sequences:
if ( if (

@ -22,7 +22,7 @@ from bpy.props import (
from bpy.app.translations import ( from bpy.app.translations import (
pgettext_tip as tip_, pgettext_tip as tip_,
contexts as i18n_contexts contexts as i18n_contexts,
) )
from mathutils import Vector from mathutils import Vector
@ -675,7 +675,7 @@ class IMAGE_OT_import_as_mesh_planes(AddObjectHelper, ImportHelper, MaterialProp
force_reload: BoolProperty( force_reload: BoolProperty(
name="Force Reload", name="Force Reload",
default=False, default=False,
description="Force reload the image if it is already opened elsewhere in Blender" description="Force reload the image if it is already opened elsewhere in Blender",
) )
image_sequence: BoolProperty( image_sequence: BoolProperty(
@ -903,7 +903,7 @@ class IMAGE_OT_import_as_mesh_planes(AddObjectHelper, ImportHelper, MaterialProp
(fn.name for fn in self.files), (fn.name for fn in self.files),
self.directory, self.directory,
force_reload=self.force_reload, force_reload=self.force_reload,
find_sequences=self.image_sequence find_sequences=self.image_sequence,
)) ))
if not images: if not images:
@ -1029,7 +1029,7 @@ class IMAGE_OT_import_as_mesh_planes(AddObjectHelper, ImportHelper, MaterialProp
elif self.size_mode == 'CAMERA': elif self.size_mode == 'CAMERA':
x, y = compute_camera_size( x, y = compute_camera_size(
context, context.scene.cursor.location, context, context.scene.cursor.location,
self.fill_mode, px / py self.fill_mode, px / py,
) )
elif self.size_mode == 'DPI': elif self.size_mode == 'DPI':
@ -1113,13 +1113,13 @@ class IMAGE_OT_convert_to_mesh_plane(MaterialProperties_MixIn, TextureProperties
('IMAGE', "Source Image", "name from laoded image"), ('IMAGE', "Source Image", "name from laoded image"),
], ],
default='OBJECT', default='OBJECT',
description="Name for new mesh object and material" description="Name for new mesh object and material",
) )
delete_ref: BoolProperty( delete_ref: BoolProperty(
name="Delete Reference Object", name="Delete Reference Object",
default=True, default=True,
description="Delete empty image object once mesh plane is created" description="Delete empty image object once mesh plane is created",
) )
@classmethod @classmethod

@ -60,20 +60,20 @@ class QuickFur(ObjectModeOperator, Operator):
min=0.001, max=100, min=0.001, max=100,
soft_min=0.01, soft_max=10, soft_min=0.01, soft_max=10,
default=0.1, default=0.1,
subtype='DISTANCE' subtype='DISTANCE',
) )
radius: FloatProperty( radius: FloatProperty(
name="Hair Radius", name="Hair Radius",
min=0.0, max=10, min=0.0, max=10,
soft_min=0.0001, soft_max=0.1, soft_min=0.0001, soft_max=0.1,
default=0.001, default=0.001,
subtype='DISTANCE' subtype='DISTANCE',
) )
view_percentage: FloatProperty( view_percentage: FloatProperty(
name="View Percentage", name="View Percentage",
min=0.0, max=1.0, min=0.0, max=1.0,
default=1.0, default=1.0,
subtype='FACTOR' subtype='FACTOR',
) )
apply_hair_guides: BoolProperty( apply_hair_guides: BoolProperty(
name="Apply Hair Guides", name="Apply Hair Guides",

@ -443,7 +443,7 @@ class AddPresetTextEditor(AddPresetBase, Operator):
preset_values = [ preset_values = [
"filepaths.text_editor", "filepaths.text_editor",
"filepaths.text_editor_args" "filepaths.text_editor_args",
] ]
preset_subdir = "text_editor" preset_subdir = "text_editor"
@ -539,7 +539,7 @@ class AddPresetEEVEERaytracing(AddPresetBase, Operator):
preset_defines = [ preset_defines = [
"eevee = bpy.context.scene.eevee", "eevee = bpy.context.scene.eevee",
"options = eevee.ray_tracing_options" "options = eevee.ray_tracing_options",
] ]
preset_values = [ preset_values = [
@ -865,7 +865,7 @@ class WM_OT_operator_presets_cleanup(Operator):
"filepath", "filepath",
"directory", "directory",
"files", "files",
"filename" "filename",
] ]
self._cleanup_operators_presets(operators, properties_exclude) self._cleanup_operators_presets(operators, properties_exclude)

@ -1046,7 +1046,7 @@ class PREFERENCES_OT_studiolight_install(Operator):
# print message # print message
msg = rpt_("StudioLight Installed {!r} into {!r}").format( msg = rpt_("StudioLight Installed {!r} into {!r}").format(
", ".join(e.name for e in self.files), ", ".join(e.name for e in self.files),
path_studiolights path_studiolights,
) )
print(msg) print(msg)
self.report({'INFO'}, msg) self.report({'INFO'}, msg)

@ -1450,7 +1450,7 @@ class WM_OT_properties_edit(Operator):
property_type: EnumProperty( property_type: EnumProperty(
name="Type", name="Type",
items=rna_custom_property_type_items, items=rna_custom_property_type_items,
update=property_type_update_cb update=property_type_update_cb,
) )
is_overridable_library: BoolProperty( is_overridable_library: BoolProperty(
name="Library Overridable", name="Library Overridable",
@ -3374,7 +3374,7 @@ class WM_MT_splash_about(Menu):
col.label(text=iface_("Date: {:s} {:s}").format( col.label(text=iface_("Date: {:s} {:s}").format(
bpy.app.build_commit_date.decode("utf-8", "replace"), bpy.app.build_commit_date.decode("utf-8", "replace"),
bpy.app.build_commit_time.decode("utf-8", "replace")), bpy.app.build_commit_time.decode("utf-8", "replace")),
translate=False translate=False,
) )
col.label(text=iface_("Hash: {:s}").format(bpy.app.build_hash.decode("ascii")), translate=False) col.label(text=iface_("Hash: {:s}").format(bpy.app.build_hash.decode("ascii")), translate=False)
col.label(text=iface_("Branch: {:s}").format(bpy.app.build_branch.decode("utf-8", "replace")), translate=False) col.label(text=iface_("Branch: {:s}").format(bpy.app.build_branch.decode("utf-8", "replace")), translate=False)
@ -3592,5 +3592,5 @@ classes = (
WM_MT_splash_quick_setup, WM_MT_splash_quick_setup,
WM_MT_splash, WM_MT_splash,
WM_MT_splash_about, WM_MT_splash_about,
WM_MT_region_toggle_pie WM_MT_region_toggle_pie,
) )

@ -112,7 +112,7 @@ class WORLD_OT_convert_volume_to_mesh(bpy.types.Operator):
from_socket_index = src_node.outputs.find(src_link.from_socket.name) from_socket_index = src_node.outputs.find(src_link.from_socket.name)
dst_tree.links.new( dst_tree.links.new(
dst_linked_node.outputs[from_socket_index], dst_linked_node.outputs[from_socket_index],
dst_socket dst_socket,
) )
def _sync_node( def _sync_node(

@ -84,7 +84,7 @@ def draw_ui_list(
list_owner, list_prop_name, list_owner, list_prop_name,
index_owner, index_prop_name, index_owner, index_prop_name,
rows=4 if list_to_draw else 1, rows=4 if list_to_draw else 1,
**kwargs **kwargs,
) )
col = row.column() col = row.column()
@ -94,7 +94,7 @@ def draw_ui_list(
layout=col, layout=col,
list_path=list_path, list_path=list_path,
active_index_path=active_index_path, active_index_path=active_index_path,
list_length=len(list_to_draw) list_length=len(list_to_draw),
) )
layout.separator() layout.separator()
@ -107,7 +107,7 @@ def draw_ui_list(
layout=col, layout=col,
list_path=list_path, list_path=list_path,
active_index_path=active_index_path, active_index_path=active_index_path,
list_length=len(list_to_draw) list_length=len(list_to_draw),
) )
# Return the right-side column. # Return the right-side column.

@ -441,7 +441,7 @@ class TEXTURE_PT_image_sampling(TextureTypePanel, Panel):
'BLENDER_RENDER', 'BLENDER_RENDER',
'BLENDER_EEVEE', 'BLENDER_EEVEE',
'BLENDER_EEVEE_NEXT', 'BLENDER_EEVEE_NEXT',
'BLENDER_WORKBENCH' 'BLENDER_WORKBENCH',
} }
def draw(self, context): def draw(self, context):
@ -476,7 +476,7 @@ class TEXTURE_PT_image_alpha(TextureTypePanel, Panel):
'BLENDER_RENDER', 'BLENDER_RENDER',
'BLENDER_EEVEE', 'BLENDER_EEVEE',
'BLENDER_EEVEE_NEXT', 'BLENDER_EEVEE_NEXT',
'BLENDER_WORKBENCH' 'BLENDER_WORKBENCH',
} }
def draw_header(self, context): def draw_header(self, context):
@ -504,7 +504,7 @@ class TEXTURE_PT_image_mapping(TextureTypePanel, Panel):
'BLENDER_RENDER', 'BLENDER_RENDER',
'BLENDER_EEVEE', 'BLENDER_EEVEE',
'BLENDER_EEVEE_NEXT', 'BLENDER_EEVEE_NEXT',
'BLENDER_WORKBENCH' 'BLENDER_WORKBENCH',
} }
def draw(self, context): def draw(self, context):
@ -561,7 +561,7 @@ class TEXTURE_PT_image_mapping_crop(TextureTypePanel, Panel):
'BLENDER_RENDER', 'BLENDER_RENDER',
'BLENDER_EEVEE', 'BLENDER_EEVEE',
'BLENDER_EEVEE_NEXT', 'BLENDER_EEVEE_NEXT',
'BLENDER_WORKBENCH' 'BLENDER_WORKBENCH',
} }
def draw(self, context): def draw(self, context):

@ -80,7 +80,7 @@ class TEXT_HT_footer(Header):
text=iface_("Text: External") text=iface_("Text: External")
if text.library if text.library
else iface_("Text: Internal"), else iface_("Text: Internal"),
translate=False translate=False,
) )

@ -1642,7 +1642,7 @@ class USERPREF_PT_file_paths_asset_libraries(FilePathsPanel, Panel):
row.template_list( row.template_list(
"USERPREF_UL_asset_libraries", "user_asset_libraries", "USERPREF_UL_asset_libraries", "user_asset_libraries",
paths, "asset_libraries", paths, "asset_libraries",
paths, "active_asset_library" paths, "active_asset_library",
) )
col = row.column(align=True) col = row.column(align=True)
@ -2145,7 +2145,7 @@ class USERPREF_PT_extensions_repos(Panel):
row.template_list( row.template_list(
"USERPREF_UL_extension_repos", "user_extension_repos", "USERPREF_UL_extension_repos", "user_extension_repos",
extensions, "repos", extensions, "repos",
extensions, "active_repo" extensions, "active_repo",
) )
col = row.column(align=True) col = row.column(align=True)

@ -1058,7 +1058,7 @@ class VIEW3D_HT_header(Header):
layout.popover( layout.popover(
panel="VIEW3D_PT_gpencil_sculpt_automasking", panel="VIEW3D_PT_gpencil_sculpt_automasking",
text="", text="",
icon=VIEW3D_HT_header._gpencil_sculpt_automasking_icon(tool_settings.gpencil_sculpt) icon=VIEW3D_HT_header._gpencil_sculpt_automasking_icon(tool_settings.gpencil_sculpt),
) )
elif object_mode == 'SCULPT': elif object_mode == 'SCULPT':
@ -1090,7 +1090,7 @@ class VIEW3D_HT_header(Header):
layout.popover( layout.popover(
panel="VIEW3D_PT_sculpt_automasking", panel="VIEW3D_PT_sculpt_automasking",
text="", text="",
icon=VIEW3D_HT_header._sculpt_automasking_icon(tool_settings.sculpt) icon=VIEW3D_HT_header._sculpt_automasking_icon(tool_settings.sculpt),
) )
elif object_mode == 'VERTEX_PAINT': elif object_mode == 'VERTEX_PAINT':
@ -3502,8 +3502,11 @@ class VIEW3D_MT_object_convert(Menu):
ob = context.active_object ob = context.active_object
if ob and ob.type != "EMPTY": if ob and ob.type != "EMPTY":
if (ob.type == 'GPENCIL' and context.gpencil_data if (
and not context.preferences.experimental.use_grease_pencil_version3): (ob.type == 'GPENCIL') and
(context.gpencil_data is not None) and
(not context.preferences.experimental.use_grease_pencil_version3)
):
layout.operator_enum("gpencil.convert", "type") layout.operator_enum("gpencil.convert", "type")
else: else:
layout.operator_enum("object.convert", "target") layout.operator_enum("object.convert", "target")
@ -3828,7 +3831,7 @@ class VIEW3D_MT_sculpt(Menu):
('SHARPEN', iface_("Sharpen")), ('SHARPEN', iface_("Sharpen")),
('ENHANCE_DETAILS', iface_("Enhance Details")), ('ENHANCE_DETAILS', iface_("Enhance Details")),
('ERASE_DISCPLACEMENT', iface_("Erase Multires Displacement")), ('ERASE_DISCPLACEMENT', iface_("Erase Multires Displacement")),
('RANDOM', iface_("Randomize")) ('RANDOM', iface_("Randomize")),
] ]
for filter_type, ui_name in sculpt_filters_types: for filter_type, ui_name in sculpt_filters_types:

@ -35,7 +35,7 @@ class VIEW3D_PT_animation_layers(Panel):
# FIXME: this should be done in response to a message-bus callback, notifier, whatnot. # FIXME: this should be done in response to a message-bus callback, notifier, whatnot.
adt = context.object.animation_data adt = context.object.animation_data
with _wm_selected_action_lock: with _wm_selected_action_lock:
selected_action = getattr(adt, 'action', None) selected_action = getattr(adt, "action", None)
# Only set if it has to change, to avoid unnecessary notifies (that cause # Only set if it has to change, to avoid unnecessary notifies (that cause
# a redraw, that cause this code to be called, etc.) # a redraw, that cause this code to be called, etc.)
if context.window_manager.selected_action != selected_action: if context.window_manager.selected_action != selected_action:
@ -45,7 +45,7 @@ class VIEW3D_PT_animation_layers(Panel):
# This has to go via an auxiliary property, as assigning an Animation # This has to go via an auxiliary property, as assigning an Animation
# data-block should be possible even when `context.object.animation_data` # data-block should be possible even when `context.object.animation_data`
# is `None`, and thus its `animation` property does not exist. # is `None`, and thus its `animation` property does not exist.
col.template_ID(context.window_manager, 'selected_action') col.template_ID(context.window_manager, "selected_action")
col = layout.column(align=False) col = layout.column(align=False)
anim = adt and adt.action anim = adt and adt.action
@ -54,21 +54,21 @@ class VIEW3D_PT_animation_layers(Panel):
# Binding selector. # Binding selector.
row = binding_sub.row(align=True) row = binding_sub.row(align=True)
row.prop(adt, 'action_binding', text="Binding") row.prop(adt, "action_binding", text="Binding")
row.operator('anim.binding_unassign_object', text="", icon='X') row.operator("anim.binding_unassign_object", text="", icon='X')
binding = anim.bindings.get(adt.action_binding, None) binding = anim.bindings.get(adt.action_binding, None)
if binding: if binding:
binding_sub.prop(binding, 'name_display', text="Name") binding_sub.prop(binding, "name_display", text="Name")
internal_sub = binding_sub.box().column(align=True) internal_sub = binding_sub.box().column(align=True)
internal_sub.active = False internal_sub.active = False
internal_sub.prop(adt, 'action_binding_handle', text="handle") internal_sub.prop(adt, "action_binding_handle", text="handle")
if binding: if binding:
internal_sub.prop(binding, 'name', text="Internal Name") internal_sub.prop(binding, "name", text="Internal Name")
if adt: if adt:
col.prop(adt, 'action_binding_name', text="ADT Binding Name") col.prop(adt, "action_binding_name", text="ADT Binding Name")
else: else:
col.label(text="ADT Binding Name: -") col.label(text="ADT Binding Name: -")

@ -26,7 +26,7 @@ class MyPanel(bpy.types.Panel):
classes = [ classes = [
MyPropGroup, MyPropGroup,
MyPanel MyPanel,
] ]
class_register, class_unregister = bpy.utils.register_classes_factory(classes) class_register, class_unregister = bpy.utils.register_classes_factory(classes)

@ -197,7 +197,7 @@ def dice(
id_str = dice_icon_name( id_str = dice_icon_name(
x, y, x, y,
parts_x, parts_y, parts_x, parts_y,
name_style=name_style, prefix=output_prefix name_style=name_style, prefix=output_prefix,
) )
if not id_str: if not id_str:
continue continue