From 4c5f30bcefbaaf0f4c90ad4ce0fdb4e63e188930 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Thu, 5 Dec 2024 15:56:39 +0100 Subject: [PATCH 1/4] Add configuration for code linting and formatting - Introduced a new config file for linting and formatting. - Set up exclusions for common directories. - Configured line length, indent width, and quote style. - Enabled specific lint rules while allowing unused variables with underscores. - Added options for auto-formatting in docstrings (currently disabled). --- ruff.toml | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 ruff.toml diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..153a5c7 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,74 @@ +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".ipynb_checkpoints", + ".mypy_cache", + ".nox", + ".pants.d", + ".pyenv", + ".pytest_cache", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + ".vscode", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "site-packages", + "venv", +] + +# Same as Black. +line-length = 79 +indent-width = 4 + +[lint] +# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. +# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or +# McCabe complexity (`C901`) by default. +select = ["E", "F", "W"] +ignore = [] + +# Allow fix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = [] + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +[format] +# Like Black, use double quotes for strings. +quote-style = "double" + +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" + +# Like Black, respect magic trailing commas. +skip-magic-trailing-comma = false + +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" + +# Enable auto-formatting of code examples in docstrings. Markdown, +# reStructuredText code/literal blocks and doctests are all supported. +# +# This is currently disabled by default, but it is planned for this +# to be opt-out in the future. +docstring-code-format = false + +# Set the line length limit used when formatting code snippets in +# docstrings. +# +# This only has an effect when the `docstring-code-format` setting is +# enabled. +docstring-code-line-length = "dynamic" From 80aff6290ecf1f24ea5b9af4fb3b11227f8f1fe7 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Thu, 5 Dec 2024 15:56:48 +0100 Subject: [PATCH 2/4] Refactor code for better readability - Cleaned up formatting and indentation across multiple files. - Improved line breaks for long statements to enhance clarity. - Updated error messages to use f-strings for consistency. - Removed unnecessary blank lines and spaces. --- client/ayon_flame/api/lib.py | 3 +- client/ayon_flame/api/menu.py | 8 +- client/ayon_flame/otio/flame_export.py | 3 +- .../plugins/create/create_shot_clip.py | 86 ++++++++++--------- .../plugins/create/create_workfile.py | 2 +- client/ayon_flame/plugins/load/load_clip.py | 6 +- .../plugins/load/load_clip_batch.py | 3 +- .../plugins/publish/collect_audio.py | 3 +- .../plugins/publish/collect_plate.py | 6 +- .../plugins/publish/collect_shots.py | 25 +++--- server/settings/loader_plugins.py | 3 +- 11 files changed, 84 insertions(+), 64 deletions(-) diff --git a/client/ayon_flame/api/lib.py b/client/ayon_flame/api/lib.py index 912e7b4..d7dab93 100644 --- a/client/ayon_flame/api/lib.py +++ b/client/ayon_flame/api/lib.py @@ -1161,7 +1161,8 @@ def _get_resolution_info_from_origin(self, xml_data): # height out_feed_height_obj = out_feed.find("storageFormat/height") - self.height = int(self._get_typed_value(out_feed_height_obj)) + self.height = int( + self._get_typed_value(out_feed_height_obj)) # pixel aspect ratio out_feed_pixel_aspect_obj = out_feed.find( diff --git a/client/ayon_flame/api/menu.py b/client/ayon_flame/api/menu.py index 0fc5460..6e9ca2b 100644 --- a/client/ayon_flame/api/menu.py +++ b/client/ayon_flame/api/menu.py @@ -53,7 +53,7 @@ def _get_main_window(): None ) return _MAIN_WINDOW - + class _FlameMenuApp(object): def __init__(self, framework): @@ -83,7 +83,11 @@ def __init__(self, framework): project_name = get_current_project_name() self.menu = { "actions": [ - {"name": f"0 - {project_name or 'project'}", "isEnabled": False}], + { + "name": f"0 - {project_name or 'project'}", + "isEnabled": False + } + ], "name": self.menu_group_name, } self.tools_helper = host_tools.HostToolsHelper( diff --git a/client/ayon_flame/otio/flame_export.py b/client/ayon_flame/otio/flame_export.py index f7f1415..79036a5 100644 --- a/client/ayon_flame/otio/flame_export.py +++ b/client/ayon_flame/otio/flame_export.py @@ -358,7 +358,8 @@ def create_otio_clip(clip_data): # create source range available_media_start = media_reference.available_range.start_time - conformed_media_start = available_media_start.value_rescaled_to(CTX.get_fps()) + conformed_media_start = available_media_start.value_rescaled_to( + CTX.get_fps()) source_range = create_otio_time_range( conformed_media_start + source_in, _clip_record_duration, diff --git a/client/ayon_flame/plugins/create/create_shot_clip.py b/client/ayon_flame/plugins/create/create_shot_clip.py index 976b1c8..695c747 100644 --- a/client/ayon_flame/plugins/create/create_shot_clip.py +++ b/client/ayon_flame/plugins/create/create_shot_clip.py @@ -123,7 +123,10 @@ def create(self, instance_data, _): }) new_instance = CreatedInstance( - self.product_type, instance_data["productName"], instance_data, self + self.product_type, + instance_data["productName"], + instance_data, + self ) self._add_instance_to_context(new_instance) new_instance.transient_data["has_promised_context"] = True @@ -620,7 +623,8 @@ def create(self, product_name, instance_data, pre_create_data): # Delete any existing instances previously generated for the clip. prev_tag_data = lib.get_segment_data_marker(segment) if prev_tag_data: - for creator_id, inst_data in prev_tag_data.get(_CONTENT_ID, {}).items(): + for creator_id, inst_data in prev_tag_data.get( + _CONTENT_ID, {}).items(): creator = self.create_context.creators[creator_id] prev_instance = self.create_context.instances_by_id.get( inst_data["instance_id"] @@ -639,7 +643,8 @@ def create(self, product_name, instance_data, pre_create_data): pre_create_data.get("export_audio", False) ) - enabled_creators = tuple(cre for cre, enabled in all_creators.items() if enabled) + enabled_creators = tuple( + cre for cre, enabled in all_creators.items() if enabled) clip_instances = {} shot_folder_path = segment_instance_data["folderPath"] shot_instances = self.shot_instances.setdefault( @@ -659,32 +664,35 @@ def create(self, product_name, instance_data, pre_create_data): segment_duration = int(segment_data["record_duration"]) workfileFrameStart = sub_instance_data[ "workfileFrameStart"] - sub_instance_data.update({ - "variant": "main", - "productType": "shot", - "productName": "shotMain", - "creator_attributes": { - "workfileFrameStart": sub_instance_data[ - "workfileFrameStart"], - "handleStart": sub_instance_data["handleStart"], - "handleEnd": sub_instance_data["handleEnd"], - "frameStart": workfileFrameStart, - "frameEnd": ( - workfileFrameStart + segment_duration), - "clipIn": int(segment_data["record_in"]), - "clipOut": int(segment_data["record_out"]), - "clipDuration": segment_duration, - "sourceIn": int(segment_data["source_in"]), - "sourceOut": int(segment_data["source_out"]), - "includeHandles": pre_create_data[ - "includeHandles"], - "retimedHandles": pre_create_data[ - "retimedHandles"], - "retimedFramerange": pre_create_data[ - "retimedFramerange"], - }, - "label": f"{shot_folder_path} shot", - }) + sub_instance_data.update( + { + "variant": "main", + "productType": "shot", + "productName": "shotMain", + "creator_attributes": { + "workfileFrameStart": workfileFrameStart, + "handleStart": sub_instance_data[ + "handleStart"], + "handleEnd": sub_instance_data["handleEnd"], + "frameStart": workfileFrameStart, + "frameEnd": ( + workfileFrameStart + segment_duration), + "clipIn": int(segment_data["record_in"]), + "clipOut": int(segment_data["record_out"]), + "clipDuration": segment_duration, + "sourceIn": int(segment_data["source_in"]), + "sourceOut": int(segment_data["source_out"]), + "includeHandles": pre_create_data[ + "includeHandles"], + "retimedHandles": pre_create_data[ + "retimedHandles"], + "retimedFramerange": pre_create_data[ + "retimedFramerange" + ], + }, + "label": f"{shot_folder_path} shot", + } + ) # Plate, # insert parent instance data to allow @@ -693,7 +701,8 @@ def create(self, product_name, instance_data, pre_create_data): parenting_data = shot_instances[shot_creator_id] sub_instance_data.update( { - "parent_instance_id": parenting_data["instance_id"], + "parent_instance_id": parenting_data[ + "instance_id"], "label": ( f"{sub_instance_data['folderPath']} " f"{sub_instance_data['productName']}" @@ -722,7 +731,8 @@ def create(self, product_name, instance_data, pre_create_data): parenting_data = shot_instances[shot_creator_id] sub_instance_data.update( { - "parent_instance_id": parenting_data["instance_id"], + "parent_instance_id": parenting_data[ + "instance_id"], "label": ( f"{sub_instance_data['folderPath']} " f"{sub_instance_data['productName']}" @@ -757,8 +767,8 @@ def create(self, product_name, instance_data, pre_create_data): return instances - def _create_and_add_instance(self, data, creator_id, - segment, instances): + def _create_and_add_instance( + self, data, creator_id, segment, instances): """ Args: data (dict): The data to re-recreate the instance from. @@ -797,17 +807,15 @@ def _collect_legacy_instance(self, segment, marker_data): sub_instance_data = instance_data.copy() segment_data = flame_export.get_segment_attributes(segment) segment_duration = int(segment_data["record_duration"]) - workfileFrameStart = \ - sub_instance_data["workfileFrameStart"] + workfileFrameStart = sub_instance_data["workfileFrameStart"] sub_instance_data.update({ "creator_attributes": { - "workfileFrameStart": \ - sub_instance_data["workfileFrameStart"], + "workfileFrameStart": workfileFrameStart, "handleStart": sub_instance_data["handleStart"], "handleEnd": sub_instance_data["handleEnd"], "frameStart": workfileFrameStart, - "frameEnd": (workfileFrameStart + - segment_duration), + "frameEnd": ( + workfileFrameStart + segment_duration), "clipIn": int(segment_data["record_in"]), "clipOut": int(segment_data["record_out"]), "clipDuration": segment_duration, diff --git a/client/ayon_flame/plugins/create/create_workfile.py b/client/ayon_flame/plugins/create/create_workfile.py index dc80135..8604589 100644 --- a/client/ayon_flame/plugins/create/create_workfile.py +++ b/client/ayon_flame/plugins/create/create_workfile.py @@ -108,7 +108,7 @@ def _create_new_instance(self): def create(self, options=None): """Auto-create an instance by default.""" - instance_data = self._load_instance_data() + instance_data = self._load_instance_data() if instance_data: return diff --git a/client/ayon_flame/plugins/load/load_clip.py b/client/ayon_flame/plugins/load/load_clip.py index 2ede130..69571ec 100644 --- a/client/ayon_flame/plugins/load/load_clip.py +++ b/client/ayon_flame/plugins/load/load_clip.py @@ -105,7 +105,8 @@ def load(self, context, name, namespace, options): openclip_path ) - # add additional metadata from the version to imprint basic folder attributes + # add additional metadata from the version to imprint basic + # folder attributes add_keys = [ "frameStart", "frameEnd", "source", "author", "fps", "handleStart", "handleEnd" @@ -209,7 +210,8 @@ def _get_segment_from_clip(self, clip): # if colorspace: # clip.setSourceMediaColourTransform(colorspace) - # # add additional metadata from the version to imprint basic folder attributes + # # add additional metadata from the version to imprint basic + # # folder attributes # add_keys = [ # "frameStart", "frameEnd", "source", "author", # "fps", "handleStart", "handleEnd" diff --git a/client/ayon_flame/plugins/load/load_clip_batch.py b/client/ayon_flame/plugins/load/load_clip_batch.py index 8eaa66f..5103ae0 100644 --- a/client/ayon_flame/plugins/load/load_clip_batch.py +++ b/client/ayon_flame/plugins/load/load_clip_batch.py @@ -121,7 +121,8 @@ def load(self, context, name, namespace, options): openclip_path ) - # add additional metadata from the version to imprint basic folder attributes + # add additional metadata from the version to imprint basic + # folder attributes add_keys = [ "frameStart", "frameEnd", "source", "author", "fps", "handleStart", "handleEnd" diff --git a/client/ayon_flame/plugins/publish/collect_audio.py b/client/ayon_flame/plugins/publish/collect_audio.py index bc5344d..763a6c6 100644 --- a/client/ayon_flame/plugins/publish/collect_audio.py +++ b/client/ayon_flame/plugins/publish/collect_audio.py @@ -29,7 +29,8 @@ def process(self, instance): otio_timeline, instance.data["clip_index"] ) if not otio_clip: - raise RuntimeError("Could not retrieve otioClip for shot %r", instance) + raise RuntimeError( + f"Could not retrieve otioClip for shot {instance}") instance.data["otioClip"] = otio_clip diff --git a/client/ayon_flame/plugins/publish/collect_plate.py b/client/ayon_flame/plugins/publish/collect_plate.py index 058e894..933d0db 100644 --- a/client/ayon_flame/plugins/publish/collect_plate.py +++ b/client/ayon_flame/plugins/publish/collect_plate.py @@ -25,7 +25,8 @@ def process(self, instance): otio_timeline, instance.data["clip_index"] ) if not otio_clip: - raise RuntimeError("Could not retrieve otioClip for shot %r", instance) + raise RuntimeError( + f"Could not retrieve otioClip for shot {instance}") instance.data["otioClip"] = otio_clip @@ -60,4 +61,5 @@ def process(self, instance): version_data["colorSpace"] = clip_data["colour_space"] instance.data["colorspace"] = clip_data["colour_space"] - instance.data["shotDurationFromSource"] = instance.data.get("retimedFramerange") + instance.data["shotDurationFromSource"] = instance.data.get( + "retimedFramerange") diff --git a/client/ayon_flame/plugins/publish/collect_shots.py b/client/ayon_flame/plugins/publish/collect_shots.py index ce9a526..c88780f 100644 --- a/client/ayon_flame/plugins/publish/collect_shots.py +++ b/client/ayon_flame/plugins/publish/collect_shots.py @@ -44,7 +44,7 @@ class CollectShot(pyblish.api.InstancePlugin): # TODO: add to own plugin for Flame # TODO: toggle for marking task which should be used for product parent - add_tasks = [] + add_tasks = [] @classmethod def _inject_editorial_shared_data(cls, instance): @@ -84,7 +84,8 @@ def process(self, instance): otio_timeline, instance.data["clip_index"] ) if not otio_clip: - raise RuntimeError("Could not retrieve otioClip for shot %r", instance) + raise RuntimeError( + f"Could not retrieve otioClip for shot {instance}") # Compute fps from creator attribute. creator_attrs = instance.data['creator_attributes'] @@ -99,18 +100,19 @@ def process(self, instance): for item in instance.context.data["flameSegments"]: item_data = ayfapi.get_segment_data_marker(item) or {} if item_data.get("clip_index") == instance.data["clip_index"]: - segment_item = item - break + segment_item = item + break if segment_item is None: - raise PublishError("Could not retrieve source from sequence segments.") + raise PublishError( + "Could not retrieve source from sequence segments.") comment_attributes = self._get_comment_attributes(segment_item) instance.data.update(comment_attributes) clip_data = ayfapi.get_segment_attributes(segment_item) clip_name = clip_data["segment_name"] - self.log.debug("clip_name: {}".format(clip_name)) + self.log.debug(f"clip_name: {clip_name}") # get file path file_path = clip_data["fpath"] @@ -142,8 +144,6 @@ def process(self, instance): "path": file_path, "sourceFirstFrame": int(first_frame), "workfileFrameStart": workfile_start, - - #TODO "flameAddTasks": self.add_tasks, "tasks": { task["name"]: {"type": task["type"]} @@ -153,7 +153,7 @@ def process(self, instance): self._get_resolution_to_data(instance.data, instance.context) self._inject_editorial_shared_data(instance) - self.log.debug("__ inst_data: {}".format(pformat(instance.data))) + self.log.debug(f"__ inst_data: {pformat(instance.data)}") @staticmethod def _set_workfile_start(data): @@ -279,15 +279,14 @@ def _get_head_tail(self, clip_data, otio_clip, handle_start, handle_end): # calculate head and tail with forward compatibility head = clip_data.get("segment_head") tail = clip_data.get("segment_tail") - self.log.debug("__ head: `{}`".format(head)) - self.log.debug("__ tail: `{}`".format(tail)) + self.log.debug(f"__ head: `{head}`") + self.log.debug(f"__ tail: `{tail}`") # HACK: it is here to serve for versions below 2021.1 if not any([head, tail]): retimed_attributes = get_media_range_with_retimes( otio_clip, handle_start, handle_end) - self.log.debug( - ">> retimed_attributes: {}".format(retimed_attributes)) + self.log.debug(f">> retimed_attributes: {retimed_attributes}") # retimed head and tail head = int(retimed_attributes["handleStart"]) diff --git a/server/settings/loader_plugins.py b/server/settings/loader_plugins.py index 684115b..cf056f7 100644 --- a/server/settings/loader_plugins.py +++ b/server/settings/loader_plugins.py @@ -93,7 +93,8 @@ class LoaderPluginsModel(BaseSettingsModel): "review" ], "reel_name": "AYON_LoadedReel", - "clip_name_template": "{batch}_{folder[name]}_{product[name]}<_{output}>", + "clip_name_template": ( + "{batch}_{folder[name]}_{product[name]}<_{output}>"), "layer_rename_template": "{folder[name]}_{product[name]}<_{output}>", "layer_rename_patterns": [ "rgb", From 660c15ca4f8b0a9722975077ade6d2cfab165b86 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Thu, 5 Dec 2024 16:02:54 +0100 Subject: [PATCH 3/4] test commit --- ruff.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruff.toml b/ruff.toml index 153a5c7..8eed094 100644 --- a/ruff.toml +++ b/ruff.toml @@ -36,7 +36,7 @@ indent-width = 4 # Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. # Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or # McCabe complexity (`C901`) by default. -select = ["E", "F", "W"] +select = ["ALL"] ignore = [] # Allow fix for all enabled rules (when `--fix`) is provided. From b2e1105e3f7147f0fb0297dd83a67ba2a0374e9a Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Thu, 5 Dec 2024 16:04:10 +0100 Subject: [PATCH 4/4] reversing test commit --- ruff.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruff.toml b/ruff.toml index 8eed094..153a5c7 100644 --- a/ruff.toml +++ b/ruff.toml @@ -36,7 +36,7 @@ indent-width = 4 # Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. # Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or # McCabe complexity (`C901`) by default. -select = ["ALL"] +select = ["E", "F", "W"] ignore = [] # Allow fix for all enabled rules (when `--fix`) is provided.