From db069448df569a165fd3521a4a4353d83bf4862d Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:59:43 +0200 Subject: [PATCH 001/106] python module tools do not support python 2 anymore --- client/ayon_core/lib/python_module_tools.py | 129 ++++++-------------- 1 file changed, 34 insertions(+), 95 deletions(-) diff --git a/client/ayon_core/lib/python_module_tools.py b/client/ayon_core/lib/python_module_tools.py index cb6e4c14c4..d146e069a9 100644 --- a/client/ayon_core/lib/python_module_tools.py +++ b/client/ayon_core/lib/python_module_tools.py @@ -5,43 +5,30 @@ import inspect import logging -import six - log = logging.getLogger(__name__) def import_filepath(filepath, module_name=None): """Import python file as python module. - Python 2 and Python 3 compatibility. - Args: - filepath(str): Path to python file. - module_name(str): Name of loaded module. Only for Python 3. By default + filepath (str): Path to python file. + module_name (str): Name of loaded module. Only for Python 3. By default is filled with filename of filepath. + """ if module_name is None: module_name = os.path.splitext(os.path.basename(filepath))[0] - # Make sure it is not 'unicode' in Python 2 - module_name = str(module_name) - # Prepare module object where content of file will be parsed module = types.ModuleType(module_name) module.__file__ = filepath - if six.PY3: - # Use loader so module has full specs - module_loader = importlib.machinery.SourceFileLoader( - module_name, filepath - ) - module_loader.exec_module(module) - else: - # Execute module code and store content to module - with open(filepath) as _stream: - # Execute content and store it to module object - six.exec_(_stream.read(), module.__dict__) - + # Use loader so module has full specs + module_loader = importlib.machinery.SourceFileLoader( + module_name, filepath + ) + module_loader.exec_module(module) return module @@ -139,35 +126,31 @@ def classes_from_module(superclass, module): return classes -def _import_module_from_dirpath_py2(dirpath, module_name, dst_module_name): - """Import passed dirpath as python module using `imp`.""" - if dst_module_name: - full_module_name = "{}.{}".format(dst_module_name, module_name) - dst_module = sys.modules[dst_module_name] - else: - full_module_name = module_name - dst_module = None - - if full_module_name in sys.modules: - return sys.modules[full_module_name] - - import imp +def import_module_from_dirpath(dirpath, folder_name, dst_module_name=None): + """Import passed directory as a python module. - fp, pathname, description = imp.find_module(module_name, [dirpath]) - module = imp.load_module(full_module_name, fp, pathname, description) - if dst_module is not None: - setattr(dst_module, module_name, module) + Imported module can be assigned as a child attribute of already loaded + module from `sys.modules` if has support of `setattr`. That is not default + behavior of python modules so parent module must be a custom module with + that ability. - return module + It is not possible to reimport already cached module. If you need to + reimport module you have to remove it from caches manually. + Args: + dirpath (str): Parent directory path of loaded folder. + folder_name (str): Folder name which should be imported inside passed + directory. + dst_module_name (str): Parent module name under which can be loaded + module added. -def _import_module_from_dirpath_py3(dirpath, module_name, dst_module_name): - """Import passed dirpath as python module using Python 3 modules.""" + """ + # Import passed dirpath as python module if dst_module_name: - full_module_name = "{}.{}".format(dst_module_name, module_name) + full_module_name = "{}.{}".format(dst_module_name, folder_name) dst_module = sys.modules[dst_module_name] else: - full_module_name = module_name + full_module_name = folder_name dst_module = None # Skip import if is already imported @@ -191,7 +174,7 @@ def _import_module_from_dirpath_py3(dirpath, module_name, dst_module_name): # Store module to destination module and `sys.modules` # WARNING this mus be done before module execution if dst_module is not None: - setattr(dst_module, module_name, module) + setattr(dst_module, folder_name, module) sys.modules[full_module_name] = module @@ -201,37 +184,6 @@ def _import_module_from_dirpath_py3(dirpath, module_name, dst_module_name): return module -def import_module_from_dirpath(dirpath, folder_name, dst_module_name=None): - """Import passed directory as a python module. - - Python 2 and 3 compatible. - - Imported module can be assigned as a child attribute of already loaded - module from `sys.modules` if has support of `setattr`. That is not default - behavior of python modules so parent module must be a custom module with - that ability. - - It is not possible to reimport already cached module. If you need to - reimport module you have to remove it from caches manually. - - Args: - dirpath(str): Parent directory path of loaded folder. - folder_name(str): Folder name which should be imported inside passed - directory. - dst_module_name(str): Parent module name under which can be loaded - module added. - """ - if six.PY3: - module = _import_module_from_dirpath_py3( - dirpath, folder_name, dst_module_name - ) - else: - module = _import_module_from_dirpath_py2( - dirpath, folder_name, dst_module_name - ) - return module - - def is_func_signature_supported(func, *args, **kwargs): """Check if a function signature supports passed args and kwargs. @@ -275,25 +227,12 @@ def is_func_signature_supported(func, *args, **kwargs): Returns: bool: Function can pass in arguments. - """ - - if hasattr(inspect, "signature"): - # Python 3 using 'Signature' object where we try to bind arg - # or kwarg. Using signature is recommended approach based on - # documentation. - sig = inspect.signature(func) - try: - sig.bind(*args, **kwargs) - return True - except TypeError: - pass - else: - # In Python 2 'signature' is not available so 'getcallargs' is used - # - 'getcallargs' is marked as deprecated since Python 3.0 - try: - inspect.getcallargs(func, *args, **kwargs) - return True - except TypeError: - pass + """ + sig = inspect.signature(func) + try: + sig.bind(*args, **kwargs) + return True + except TypeError: + pass return False From 6e7d6201c969b8f3147db9f724efd03c836cf17a Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:00:15 +0200 Subject: [PATCH 002/106] use WeakMethod from weakref --- client/ayon_core/lib/events.py | 3 +- client/ayon_core/lib/python_2_comp.py | 53 +++++++-------------------- 2 files changed, 14 insertions(+), 42 deletions(-) diff --git a/client/ayon_core/lib/events.py b/client/ayon_core/lib/events.py index 774790b80a..9a3d1edfd4 100644 --- a/client/ayon_core/lib/events.py +++ b/client/ayon_core/lib/events.py @@ -8,7 +8,6 @@ import weakref from uuid import uuid4 -from .python_2_comp import WeakMethod from .python_module_tools import is_func_signature_supported @@ -18,7 +17,7 @@ class MissingEventSystem(Exception): def _get_func_ref(func): if inspect.ismethod(func): - return WeakMethod(func) + return weakref.WeakMethod(func) return weakref.ref(func) diff --git a/client/ayon_core/lib/python_2_comp.py b/client/ayon_core/lib/python_2_comp.py index 091c51a6f6..900db59062 100644 --- a/client/ayon_core/lib/python_2_comp.py +++ b/client/ayon_core/lib/python_2_comp.py @@ -1,44 +1,17 @@ +# Deprecated file +# - the file container 'WeakMethod' implementation for Python 2 which is not +# needed anymore. +import warnings import weakref -WeakMethod = getattr(weakref, "WeakMethod", None) +WeakMethod = weakref.WeakMethod -if WeakMethod is None: - class _WeakCallable: - def __init__(self, obj, func): - self.im_self = obj - self.im_func = func - - def __call__(self, *args, **kws): - if self.im_self is None: - return self.im_func(*args, **kws) - else: - return self.im_func(self.im_self, *args, **kws) - - - class WeakMethod: - """ Wraps a function or, more importantly, a bound method in - a way that allows a bound method's object to be GCed, while - providing the same interface as a normal weak reference. """ - - def __init__(self, fn): - try: - self._obj = weakref.ref(fn.im_self) - self._meth = fn.im_func - except AttributeError: - # It's not a bound method - self._obj = None - self._meth = fn - - def __call__(self): - if self._dead(): - return None - return _WeakCallable(self._getobj(), self._meth) - - def _dead(self): - return self._obj is not None and self._obj() is None - - def _getobj(self): - if self._obj is None: - return None - return self._obj() +warnings.warn( + ( + "'ayon_core.lib.python_2_comp' is deprecated." + "Please use 'weakref.WeakMethod'." + ), + DeprecationWarning, + stacklevel=2 +) From e731dd7064a52035cfec4f8d233344507e2b3a6c Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:00:30 +0200 Subject: [PATCH 003/106] don't handle py2 vs. py3 imports --- client/ayon_core/lib/local_settings.py | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/client/ayon_core/lib/local_settings.py b/client/ayon_core/lib/local_settings.py index 54432265d9..00e551d119 100644 --- a/client/ayon_core/lib/local_settings.py +++ b/client/ayon_core/lib/local_settings.py @@ -3,26 +3,10 @@ import os import json import platform +import configparser from datetime import datetime from abc import ABC, abstractmethod - -# disable lru cache in Python 2 -try: - from functools import lru_cache -except ImportError: - def lru_cache(maxsize): - def max_size(func): - def wrapper(*args, **kwargs): - value = func(*args, **kwargs) - return value - return wrapper - return max_size - -# ConfigParser was renamed in python3 to configparser -try: - import configparser -except ImportError: - import ConfigParser as configparser +from functools import lru_cache import appdirs import ayon_api From 11641c996e880d555e12d6320462d8ed11350b68 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:05:22 +0200 Subject: [PATCH 004/106] do not inherit from object by default --- client/ayon_core/lib/attribute_definitions.py | 2 +- client/ayon_core/lib/events.py | 7 +++---- client/ayon_core/lib/file_transaction.py | 2 +- client/ayon_core/lib/path_templates.py | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/client/ayon_core/lib/attribute_definitions.py b/client/ayon_core/lib/attribute_definitions.py index 360d47ea17..7e022f6dba 100644 --- a/client/ayon_core/lib/attribute_definitions.py +++ b/client/ayon_core/lib/attribute_definitions.py @@ -577,7 +577,7 @@ def convert_value(self, value): return self.default -class FileDefItem(object): +class FileDefItem: def __init__( self, directory, filenames, frames=None, template=None ): diff --git a/client/ayon_core/lib/events.py b/client/ayon_core/lib/events.py index 9a3d1edfd4..2601bc1cf4 100644 --- a/client/ayon_core/lib/events.py +++ b/client/ayon_core/lib/events.py @@ -122,7 +122,7 @@ def validate_signature(self, *args, **kwargs): ) -class EventCallback(object): +class EventCallback: """Callback registered to a topic. The callback function is registered to a topic. Topic is a string which @@ -379,8 +379,7 @@ def _validate_ref(self): self._partial_func = None -# Inherit from 'object' for Python 2 hosts -class Event(object): +class Event: """Base event object. Can be used for any event because is not specific. Only required argument @@ -487,7 +486,7 @@ def from_data(cls, event_data, event_system=None): return obj -class EventSystem(object): +class EventSystem: """Encapsulate event handling into an object. System wraps registered callbacks and triggered events into single object, diff --git a/client/ayon_core/lib/file_transaction.py b/client/ayon_core/lib/file_transaction.py index 47b10dd994..a502403958 100644 --- a/client/ayon_core/lib/file_transaction.py +++ b/client/ayon_core/lib/file_transaction.py @@ -22,7 +22,7 @@ class DuplicateDestinationError(ValueError): """ -class FileTransaction(object): +class FileTransaction: """File transaction with rollback options. The file transaction is a three-step process. diff --git a/client/ayon_core/lib/path_templates.py b/client/ayon_core/lib/path_templates.py index 01a6985a25..ccd36796c1 100644 --- a/client/ayon_core/lib/path_templates.py +++ b/client/ayon_core/lib/path_templates.py @@ -38,7 +38,7 @@ def __init__(self, template, missing_keys, invalid_types): ) -class StringTemplate(object): +class StringTemplate: """String that can be formatted.""" def __init__(self, template): if not isinstance(template, str): @@ -410,7 +410,7 @@ def add_invalid_type(self, key, value): self._invalid_types[key] = type(value) -class FormatObject(object): +class FormatObject: """Object that can be used for formatting. This is base that is valid for to be used in 'StringTemplate' value. From 8a20416e492a8301c8bcdb264b9f6b1bd3d00dc6 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 8 Aug 2024 10:10:21 +0200 Subject: [PATCH 005/106] don't validate extension of dropped file --- .../ayon_core/tools/publisher/publish_report_viewer/window.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/window.py b/client/ayon_core/tools/publisher/publish_report_viewer/window.py index aedc3b9e31..d5742d73e0 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/window.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/window.py @@ -576,8 +576,7 @@ def dropEvent(self, event): filepaths = [] for url in mime_data.urls(): filepath = url.toLocalFile() - ext = os.path.splitext(filepath)[-1] - if os.path.exists(filepath) and ext == ".json": + if os.path.exists(filepath): filepaths.append(filepath) self._add_filepaths(filepaths) event.accept() From 85a7d2e24e3f712eea225cb5baac4ea236cdedbe Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:27:45 +0200 Subject: [PATCH 006/106] added more information about plugin to report --- client/ayon_core/tools/publisher/models/publish.py | 8 +++++++- .../tools/publisher/publish_report_viewer/report_items.py | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/tools/publisher/models/publish.py b/client/ayon_core/tools/publisher/models/publish.py index ef207bfb79..42dcca7bb3 100644 --- a/client/ayon_core/tools/publisher/models/publish.py +++ b/client/ayon_core/tools/publisher/models/publish.py @@ -172,7 +172,7 @@ def get_report( "crashed_file_paths": crashed_file_paths, "id": uuid.uuid4().hex, "created_at": now.isoformat(), - "report_version": "1.0.1", + "report_version": "1.1.0", } def _add_plugin_data_item(self, plugin: pyblish.api.Plugin): @@ -194,11 +194,17 @@ def _create_plugin_data_item( if hasattr(plugin, "label"): label = plugin.label + plugin_type = "instance" if plugin.__instanceEnabled__ else "context" + return { "id": plugin.id, "name": plugin.__name__, "label": label, "order": plugin.order, + "filepath": inspect.getfile(plugin), + "docstring": inspect.getdoc(plugin), + "plugin_type": plugin_type, + "families": list(plugin.families), "targets": list(plugin.targets), "instances_data": [], "actions_data": [], diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/report_items.py b/client/ayon_core/tools/publisher/publish_report_viewer/report_items.py index 206f999bac..cfc2fbfd67 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/report_items.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/report_items.py @@ -13,6 +13,12 @@ def __init__(self, plugin_data): self.skipped = plugin_data["skipped"] self.passed = plugin_data["passed"] + # Introduced in report '1.1.0' + self.docstring = plugin_data.get("docstring") + self.filepath = plugin_data.get("filepath") + self.plugin_type = plugin_data.get("plugin_type") + self.families = plugin_data.get("families") + errored = False for instance_data in plugin_data["instances_data"]: for log_item in instance_data["logs"]: From d0ea1a31b1562a0803f62fc8c040eb7bb47bf941 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:30:25 +0200 Subject: [PATCH 007/106] mark tab widget as active to avoid long loading time --- .../publish_report_viewer/widgets.py | 103 +++++++++++++++--- 1 file changed, 87 insertions(+), 16 deletions(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index 61a52533ba..3e2c6adc8a 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -23,32 +23,73 @@ class PluginLoadReportModel(QtGui.QStandardItemModel): - def set_report(self, report): - parent = self.invisibleRootItem() - parent.removeRows(0, parent.rowCount()) + def __init__(self): + super().__init__() + self._traceback_by_filepath = {} + self._items_by_filepath = {} + self._is_active = True + self._need_refresh = False + + def set_active(self, is_active): + if self._is_active is is_active: + return + self._is_active = is_active + self._update_items() + def set_report(self, report): + self._need_refresh = True if report is None: + self._traceback_by_filepath.clear() + self._update_items() + return + + filepaths = set(report.crashed_plugin_paths.keys()) + to_remove = set(self._traceback_by_filepath) - filepaths + for filepath in filepaths: + self._traceback_by_filepath[filepath] = ( + report.crashed_plugin_paths[filepath] + ) + + for filepath in to_remove: + self._traceback_by_filepath.pop(filepath) + self._update_items() + + def _update_items(self): + if not self._is_active or not self._need_refresh: + return + parent = self.invisibleRootItem() + if not self._traceback_by_filepath: + parent.removeRows(0, parent.rowCount()) return new_items = [] new_items_by_filepath = {} - for filepath in report.crashed_plugin_paths.keys(): + to_remove = ( + set(self._items_by_filepath) - set(self._traceback_by_filepath) + ) + for filepath in self._traceback_by_filepath: + if filepath in self._items_by_filepath: + continue item = QtGui.QStandardItem(filepath) new_items.append(item) new_items_by_filepath[filepath] = item + self._items_by_filepath[filepath] = item - if not new_items: - return + if new_items: + parent.appendRows(new_items) - parent.appendRows(new_items) for filepath, item in new_items_by_filepath.items(): - traceback_txt = report.crashed_plugin_paths[filepath] + traceback_txt = self._traceback_by_filepath[filepath] detail_item = QtGui.QStandardItem() detail_item.setData(filepath, FILEPATH_ROLE) detail_item.setData(traceback_txt, TRACEBACK_ROLE) detail_item.setData(True, IS_DETAIL_ITEM_ROLE) item.appendRow(detail_item) + for filepath in to_remove: + item = self._items_by_filepath.pop(filepath) + parent.removeRow(item.row()) + class DetailWidget(QtWidgets.QTextEdit): def __init__(self, text, *args, **kwargs): @@ -95,10 +136,12 @@ def __init__(self, parent): self._model = model self._widgets_by_filepath = {} - def _on_expand(self, index): - for row in range(self._model.rowCount(index)): - child_index = self._model.index(row, index.column(), index) - self._create_widget(child_index) + def set_active(self, is_active): + self._model.set_active(is_active) + + def set_report(self, report): + self._widgets_by_filepath = {} + self._model.set_report(report) def showEvent(self, event): super().showEvent(event) @@ -108,6 +151,11 @@ def resizeEvent(self, event): super().resizeEvent(event) self._update_widgets_size_hints() + def _on_expand(self, index): + for row in range(self._model.rowCount(index)): + child_index = self._model.index(row, index.column(), index) + self._create_widget(child_index) + def _update_widgets_size_hints(self): for item in self._widgets_by_filepath.values(): widget, index = item @@ -136,10 +184,6 @@ def _create_widget(self, index): self._view.setIndexWidget(index, widget) self._widgets_by_filepath[filepath] = (widget, index) - def set_report(self, report): - self._widgets_by_filepath = {} - self._model.set_report(report) - class ZoomPlainText(QtWidgets.QPlainTextEdit): min_point_size = 1.0 @@ -229,6 +273,8 @@ def __init__(self, parent): layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(output_widget) + self._is_active = True + self._need_refresh = False self._output_widget = output_widget self._report_item = None self._instance_filter = set() @@ -237,21 +283,33 @@ def __init__(self, parent): def clear(self): self._output_widget.setPlainText("") + def set_active(self, is_active): + if self._is_active is is_active: + return + self._is_active = is_active + self._update_logs() + def set_report(self, report): self._report_item = report self._plugin_filter = set() self._instance_filter = set() + self._need_refresh = True self._update_logs() def set_plugin_filter(self, plugin_filter): self._plugin_filter = plugin_filter + self._need_refresh = True self._update_logs() def set_instance_filter(self, instance_filter): self._instance_filter = instance_filter + self._need_refresh = True self._update_logs() def _update_logs(self): + if not self._is_active or not self._need_refresh: + return + if not self._report_item: self._output_widget.setPlainText("") return @@ -422,6 +480,8 @@ def __init__(self, parent=None): logs_text_widget = DetailsWidget(details_tab_widget) plugin_load_report_widget = PluginLoadReportWidget(details_tab_widget) + plugin_load_report_widget.set_active(False) + details_tab_widget.addTab(logs_text_widget, "Logs") details_tab_widget.addTab(plugin_load_report_widget, "Crashed plugins") @@ -440,6 +500,7 @@ def __init__(self, parent=None): layout.addWidget(middle_widget, 0) layout.addWidget(details_widget, 1) + details_tab_widget.currentChanged.connect(self._on_tab_change) instances_view.selectionModel().selectionChanged.connect( self._on_instance_change ) @@ -458,6 +519,7 @@ def __init__(self, parent=None): details_popup_btn.clicked.connect(self._on_details_popup) details_popup.closed.connect(self._on_popup_close) + self._current_tab_idx = 0 self._ignore_selection_changes = False self._report_item = None self._logs_text_widget = logs_text_widget @@ -517,6 +579,15 @@ def set_report(self, report): self._instances_view.expandAll() self._plugins_view.expandAll() + def _on_tab_change(self, new_idx): + if self._current_tab_idx == new_idx: + return + old_widget = self._details_tab_widget.widget(self._current_tab_idx) + new_widget = self._details_tab_widget.widget(new_idx) + self._current_tab_idx = new_idx + old_widget.set_active(False) + new_widget.set_active(True) + def _on_instance_change(self, *_args): if self._ignore_selection_changes: return From d073f15a7a8dbd8e9271459e210384c52963898b Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:30:43 +0200 Subject: [PATCH 008/106] added helper 'ElideLabel' widget to elide long text --- client/ayon_core/tools/utils/__init__.py | 2 + client/ayon_core/tools/utils/widgets.py | 64 ++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/client/ayon_core/tools/utils/__init__.py b/client/ayon_core/tools/utils/__init__.py index 4b5fbeaf67..1eada0c67a 100644 --- a/client/ayon_core/tools/utils/__init__.py +++ b/client/ayon_core/tools/utils/__init__.py @@ -5,6 +5,7 @@ ComboBox, CustomTextComboBox, PlaceholderLineEdit, + ElideLabel, ExpandingTextEdit, BaseClickableFrame, ClickableFrame, @@ -88,6 +89,7 @@ "ComboBox", "CustomTextComboBox", "PlaceholderLineEdit", + "ElideLabel", "ExpandingTextEdit", "BaseClickableFrame", "ClickableFrame", diff --git a/client/ayon_core/tools/utils/widgets.py b/client/ayon_core/tools/utils/widgets.py index 28331fbc35..af85fc915e 100644 --- a/client/ayon_core/tools/utils/widgets.py +++ b/client/ayon_core/tools/utils/widgets.py @@ -104,6 +104,70 @@ def __init__(self, *args, **kwargs): self.setPalette(filter_palette) +class ElideLabel(QtWidgets.QLabel): + """Label which elide text. + + By default, elide happens in middle. Can be changed with + 'set_elide_mode' method. + """ + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.setSizePolicy( + QtWidgets.QSizePolicy.Expanding, + QtWidgets.QSizePolicy.Preferred + ) + # Store text set during init + self._text = self.text() + # Define initial elide mode + self._elide_mode = QtCore.Qt.ElideMiddle + # Make sure that text of QLabel is empty + super().setText("") + + def setText(self, text): + # Update private text attribute and force update + self._text = text + self.update() + + def setWordWrap(self, word_wrap): + # Word wrap is not supported in 'ElideLabel' + if word_wrap: + raise ValueError("Word wrap is not supported in 'ElideLabel'.") + + def set_set(self, text): + self.setText(text) + + def set_elide_mode(self, elide_mode): + """Change elide type. + + Args: + elide_mode: Possible elide type. Available in 'QtCore.Qt' + 'ElideLeft', 'ElideRight' and 'ElideMiddle'. + + """ + if elide_mode == QtCore.Qt.ElideNone: + raise ValueError( + "Invalid elide type. 'ElideNone' is not supported." + ) + + if elide_mode not in ( + QtCore.Qt.ElideLeft, + QtCore.Qt.ElideRight, + QtCore.Qt.ElideMiddle, + ): + raise ValueError(f"Unknown value '{elide_mode}'") + self._elide_mode = elide_mode + + def paintEvent(self, event): + super().paintEvent(event) + + painter = QtGui.QPainter(self) + fm = painter.fontMetrics() + elided_line = fm.elidedText( + self._text, self._elide_mode, self.width() + ) + painter.drawText(QtCore.QPoint(0, fm.ascent()), elided_line) + + class ExpandingTextEdit(QtWidgets.QTextEdit): """QTextEdit which does not have sroll area but expands height.""" From 2a0208a49406537aad756f7305b1cdc9a235e0eb Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:48:37 +0200 Subject: [PATCH 009/106] added plugin details widget --- .../publish_report_viewer/widgets.py | 161 +++++++++++++++++- 1 file changed, 159 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index 3e2c6adc8a..1dc4eccce8 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -1,7 +1,7 @@ from math import ceil from qtpy import QtWidgets, QtCore, QtGui -from ayon_core.tools.utils import NiceCheckbox +from ayon_core.tools.utils import NiceCheckbox, ElideLabel # from ayon_core.tools.utils import DeselectableTreeView from .constants import ( @@ -352,6 +352,155 @@ def _set_logs(self, logs): self._output_widget.setPlainText(text) +class PluginDetailsWidget(QtWidgets.QWidget): + def __init__(self, plugin_item, parent): + super().__init__(parent) + + content_widget = QtWidgets.QWidget(self) + + plugin_label_widget = QtWidgets.QLabel(content_widget) + + plugin_type_label = QtWidgets.QLabel("Plugin type:") + plugin_type_widget = QtWidgets.QLabel(content_widget) + + plugin_path_label = QtWidgets.QLabel("File Path:") + plugin_path_widget = ElideLabel(content_widget) + + plugin_doc_widget = QtWidgets.QLabel(content_widget) + plugin_doc_widget.setWordWrap(True) + + plugin_families_label = QtWidgets.QLabel("Families:") + plugin_families_widget = QtWidgets.QLabel(content_widget) + plugin_families_widget.setWordWrap(True) + + plugin_label_widget.setText(plugin_item.label or plugin_item.name) + plugin_doc_widget.setText(plugin_item.docstring or "N/A") + plugin_type_widget.setText(plugin_item.plugin_type or "N/A") + plugin_path_widget.setText(plugin_item.filepath or "N/A") + plugin_path_widget.setToolTip(plugin_item.filepath or None) + plugin_families_widget.setText(str(plugin_item.families or "N/A")) + + row = 0 + + content_layout = QtWidgets.QGridLayout(content_widget) + content_layout.setContentsMargins(0, 0, 0, 0) + content_layout.setColumnStretch(0, 0) + content_layout.setColumnStretch(1, 1) + + content_layout.addWidget(plugin_label_widget, row, 0, 1, 2) + row += 1 + + content_layout.addWidget(plugin_doc_widget, row, 0, 1, 2) + row += 1 + + content_layout.addWidget(plugin_type_label, row, 0) + content_layout.addWidget(plugin_type_widget, row, 1) + row += 1 + + content_layout.addWidget(plugin_path_label, row, 0) + content_layout.addWidget(plugin_path_widget, row, 1) + row += 1 + + content_layout.addWidget(plugin_families_label, row, 0) + content_layout.addWidget(plugin_families_widget, row, 1) + row += 1 + + main_layout = QtWidgets.QVBoxLayout(self) + main_layout.setContentsMargins(0, 0, 0, 0) + main_layout.addWidget(content_widget, 0) + + +class PluginsDetailsWidget(QtWidgets.QWidget): + def __init__(self, parent): + super().__init__(parent) + + scroll_area = QtWidgets.QScrollArea(self) + scroll_area.setWidgetResizable(True) + + content_widget = QtWidgets.QWidget(scroll_area) + + scroll_area.setWidget(content_widget) + + content_layout = QtWidgets.QVBoxLayout(content_widget) + content_layout.addStretch(1) + + main_layout = QtWidgets.QVBoxLayout(self) + main_layout.setContentsMargins(0, 0, 0, 0) + main_layout.addWidget(scroll_area, 1) + + self._scroll_area = scroll_area + self._content_layout = content_layout + self._content_widget = content_widget + + self._widgets_by_plugin_id = {} + + self._is_active = True + self._need_refresh = False + + self._report_item = None + self._plugin_filter = set() + self._plugin_ids = None + + def set_active(self, is_active): + if self._is_active is is_active: + return + self._is_active = is_active + self._update_widgets() + + def set_plugin_filter(self, plugin_filter): + self._plugin_filter = plugin_filter + self._need_refresh = True + self._update_widgets() + + def set_report(self, report): + self._report_item = report + self._plugin_ids = None + self._plugin_filter = set() + self._need_refresh = True + self._update_widgets() + + def _get_plugin_ids(self): + if self._plugin_ids is not None: + return self._plugin_ids + + # Clear layout and clear widgets + while self._content_layout.count(): + self._content_layout.takeAt(0) + + self._widgets_by_plugin_id.clear() + + plugin_ids = [] + if self._report_item is not None: + plugin_ids = list(self._report_item.plugins_id_order) + self._plugin_ids = plugin_ids + return plugin_ids + + def _update_widgets(self): + if not self._is_active or not self._need_refresh: + return + + self._need_refresh = False + + is_new = len(self._widgets_by_plugin_id) == 0 + for plugin_id in self._get_plugin_ids(): + widget = self._widgets_by_plugin_id.get(plugin_id) + if is_new: + plugin_item = self._report_item.plugins_items_by_id[plugin_id] + widget = PluginDetailsWidget(plugin_item, self._content_widget) + self._widgets_by_plugin_id[plugin_id] = widget + + widget.setVisible( + not self._plugin_filter + or plugin_id in self._plugin_filter + ) + + if is_new: + self._content_layout.addWidget(widget, 0) + + if is_new: + self._content_layout.addStretch(1) + + class DeselectableTreeView(QtWidgets.QTreeView): """A tree view that deselects on clicking on an empty area in the view""" @@ -479,11 +628,16 @@ def __init__(self, parent=None): logs_text_widget = DetailsWidget(details_tab_widget) plugin_load_report_widget = PluginLoadReportWidget(details_tab_widget) + plugins_details_widget = PluginsDetailsWidget(details_tab_widget) plugin_load_report_widget.set_active(False) + plugins_details_widget.set_active(False) details_tab_widget.addTab(logs_text_widget, "Logs") - details_tab_widget.addTab(plugin_load_report_widget, "Crashed plugins") + details_tab_widget.addTab(plugins_details_widget, "Plugins Details") + details_tab_widget.addTab( + plugin_load_report_widget, "Crashed plugins" + ) middle_widget = QtWidgets.QWidget(self) middle_layout = QtWidgets.QGridLayout(middle_widget) @@ -524,6 +678,7 @@ def __init__(self, parent=None): self._report_item = None self._logs_text_widget = logs_text_widget self._plugin_load_report_widget = plugin_load_report_widget + self._plugins_details_widget = plugins_details_widget self._removed_instances_check = removed_instances_check self._instances_view = instances_view @@ -573,6 +728,7 @@ def set_report(self, report): self._plugins_model.set_report(report) self._logs_text_widget.set_report(report) self._plugin_load_report_widget.set_report(report) + self._plugins_details_widget.set_report(report) self._ignore_selection_changes = False @@ -609,6 +765,7 @@ def _on_plugin_change(self, *_args): plugin_ids.add(index.data(ITEM_ID_ROLE)) self._logs_text_widget.set_plugin_filter(plugin_ids) + self._plugins_details_widget.set_plugin_filter(plugin_ids) def _on_skipped_plugin_check(self): self._plugins_proxy.set_ignore_skipped( From f65cf0325bc62f53147074c8206a6a71a5fdf5d9 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:04:54 +0200 Subject: [PATCH 010/106] overall fixes of details widget --- client/ayon_core/style/style.css | 12 +++ .../publish_report_viewer/widgets.py | 88 ++++++++++++------- 2 files changed, 69 insertions(+), 31 deletions(-) diff --git a/client/ayon_core/style/style.css b/client/ayon_core/style/style.css index 607fd1fa31..c8ba2ba8f2 100644 --- a/client/ayon_core/style/style.css +++ b/client/ayon_core/style/style.css @@ -1231,6 +1231,18 @@ ValidationArtistMessage QLabel { background: transparent; } +#PluginDetailsContent { + background: {color:bg-inputs}; + border-radius: 0.2em; +} +#PluginDetailsContent #PluginLabel { + font-size: 14pt; + font-weight: bold; +} +#PluginDetailsContent #PluginFormLabel { + font-weight: bold; +} + CreateNextPageOverlay { font-size: 32pt; } diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index 1dc4eccce8..263ca0464a 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -356,46 +356,66 @@ class PluginDetailsWidget(QtWidgets.QWidget): def __init__(self, plugin_item, parent): super().__init__(parent) - content_widget = QtWidgets.QWidget(self) + content_widget = QtWidgets.QFrame(self) + content_widget.setObjectName("PluginDetailsContent") plugin_label_widget = QtWidgets.QLabel(content_widget) - - plugin_type_label = QtWidgets.QLabel("Plugin type:") - plugin_type_widget = QtWidgets.QLabel(content_widget) + plugin_label_widget.setObjectName("PluginLabel") + plugin_label_widget.setTextInteractionFlags( + QtCore.Qt.TextBrowserInteraction + ) plugin_path_label = QtWidgets.QLabel("File Path:") plugin_path_widget = ElideLabel(content_widget) - - plugin_doc_widget = QtWidgets.QLabel(content_widget) - plugin_doc_widget.setWordWrap(True) + plugin_path_widget.set_elide_mode(QtCore.Qt.ElideLeft) plugin_families_label = QtWidgets.QLabel("Families:") plugin_families_widget = QtWidgets.QLabel(content_widget) + plugin_families_widget.setTextInteractionFlags( + QtCore.Qt.TextBrowserInteraction + ) plugin_families_widget.setWordWrap(True) - plugin_label_widget.setText(plugin_item.label or plugin_item.name) - plugin_doc_widget.setText(plugin_item.docstring or "N/A") - plugin_type_widget.setText(plugin_item.plugin_type or "N/A") + for label_widget in ( + plugin_path_label, + plugin_families_label, + ): + label_widget.setObjectName("PluginFormLabel") + + plugin_doc_widget = QtWidgets.QLabel(content_widget) + plugin_doc_widget.setWordWrap(True) + plugin_doc_widget.setTextInteractionFlags( + QtCore.Qt.TextBrowserInteraction + ) + + plugin_label = plugin_item.label or plugin_item.name + if plugin_item.plugin_type: + plugin_label += " ({})".format( + plugin_item.plugin_type.capitalize() + ) + plugin_label_widget.setText(plugin_label) + # plugin_type_widget.setText(plugin_item.plugin_type or "N/A") plugin_path_widget.setText(plugin_item.filepath or "N/A") plugin_path_widget.setToolTip(plugin_item.filepath or None) plugin_families_widget.setText(str(plugin_item.families or "N/A")) + plugin_doc_widget.setText(plugin_item.docstring or "N/A") row = 0 content_layout = QtWidgets.QGridLayout(content_widget) - content_layout.setContentsMargins(0, 0, 0, 0) + content_layout.setContentsMargins(8, 8, 8, 8) content_layout.setColumnStretch(0, 0) content_layout.setColumnStretch(1, 1) content_layout.addWidget(plugin_label_widget, row, 0, 1, 2) row += 1 - content_layout.addWidget(plugin_doc_widget, row, 0, 1, 2) - row += 1 - - content_layout.addWidget(plugin_type_label, row, 0) - content_layout.addWidget(plugin_type_widget, row, 1) - row += 1 + # Hide docstring if it is empty + if plugin_item.docstring: + content_layout.addWidget(plugin_doc_widget, row, 0, 1, 2) + row += 1 + else: + plugin_doc_widget.setVisible(False) content_layout.addWidget(plugin_path_label, row, 0) content_layout.addWidget(plugin_path_widget, row, 1) @@ -417,12 +437,19 @@ def __init__(self, parent): scroll_area = QtWidgets.QScrollArea(self) scroll_area.setWidgetResizable(True) - content_widget = QtWidgets.QWidget(scroll_area) + scroll_content_widget = QtWidgets.QWidget(scroll_area) - scroll_area.setWidget(content_widget) + scroll_area.setWidget(scroll_content_widget) + + content_widget = QtWidgets.QWidget(scroll_content_widget) content_layout = QtWidgets.QVBoxLayout(content_widget) - content_layout.addStretch(1) + content_layout.setContentsMargins(0, 0, 0, 0) + + scroll_content_layout = QtWidgets.QVBoxLayout(scroll_content_widget) + scroll_content_layout.setContentsMargins(0, 0, 0, 0) + scroll_content_layout.addWidget(content_widget, 0) + scroll_content_layout.addStretch(1) main_layout = QtWidgets.QVBoxLayout(self) main_layout.setContentsMargins(0, 0, 0, 0) @@ -433,6 +460,7 @@ def __init__(self, parent): self._content_widget = content_widget self._widgets_by_plugin_id = {} + self._stretch_item_index = 0 self._is_active = True self._need_refresh = False @@ -448,15 +476,15 @@ def set_active(self, is_active): self._update_widgets() def set_plugin_filter(self, plugin_filter): - self._plugin_filter = plugin_filter self._need_refresh = True + self._plugin_filter = plugin_filter self._update_widgets() def set_report(self, report): - self._report_item = report self._plugin_ids = None self._plugin_filter = set() self._need_refresh = True + self._report_item = report self._update_widgets() def _get_plugin_ids(self): @@ -465,7 +493,11 @@ def _get_plugin_ids(self): # Clear layout and clear widgets while self._content_layout.count(): - self._content_layout.takeAt(0) + item = self._content_layout.takeAt(0) + widget = item.widget() + if widget: + widget.setVisible(False) + widget.deleteLater() self._widgets_by_plugin_id.clear() @@ -481,25 +513,19 @@ def _update_widgets(self): self._need_refresh = False - is_new = len(self._widgets_by_plugin_id) == 0 for plugin_id in self._get_plugin_ids(): widget = self._widgets_by_plugin_id.get(plugin_id) - if is_new: + if widget is None: plugin_item = self._report_item.plugins_items_by_id[plugin_id] widget = PluginDetailsWidget(plugin_item, self._content_widget) self._widgets_by_plugin_id[plugin_id] = widget + self._content_layout.addWidget(widget, 0) widget.setVisible( not self._plugin_filter or plugin_id in self._plugin_filter ) - if is_new: - self._content_layout.addWidget(widget, 0) - - if is_new: - self._content_layout.addStretch(1) - class DeselectableTreeView(QtWidgets.QTreeView): """A tree view that deselects on clicking on an empty area in the view""" From f16cb1f4e137fa0b20fd18e06472bbf74b2735b7 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:05:09 +0200 Subject: [PATCH 011/106] added option to copy text from ElideLabel --- client/ayon_core/tools/utils/widgets.py | 36 +++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/tools/utils/widgets.py b/client/ayon_core/tools/utils/widgets.py index af85fc915e..e58333a07d 100644 --- a/client/ayon_core/tools/utils/widgets.py +++ b/client/ayon_core/tools/utils/widgets.py @@ -107,8 +107,11 @@ def __init__(self, *args, **kwargs): class ElideLabel(QtWidgets.QLabel): """Label which elide text. - By default, elide happens in middle. Can be changed with + By default, elide happens on right side. Can be changed with 'set_elide_mode' method. + + It is not possible to use other features of QLabel like word wrap or + interactive text. This is a simple label which elide text. """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -119,7 +122,7 @@ def __init__(self, *args, **kwargs): # Store text set during init self._text = self.text() # Define initial elide mode - self._elide_mode = QtCore.Qt.ElideMiddle + self._elide_mode = QtCore.Qt.ElideRight # Make sure that text of QLabel is empty super().setText("") @@ -133,6 +136,30 @@ def setWordWrap(self, word_wrap): if word_wrap: raise ValueError("Word wrap is not supported in 'ElideLabel'.") + def contextMenuEvent(self, event): + menu = self.create_context_menu(event.pos()) + if menu is None: + event.ignore() + return + event.accept() + menu.setAttribute(QtCore.Qt.WA_DeleteOnClose) + menu.popup(event.globalPos()) + + def create_context_menu(self, pos): + if not self._text: + return None + menu = QtWidgets.QMenu(self) + + # Copy text action + copy_action = menu.addAction("Copy") + copy_action.setObjectName("edit-copy") + icon = QtGui.QIcon.fromTheme("edit-copy") + if not icon.isNull(): + copy_action.setIcon(icon) + + copy_action.triggered.connect(self._on_copy_text) + return menu + def set_set(self, text): self.setText(text) @@ -156,6 +183,7 @@ def set_elide_mode(self, elide_mode): ): raise ValueError(f"Unknown value '{elide_mode}'") self._elide_mode = elide_mode + self.update() def paintEvent(self, event): super().paintEvent(event) @@ -167,6 +195,10 @@ def paintEvent(self, event): ) painter.drawText(QtCore.QPoint(0, fm.ascent()), elided_line) + def _on_copy_text(self): + clipboard = QtWidgets.QApplication.clipboard() + clipboard.setText(self._text) + class ExpandingTextEdit(QtWidgets.QTextEdit): """QTextEdit which does not have sroll area but expands height.""" From 3977a21820d0d6e5d8f547e95a0567b0f8e1450e Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:33:59 +0200 Subject: [PATCH 012/106] use only plugin's docstring --- client/ayon_core/tools/publisher/models/publish.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/tools/publisher/models/publish.py b/client/ayon_core/tools/publisher/models/publish.py index 42dcca7bb3..a973d47a11 100644 --- a/client/ayon_core/tools/publisher/models/publish.py +++ b/client/ayon_core/tools/publisher/models/publish.py @@ -195,14 +195,20 @@ def _create_plugin_data_item( label = plugin.label plugin_type = "instance" if plugin.__instanceEnabled__ else "context" - + # Get docstring + # NOTE we do care only about docstring from the plugin so we can't + # use 'inspect.getdoc' which also looks for docstring in parent + # classes. + docstring = getattr(plugin, "__doc__", None) + if docstring: + docstring = inspect.cleandoc(docstring) return { "id": plugin.id, "name": plugin.__name__, "label": label, "order": plugin.order, "filepath": inspect.getfile(plugin), - "docstring": inspect.getdoc(plugin), + "docstring": docstring, "plugin_type": plugin_type, "families": list(plugin.families), "targets": list(plugin.targets), From cf68742129e89f929793c22255a72ee2f84d2105 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:34:20 +0200 Subject: [PATCH 013/106] added class name and order --- .../publish_report_viewer/widgets.py | 74 ++++++++++++------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index 263ca0464a..a403bd06fc 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -1,7 +1,7 @@ from math import ceil from qtpy import QtWidgets, QtCore, QtGui -from ayon_core.tools.utils import NiceCheckbox, ElideLabel +from ayon_core.tools.utils import NiceCheckbox, ElideLabel, SeparatorWidget # from ayon_core.tools.utils import DeselectableTreeView from .constants import ( @@ -361,51 +361,66 @@ def __init__(self, plugin_item, parent): plugin_label_widget = QtWidgets.QLabel(content_widget) plugin_label_widget.setObjectName("PluginLabel") - plugin_label_widget.setTextInteractionFlags( - QtCore.Qt.TextBrowserInteraction - ) - plugin_path_label = QtWidgets.QLabel("File Path:") - plugin_path_widget = ElideLabel(content_widget) - plugin_path_widget.set_elide_mode(QtCore.Qt.ElideLeft) + plugin_doc_widget = QtWidgets.QLabel(content_widget) + plugin_doc_widget.setWordWrap(True) + + form_separator = SeparatorWidget(parent=content_widget) plugin_families_label = QtWidgets.QLabel("Families:") plugin_families_widget = QtWidgets.QLabel(content_widget) - plugin_families_widget.setTextInteractionFlags( - QtCore.Qt.TextBrowserInteraction - ) plugin_families_widget.setWordWrap(True) + plugin_order_label = QtWidgets.QLabel("Order:") + plugin_order_widget = QtWidgets.QLabel(content_widget) + + plugin_class_label = QtWidgets.QLabel("Class:") + plugin_class_widget = QtWidgets.QLabel(content_widget) + + plugin_path_label = QtWidgets.QLabel("File Path:") + plugin_path_widget = ElideLabel(content_widget) + plugin_path_widget.set_elide_mode(QtCore.Qt.ElideLeft) + + # Set interaction flags + for label_widget in ( + plugin_label_widget, + plugin_families_widget, + plugin_order_widget, + plugin_class_widget, + plugin_doc_widget, + ): + label_widget.setTextInteractionFlags( + QtCore.Qt.TextBrowserInteraction + ) + + # Change style of form labels for label_widget in ( - plugin_path_label, plugin_families_label, + plugin_order_label, + plugin_class_label, + plugin_path_label, ): label_widget.setObjectName("PluginFormLabel") - plugin_doc_widget = QtWidgets.QLabel(content_widget) - plugin_doc_widget.setWordWrap(True) - plugin_doc_widget.setTextInteractionFlags( - QtCore.Qt.TextBrowserInteraction - ) - plugin_label = plugin_item.label or plugin_item.name if plugin_item.plugin_type: plugin_label += " ({})".format( plugin_item.plugin_type.capitalize() ) plugin_label_widget.setText(plugin_label) - # plugin_type_widget.setText(plugin_item.plugin_type or "N/A") + plugin_doc_widget.setText(plugin_item.docstring or "N/A") + plugin_families_widget.setText(str(plugin_item.families or "N/A")) + plugin_order_widget.setText(str(plugin_item.order or "N/A")) + plugin_class_widget.setText(plugin_item.name or "N/A") plugin_path_widget.setText(plugin_item.filepath or "N/A") + # Show full path in tooltip plugin_path_widget.setToolTip(plugin_item.filepath or None) - plugin_families_widget.setText(str(plugin_item.families or "N/A")) - plugin_doc_widget.setText(plugin_item.docstring or "N/A") - - row = 0 content_layout = QtWidgets.QGridLayout(content_widget) content_layout.setContentsMargins(8, 8, 8, 8) content_layout.setColumnStretch(0, 0) content_layout.setColumnStretch(1, 1) + row = 0 content_layout.addWidget(plugin_label_widget, row, 0, 1, 2) row += 1 @@ -417,13 +432,18 @@ def __init__(self, plugin_item, parent): else: plugin_doc_widget.setVisible(False) - content_layout.addWidget(plugin_path_label, row, 0) - content_layout.addWidget(plugin_path_widget, row, 1) + content_layout.addWidget(form_separator, row, 0, 1, 2) row += 1 - content_layout.addWidget(plugin_families_label, row, 0) - content_layout.addWidget(plugin_families_widget, row, 1) - row += 1 + for label_widget, value_widget in ( + (plugin_families_label, plugin_families_widget), + (plugin_class_label, plugin_class_widget), + (plugin_order_label, plugin_order_widget), + (plugin_path_label, plugin_path_widget), + ): + content_layout.addWidget(label_widget, row, 0) + content_layout.addWidget(value_widget, row, 1) + row += 1 main_layout = QtWidgets.QVBoxLayout(self) main_layout.setContentsMargins(0, 0, 0, 0) From 3bda6370e3049a163b8f642d45d4e71e32b0b51f Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:34:29 +0200 Subject: [PATCH 014/106] added spacing to widgets --- .../ayon_core/tools/publisher/publish_report_viewer/widgets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index a403bd06fc..de24e1f653 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -465,6 +465,7 @@ def __init__(self, parent): content_layout = QtWidgets.QVBoxLayout(content_widget) content_layout.setContentsMargins(0, 0, 0, 0) + content_layout.setSpacing(10) scroll_content_layout = QtWidgets.QVBoxLayout(scroll_content_widget) scroll_content_layout.setContentsMargins(0, 0, 0, 0) From 08e0eb03b631dbea795ccc8745a6564ea63ab803 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:34:44 +0200 Subject: [PATCH 015/106] remove bold style from labels --- client/ayon_core/style/style.css | 3 --- 1 file changed, 3 deletions(-) diff --git a/client/ayon_core/style/style.css b/client/ayon_core/style/style.css index c8ba2ba8f2..2e3ea53fb3 100644 --- a/client/ayon_core/style/style.css +++ b/client/ayon_core/style/style.css @@ -1239,9 +1239,6 @@ ValidationArtistMessage QLabel { font-size: 14pt; font-weight: bold; } -#PluginDetailsContent #PluginFormLabel { - font-weight: bold; -} CreateNextPageOverlay { font-size: 32pt; From 3eb960a8568e5366ad685572c9107c653b8fb9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Thu, 8 Aug 2024 18:13:13 +0200 Subject: [PATCH 016/106] :art: use product name for render templates this is fixing issue where product name templates were hardcoded. Old behavior is enabled by default but deprecation warning is issued --- .../ayon_core/pipeline/create/product_name.py | 8 +- .../pipeline/farm/pyblish_functions.py | 276 +++++++++++++----- .../publish/collect_anatomy_instance_data.py | 17 +- client/ayon_core/plugins/publish/integrate.py | 5 + server/settings/tools.py | 8 + 5 files changed, 238 insertions(+), 76 deletions(-) diff --git a/client/ayon_core/pipeline/create/product_name.py b/client/ayon_core/pipeline/create/product_name.py index 8a08bdc36c..597c9f4862 100644 --- a/client/ayon_core/pipeline/create/product_name.py +++ b/client/ayon_core/pipeline/create/product_name.py @@ -1,7 +1,6 @@ import ayon_api - +from ayon_core.lib import StringTemplate, filter_profiles, prepare_template_data from ayon_core.settings import get_project_settings -from ayon_core.lib import filter_profiles, prepare_template_data from .constants import DEFAULT_PRODUCT_TEMPLATE @@ -183,7 +182,10 @@ def get_product_name( fill_pairs[key] = value try: - return template.format(**prepare_template_data(fill_pairs)) + return StringTemplate.format_template( + template=template, + data=prepare_template_data(fill_pairs) + ) except KeyError as exp: raise TemplateFillError( "Value for {} key is missing in template '{}'." diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index 72deee185e..fc769a06bb 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -1,5 +1,5 @@ -import os import copy +import os import re import warnings from copy import deepcopy @@ -7,14 +7,11 @@ import attr import ayon_api import clique - -from ayon_core.pipeline import ( - get_current_project_name, - get_representation_path, -) from ayon_core.lib import Logger -from ayon_core.pipeline.publish import KnownPublishError +from ayon_core.pipeline import get_current_project_name, get_representation_path +from ayon_core.pipeline.create import get_product_name from ayon_core.pipeline.farm.patterning import match_aov_pattern +from ayon_core.pipeline.publish import KnownPublishError @attr.s @@ -250,6 +247,9 @@ def create_skeleton_instance( "colorspace": data.get("colorspace") } + if data.get("renderlayer"): + instance_skeleton_data["renderlayer"] = data["renderlayer"] + # skip locking version if we are creating v01 instance_version = data.get("version") # take this if exists if instance_version != 1: @@ -464,7 +464,9 @@ def create_instances_for_aov(instance, skeleton, aov_filter, Args: instance (pyblish.api.Instance): Original instance. skeleton (dict): Skeleton instance data. + aov_filter (dict): AOV filter. skip_integration_repre_list (list): skip + do_not_add_review (bool): Explicitly disable reviews Returns: list of pyblish.api.Instance: Instances created from @@ -515,6 +517,113 @@ def create_instances_for_aov(instance, skeleton, aov_filter, ) +def _get_legacy_product_name_and_group( + product_type, + source_product_name, + task_name, + dynamic_data): + """Get product name with legacy logic. + + This function holds legacy behaviour of creating product name + that is deprecated. This wasn't using product name templates + at all, only hardcoded values. It shouldn't be used anymore, + but transition to templates need careful checking of the project + and studio settings. + + Deprecated: + since 0.4.4 + + Args: + product_type (str): Product type. + source_product_name (str): Source product name. + task_name (str): Task name. + dynamic_data (dict): Dynamic data (camera, aov, ...) + + Returns: + tuple: product name and group name + + """ + warnings.warn("Using legacy product name for renders", + DeprecationWarning) + + if not source_product_name.startswith(product_type): + resulting_group_name = '{}{}{}{}{}'.format( + product_type, + task_name[0].upper(), task_name[1:], + source_product_name[0].upper(), source_product_name[1:]) + else: + resulting_group_name = source_product_name + + # create product name `` + if not source_product_name.startswith(product_type): + resulting_group_name = '{}{}{}{}{}'.format( + product_type, + task_name[0].upper(), task_name[1:], + source_product_name[0].upper(), source_product_name[1:]) + else: + resulting_group_name = source_product_name + + resulting_product_name = '{}'.format(resulting_group_name) + camera = dynamic_data.get("camera") + aov = dynamic_data.get("aov") + if camera: + if not aov: + resulting_product_name = '{}_{}'.format( + resulting_group_name, camera) + elif not aov.startswith(camera): + resulting_product_name = '{}_{}_{}'.format( + resulting_group_name, camera, aov) + else: + resulting_product_name = "{}_{}".format( + resulting_group_name, aov) + else: + if aov: + resulting_product_name = '{}_{}'.format( + resulting_group_name, aov) + + return resulting_product_name, resulting_group_name + + +def _get_product_name_and_group_from_template( + task_entity, + project_name, + host_name, + product_type, + variant, + project_settings, + dynamic_data=None): + """Get product name and group name from template. + + This will get product name and group name from template based on + data provided. It is doing similar work as + `func::_get_legacy_product_name_and_group` but using templates. + + Args: + task_entity (dict): Task entity. + project_name (str): Project name. + host_name (str): Host name. + product_type (str): Product type. + variant (str): Variant. + project_settings (dict): Project settings. + dynamic_data (dict): Dynamic data (aov, renderlayer, camera, ...). + + Returns: + tuple: product name and group name. + + """ + resulting_product_name = get_product_name( + project_name=project_name, + task_name=task_entity["taskName"], + task_type=task_entity["taskType"], + host_name=host_name, + product_type=product_type, + dynamic_data=dynamic_data, + variant=variant, + project_settings=project_settings, + ) + return resulting_product_name, "" + + def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, skip_integration_repre_list, do_not_add_review): """Create instance for each AOV found. @@ -526,10 +635,10 @@ def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, instance (pyblish.api.Instance): Original instance. skeleton (dict): Skeleton data for instance (those needed) later by collector. - additional_data (dict): .. + additional_data (dict): ... skip_integration_repre_list (list): list of extensions that shouldn't be published - do_not_addbe _review (bool): explicitly disable review + do_not_add_review (bool): explicitly disable review Returns: @@ -539,68 +648,69 @@ def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, ValueError: """ - # TODO: this needs to be taking the task from context or instance - task = os.environ["AYON_TASK_NAME"] anatomy = instance.context.data["anatomy"] - s_product_name = skeleton["productName"] + source_product_name = skeleton["productName"] cameras = instance.data.get("cameras", []) - exp_files = instance.data["expectedFiles"] + expected_files = instance.data["expectedFiles"] log = Logger.get_logger("farm_publishing") instances = [] # go through AOVs in expected files - for aov, files in exp_files[0].items(): - cols, rem = clique.assemble(files) - # we shouldn't have any reminders. And if we do, it should - # be just one item for single frame renders. - if not cols and rem: - if len(rem) != 1: - raise ValueError("Found multiple non related files " - "to render, don't know what to do " - "with them.") - col = rem[0] - ext = os.path.splitext(col)[1].lstrip(".") - else: - # but we really expect only one collection. - # Nothing else make sense. - if len(cols) != 1: - raise ValueError("Only one image sequence type is expected.") # noqa: E501 - ext = cols[0].tail.lstrip(".") - col = list(cols[0]) + for aov, files in expected_files[0].items(): + collected_files = _collect_expected_files_for_aov(files) - # create product name `` - # TODO refactor/remove me - product_type = skeleton["productType"] - if not s_product_name.startswith(product_type): - group_name = '{}{}{}{}{}'.format( - product_type, - task[0].upper(), task[1:], - s_product_name[0].upper(), s_product_name[1:]) - else: - group_name = s_product_name - - # if there are multiple cameras, we need to add camera name - expected_filepath = col[0] if isinstance(col, (list, tuple)) else col - cams = [cam for cam in cameras if cam in expected_filepath] - if cams: - for cam in cams: - if not aov: - product_name = '{}_{}'.format(group_name, cam) - elif not aov.startswith(cam): - product_name = '{}_{}_{}'.format(group_name, cam, aov) - else: - product_name = "{}_{}".format(group_name, aov) - else: - if aov: - product_name = '{}_{}'.format(group_name, aov) - else: - product_name = '{}'.format(group_name) + expected_filepath = collected_files[0] \ + if isinstance(collected_files, (list, tuple)) else collected_files + + dynamic_data = { + "aov": aov, + "renderlayer": instance.data.get("renderlayer"), + } + + # find if camera is used in the file path + # TODO: this must be changed to be more robust. Any coincidence + # of camera name in the file path will be considered as + # camera name. This is not correct. + camera = [cam for cam in cameras if cam in expected_filepath] + + # Is there just one camera matching? + # TODO: this is not true, we can have multiple cameras in the scene + # and we should be able to detect them all. Currently, we are + # keeping the old behavior, taking the first one found. + if camera: + dynamic_data["camera"] = camera[0] + + project_settings = instance.context.data.get("project_settings") + + use_legacy_product_name = True + try: + use_legacy_product_name = project_settings["core"]["tools"]["creator"]["product_name_profiles"]["use_legacy_for_renders"] # noqa: E501 + except KeyError: + warnings.warn( + ("use_legacy_for_renders not found in project settings. " + "Using legacy product name for renders. Please update " + "your ayon-core version."), DeprecationWarning) + use_legacy_product_name = True + + if use_legacy_product_name: + product_name, group_name = _get_legacy_product_name_and_group( + product_type=skeleton["productType"], + source_product_name=source_product_name, + task_name=instance.data["task"], + dynamic_data=dynamic_data) - if isinstance(col, (list, tuple)): - staging = os.path.dirname(col[0]) else: - staging = os.path.dirname(col) + product_name, group_name = _get_product_name_and_group_from_template( + task_entity=instance.data["taskEntity"], + project_name=instance.context.data["projectName"], + host_name=instance.context.data["hostName"], + product_type=skeleton["productType"], + variant=instance.data.get('variant', ''), + project_settings=project_settings + ) + + staging = os.path.dirname(expected_filepath) try: staging = remap_source(staging, anatomy) @@ -611,10 +721,8 @@ def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, app = os.environ.get("AYON_HOST_NAME", "") - if isinstance(col, list): - render_file_name = os.path.basename(col[0]) - else: - render_file_name = os.path.basename(col) + render_file_name = os.path.basename(expected_filepath) + aov_patterns = aov_filter preview = match_aov_pattern(app, aov_patterns, render_file_name) @@ -622,9 +730,10 @@ def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, new_instance = deepcopy(skeleton) new_instance["productName"] = product_name new_instance["productGroup"] = group_name + new_instance["aov"] = aov # toggle preview on if multipart is on - # Because we cant query the multipartExr data member of each AOV we'll + # Because we can't query the multipartExr data member of each AOV we'll # need to have hardcoded rule of excluding any renders with # "cryptomatte" in the file name from being a multipart EXR. This issue # happens with Redshift that forces Cryptomatte renders to be separate @@ -650,10 +759,7 @@ def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, new_instance["review"] = True # create representation - if isinstance(col, (list, tuple)): - files = [os.path.basename(f) for f in col] - else: - files = os.path.basename(col) + ext = os.path.splitext(render_file_name)[-1].lstrip(".") # Copy render product "colorspace" data to representation. colorspace = "" @@ -708,6 +814,36 @@ def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, return instances +def _collect_expected_files_for_aov(files): + """Collect expected files. + + Args: + files (list): List of files. + + Returns: + list or str: Collection of files or single file. + + Raises: + ValueError: If there are multiple collections. + + """ + cols, rem = clique.assemble(files) + # we shouldn't have any reminders. And if we do, it should + # be just one item for single frame renders. + if not cols and rem: + if len(rem) != 1: + raise ValueError("Found multiple non related files " + "to render, don't know what to do " + "with them.") + return rem[0] + else: + # but we really expect only one collection. + # Nothing else make sense. + if len(cols) != 1: + raise ValueError("Only one image sequence type is expected.") # noqa: E501 + return list(cols[0]) + + def get_resources(project_name, version_entity, extension=None): """Get the files from the specific version. diff --git a/client/ayon_core/plugins/publish/collect_anatomy_instance_data.py b/client/ayon_core/plugins/publish/collect_anatomy_instance_data.py index b6636696c1..c83906d7f1 100644 --- a/client/ayon_core/plugins/publish/collect_anatomy_instance_data.py +++ b/client/ayon_core/plugins/publish/collect_anatomy_instance_data.py @@ -138,7 +138,7 @@ def fill_missing_task_entities(self, context, project_name): folder_path_by_id = {} for instance in context: folder_entity = instance.data.get("folderEntity") - # Skip if instnace does not have filled folder entity + # Skip if instance does not have filled folder entity if not folder_entity: continue folder_id = folder_entity["id"] @@ -385,8 +385,19 @@ def fill_anatomy_data(self, context): json.dumps(anatomy_data, indent=4) )) + # make render layer available in anatomy data + render_layer = instance.data.get("renderLayer") + if render_layer: + anatomy_data["renderLayer"] = render_layer + + # make aov name available in anatomy data + aov = instance.data.get("aov") + if aov: + anatomy_data["aov"] = aov + + def _fill_folder_data(self, instance, project_entity, anatomy_data): - # QUESTION should we make sure that all folder data are poped if + # QUESTION: should we make sure that all folder data are popped if # folder data cannot be found? # - 'folder', 'hierarchy', 'parent', 'folder' folder_entity = instance.data.get("folderEntity") @@ -426,7 +437,7 @@ def _fill_folder_data(self, instance, project_entity, anatomy_data): }) def _fill_task_data(self, instance, task_types_by_name, anatomy_data): - # QUESTION should we make sure that all task data are poped if task + # QUESTION: should we make sure that all task data are popped if task # data cannot be resolved? # - 'task' diff --git a/client/ayon_core/plugins/publish/integrate.py b/client/ayon_core/plugins/publish/integrate.py index 69c14465eb..d3f6c04333 100644 --- a/client/ayon_core/plugins/publish/integrate.py +++ b/client/ayon_core/plugins/publish/integrate.py @@ -744,6 +744,11 @@ def prepare_representation( if not is_udim: repre_context["frame"] = first_index_padded + # store renderlayer in context if it exists + # to be later used for example by delivery templates + if instance.data.get("renderlayer"): + repre_context["renderlayer"] = instance.data["renderlayer"] + # Update the destination indexes and padding dst_collection = clique.assemble(dst_filepaths)[0][0] dst_collection.padding = destination_padding diff --git a/server/settings/tools.py b/server/settings/tools.py index 85a66f6a70..3b2c140b3a 100644 --- a/server/settings/tools.py +++ b/server/settings/tools.py @@ -22,6 +22,14 @@ def normalize_value(cls, value): class ProductNameProfile(BaseSettingsModel): _layout = "expanded" + # TODO: change to False in next releases + use_legacy_for_renders: bool = SettingsField( + True, title="Use legacy for renders", + description="Use product naming logic for renders. " + "This is for backwards compatibility enabled by default." + "When enabled, it will ignore any templates for renders " + "that are set in the product name profiles.") + product_types: list[str] = SettingsField( default_factory=list, title="Product types" ) From 551d4f2b7065c3c13467aff3ab749e7a9632dc8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Thu, 8 Aug 2024 18:13:47 +0200 Subject: [PATCH 017/106] :fire: remove old python interface file --- .../pipeline/farm/pyblish_functions.pyi | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 client/ayon_core/pipeline/farm/pyblish_functions.pyi diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.pyi b/client/ayon_core/pipeline/farm/pyblish_functions.pyi deleted file mode 100644 index fe0ae57da0..0000000000 --- a/client/ayon_core/pipeline/farm/pyblish_functions.pyi +++ /dev/null @@ -1,24 +0,0 @@ -import pyblish.api -from ayon_core.pipeline import Anatomy -from typing import Tuple, List - - -class TimeData: - start: int - end: int - fps: float | int - step: int - handle_start: int - handle_end: int - - def __init__(self, start: int, end: int, fps: float | int, step: int, handle_start: int, handle_end: int): - ... - ... - -def remap_source(source: str, anatomy: Anatomy): ... -def extend_frames(folder_path: str, product_name: str, start: int, end: int) -> Tuple[int, int]: ... -def get_time_data_from_instance_or_context(instance: pyblish.api.Instance) -> TimeData: ... -def get_transferable_representations(instance: pyblish.api.Instance) -> list: ... -def create_skeleton_instance(instance: pyblish.api.Instance, families_transfer: list = ..., instance_transfer: dict = ...) -> dict: ... -def create_instances_for_aov(instance: pyblish.api.Instance, skeleton: dict, aov_filter: dict) -> List[pyblish.api.Instance]: ... -def attach_instances_to_product(attach_to: list, instances: list) -> list: ... From c50badd51df6dac2987c46111900f7b07d620b70 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 8 Aug 2024 18:34:18 +0200 Subject: [PATCH 018/106] added process time --- .../publish_report_viewer/report_items.py | 3 ++ .../publish_report_viewer/widgets.py | 51 ++++++++++++++----- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/report_items.py b/client/ayon_core/tools/publisher/publish_report_viewer/report_items.py index cfc2fbfd67..a3c5a7a2fd 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/report_items.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/report_items.py @@ -20,7 +20,9 @@ def __init__(self, plugin_data): self.families = plugin_data.get("families") errored = False + process_time = 0.0 for instance_data in plugin_data["instances_data"]: + process_time += instance_data["process_time"] for log_item in instance_data["logs"]: errored = log_item["type"] == "error" if errored: @@ -28,6 +30,7 @@ def __init__(self, plugin_data): if errored: break + self.process_time = process_time self.errored = errored @property diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index de24e1f653..c58fae5c87 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -22,6 +22,21 @@ IS_DETAIL_ITEM_ROLE = QtCore.Qt.UserRole + 3 +def get_pretty_milliseconds(value): + if value < 1000: + return f"{value:.3f}ms" + value /= 1000 + if value < 60: + return f"{value:.2f}s" + seconds = int(value % 60) + value /= 60 + if value < 60: + return f"{value:.2f}m {seconds:.2f}s" + minutes = int(value % 60) + value /= 60 + return f"{value:.2f}h {minutes:.2f}m" + + class PluginLoadReportModel(QtGui.QStandardItemModel): def __init__(self): super().__init__() @@ -367,27 +382,31 @@ def __init__(self, plugin_item, parent): form_separator = SeparatorWidget(parent=content_widget) - plugin_families_label = QtWidgets.QLabel("Families:") - plugin_families_widget = QtWidgets.QLabel(content_widget) - plugin_families_widget.setWordWrap(True) + plugin_class_label = QtWidgets.QLabel("Class:") + plugin_class_widget = QtWidgets.QLabel(content_widget) plugin_order_label = QtWidgets.QLabel("Order:") plugin_order_widget = QtWidgets.QLabel(content_widget) - plugin_class_label = QtWidgets.QLabel("Class:") - plugin_class_widget = QtWidgets.QLabel(content_widget) + plugin_families_label = QtWidgets.QLabel("Families:") + plugin_families_widget = QtWidgets.QLabel(content_widget) + plugin_families_widget.setWordWrap(True) plugin_path_label = QtWidgets.QLabel("File Path:") plugin_path_widget = ElideLabel(content_widget) plugin_path_widget.set_elide_mode(QtCore.Qt.ElideLeft) + plugin_time_label = QtWidgets.QLabel("Time:") + plugin_time_widget = QtWidgets.QLabel(content_widget) + # Set interaction flags for label_widget in ( plugin_label_widget, - plugin_families_widget, - plugin_order_widget, - plugin_class_widget, plugin_doc_widget, + plugin_class_widget, + plugin_order_widget, + plugin_families_widget, + plugin_time_widget, ): label_widget.setTextInteractionFlags( QtCore.Qt.TextBrowserInteraction @@ -395,10 +414,11 @@ def __init__(self, plugin_item, parent): # Change style of form labels for label_widget in ( - plugin_families_label, - plugin_order_label, plugin_class_label, + plugin_order_label, + plugin_families_label, plugin_path_label, + plugin_time_label, ): label_widget.setObjectName("PluginFormLabel") @@ -409,12 +429,14 @@ def __init__(self, plugin_item, parent): ) plugin_label_widget.setText(plugin_label) plugin_doc_widget.setText(plugin_item.docstring or "N/A") - plugin_families_widget.setText(str(plugin_item.families or "N/A")) - plugin_order_widget.setText(str(plugin_item.order or "N/A")) plugin_class_widget.setText(plugin_item.name or "N/A") + plugin_order_widget.setText(str(plugin_item.order or "N/A")) + plugin_families_widget.setText(str(plugin_item.families or "N/A")) plugin_path_widget.setText(plugin_item.filepath or "N/A") - # Show full path in tooltip plugin_path_widget.setToolTip(plugin_item.filepath or None) + plugin_time_widget.setText( + get_pretty_milliseconds(plugin_item.process_time) + ) content_layout = QtWidgets.QGridLayout(content_widget) content_layout.setContentsMargins(8, 8, 8, 8) @@ -436,10 +458,11 @@ def __init__(self, plugin_item, parent): row += 1 for label_widget, value_widget in ( - (plugin_families_label, plugin_families_widget), (plugin_class_label, plugin_class_widget), (plugin_order_label, plugin_order_widget), + (plugin_families_label, plugin_families_widget), (plugin_path_label, plugin_path_widget), + (plugin_time_label, plugin_time_widget), ): content_layout.addWidget(label_widget, row, 0) content_layout.addWidget(value_widget, row, 1) From 6608a18bb0c8e83acd43eb577d31357a694f8a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Thu, 8 Aug 2024 18:38:56 +0200 Subject: [PATCH 019/106] :recycle: make function public --- client/ayon_core/pipeline/farm/pyblish_functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index fc769a06bb..4825818980 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -584,7 +584,7 @@ def _get_legacy_product_name_and_group( return resulting_product_name, resulting_group_name -def _get_product_name_and_group_from_template( +def get_product_name_and_group_from_template( task_entity, project_name, host_name, @@ -701,7 +701,7 @@ def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, dynamic_data=dynamic_data) else: - product_name, group_name = _get_product_name_and_group_from_template( + product_name, group_name = get_product_name_and_group_from_template( task_entity=instance.data["taskEntity"], project_name=instance.context.data["projectName"], host_name=instance.context.data["hostName"], From 6acff9e04653930eeb51d83d20af28b8c5746460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Thu, 8 Aug 2024 19:00:33 +0200 Subject: [PATCH 020/106] :recycle: first shot at group name also removing need for project settings --- client/ayon_core/pipeline/farm/pyblish_functions.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index 4825818980..5a00f8e973 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -590,7 +590,6 @@ def get_product_name_and_group_from_template( host_name, product_type, variant, - project_settings, dynamic_data=None): """Get product name and group name from template. @@ -604,7 +603,6 @@ def get_product_name_and_group_from_template( host_name (str): Host name. product_type (str): Product type. variant (str): Variant. - project_settings (dict): Project settings. dynamic_data (dict): Dynamic data (aov, renderlayer, camera, ...). Returns: @@ -619,9 +617,8 @@ def get_product_name_and_group_from_template( product_type=product_type, dynamic_data=dynamic_data, variant=variant, - project_settings=project_settings, ) - return resulting_product_name, "" + return resulting_product_name, f"{product_type}{variant}" def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, @@ -706,8 +703,7 @@ def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, project_name=instance.context.data["projectName"], host_name=instance.context.data["hostName"], product_type=skeleton["productType"], - variant=instance.data.get('variant', ''), - project_settings=project_settings + variant=instance.data.get('variant', source_product_name), ) staging = os.path.dirname(expected_filepath) From 07f697d5a4dea4618fc480cdbe76f37a96ed5396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 9 Aug 2024 10:43:05 +0200 Subject: [PATCH 021/106] :recycle: derive group name from templates too --- .../pipeline/farm/pyblish_functions.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index 5a00f8e973..0cc3cef879 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -597,6 +597,13 @@ def get_product_name_and_group_from_template( data provided. It is doing similar work as `func::_get_legacy_product_name_and_group` but using templates. + To get group name, template is called without any dynamic data, so + (depending on the template itself) it should be product name without + aov. + + Todo: + Maybe we should introduce templates for the groups themselves. + Args: task_entity (dict): Task entity. project_name (str): Project name. @@ -609,6 +616,16 @@ def get_product_name_and_group_from_template( tuple: product name and group name. """ + + resulting_group_name = get_product_name( + project_name=project_name, + task_name=task_entity["taskName"], + task_type=task_entity["taskType"], + host_name=host_name, + product_type=product_type, + variant=variant, + ) + resulting_product_name = get_product_name( project_name=project_name, task_name=task_entity["taskName"], @@ -618,7 +635,7 @@ def get_product_name_and_group_from_template( dynamic_data=dynamic_data, variant=variant, ) - return resulting_product_name, f"{product_type}{variant}" + return resulting_product_name, resulting_group_name def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, From a394556103dfd6f300e0f1998286fb1d0dfc4f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 9 Aug 2024 13:17:20 +0200 Subject: [PATCH 022/106] :bug: fix task name reference --- client/ayon_core/pipeline/farm/pyblish_functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index 0cc3cef879..54ee081c9f 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -619,7 +619,7 @@ def get_product_name_and_group_from_template( resulting_group_name = get_product_name( project_name=project_name, - task_name=task_entity["taskName"], + task_name=task_entity["name"], task_type=task_entity["taskType"], host_name=host_name, product_type=product_type, @@ -628,7 +628,7 @@ def get_product_name_and_group_from_template( resulting_product_name = get_product_name( project_name=project_name, - task_name=task_entity["taskName"], + task_name=task_entity["name"], task_type=task_entity["taskType"], host_name=host_name, product_type=product_type, From c63d2005cf5cad0941b0097c2c5c00e816ba3f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 9 Aug 2024 13:18:16 +0200 Subject: [PATCH 023/106] :recycle: move the setting one level up --- .../ayon_core/pipeline/farm/pyblish_functions.py | 2 +- server/settings/tools.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index 54ee081c9f..aa30aefbd0 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -699,7 +699,7 @@ def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, use_legacy_product_name = True try: - use_legacy_product_name = project_settings["core"]["tools"]["creator"]["product_name_profiles"]["use_legacy_for_renders"] # noqa: E501 + use_legacy_product_name = project_settings["core"]["tools"]["creator"]["use_legacy_product_names_for_renders"] # noqa: E501 except KeyError: warnings.warn( ("use_legacy_for_renders not found in project settings. " diff --git a/server/settings/tools.py b/server/settings/tools.py index 3b2c140b3a..5e9c8e14a0 100644 --- a/server/settings/tools.py +++ b/server/settings/tools.py @@ -22,13 +22,6 @@ def normalize_value(cls, value): class ProductNameProfile(BaseSettingsModel): _layout = "expanded" - # TODO: change to False in next releases - use_legacy_for_renders: bool = SettingsField( - True, title="Use legacy for renders", - description="Use product naming logic for renders. " - "This is for backwards compatibility enabled by default." - "When enabled, it will ignore any templates for renders " - "that are set in the product name profiles.") product_types: list[str] = SettingsField( default_factory=list, title="Product types" @@ -73,6 +66,14 @@ class CreatorToolModel(BaseSettingsModel): title="Create Smart Select" ) ) + # TODO: change to False in next releases + use_legacy_product_names_for_renders: bool = SettingsField( + True, title="Use legacy product names for renders", + description="Use product naming templates for renders. " + "This is for backwards compatibility enabled by default." + "When enabled, it will ignore any templates for renders " + "that are set in the product name profiles.") + product_name_profiles: list[ProductNameProfile] = SettingsField( default_factory=list, title="Product name profiles" From 3350b91cf934aceb0558423e5b7707fd50934315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 9 Aug 2024 13:27:34 +0200 Subject: [PATCH 024/106] :bug: fix letter-case typo --- .../plugins/publish/collect_anatomy_instance_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/plugins/publish/collect_anatomy_instance_data.py b/client/ayon_core/plugins/publish/collect_anatomy_instance_data.py index c83906d7f1..5b750a5232 100644 --- a/client/ayon_core/plugins/publish/collect_anatomy_instance_data.py +++ b/client/ayon_core/plugins/publish/collect_anatomy_instance_data.py @@ -386,9 +386,9 @@ def fill_anatomy_data(self, context): )) # make render layer available in anatomy data - render_layer = instance.data.get("renderLayer") + render_layer = instance.data.get("renderlayer") if render_layer: - anatomy_data["renderLayer"] = render_layer + anatomy_data["renderlayer"] = render_layer # make aov name available in anatomy data aov = instance.data.get("aov") From eddba580ef29cbe1525a4c1579571afb925bb400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Fri, 9 Aug 2024 14:17:20 +0200 Subject: [PATCH 025/106] :recycle: explicitly remove `aov` key for group name this solution is a little hack. proper one would be probably introducing product group name templates as mentioned in the code comment --- client/ayon_core/pipeline/farm/pyblish_functions.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index aa30aefbd0..91e155469d 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -616,13 +616,18 @@ def get_product_name_and_group_from_template( tuple: product name and group name. """ - + # remove 'aov' from data used to format group. See todo comment above + # for possible solution. + _dynamic_data = deepcopy(dynamic_data) or {} + if _dynamic_data["aov"]: + del _dynamic_data["aov"] resulting_group_name = get_product_name( project_name=project_name, task_name=task_entity["name"], task_type=task_entity["taskType"], host_name=host_name, product_type=product_type, + dynamic_data=_dynamic_data, variant=variant, ) @@ -721,6 +726,7 @@ def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, host_name=instance.context.data["hostName"], product_type=skeleton["productType"], variant=instance.data.get('variant', source_product_name), + dynamic_data=dynamic_data ) staging = os.path.dirname(expected_filepath) From 9ff4ec856b0ce9f78fe15bedabbca731b36fd837 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:00:10 +0200 Subject: [PATCH 026/106] introduced new function to get launcher storage and local dir --- client/ayon_core/lib/__init__.py | 4 +++ client/ayon_core/lib/local_settings.py | 49 ++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/client/ayon_core/lib/__init__.py b/client/ayon_core/lib/__init__.py index 12c391d867..d4b161031e 100644 --- a/client/ayon_core/lib/__init__.py +++ b/client/ayon_core/lib/__init__.py @@ -9,6 +9,8 @@ AYONSettingsRegistry, OpenPypeSecureRegistry, OpenPypeSettingsRegistry, + get_launcher_local_dir, + get_launcher_storage_dir, get_local_site_id, get_ayon_username, get_openpype_username, @@ -144,6 +146,8 @@ "AYONSettingsRegistry", "OpenPypeSecureRegistry", "OpenPypeSettingsRegistry", + "get_launcher_local_dir", + "get_launcher_storage_dir", "get_local_site_id", "get_ayon_username", "get_openpype_username", diff --git a/client/ayon_core/lib/local_settings.py b/client/ayon_core/lib/local_settings.py index 54432265d9..68ec48695f 100644 --- a/client/ayon_core/lib/local_settings.py +++ b/client/ayon_core/lib/local_settings.py @@ -30,6 +30,55 @@ def wrapper(*args, **kwargs): _PLACEHOLDER = object() +def get_launcher_storage_dir(*subdirs: str) -> str: + """Get storage directory for launcher. + + Storage directory is used for storing shims, addons, dependencies, etc. + + It is not recommended, but the location can be shared across + multiple machines. + + Note: + This function should be called at least once on bootstrap. + + Args: + *subdirs (str): Subdirectories relative to storage dir. + + Returns: + str: Path to storage directory. + + """ + storage_dir = os.getenv("AYON_LAUNCHER_STORAGE_DIR") + if not storage_dir: + storage_dir = get_ayon_appdirs() + + return os.path.join(storage_dir, *subdirs) + + +def get_launcher_local_dir(*subdirs: str) -> str: + """Get local directory for launcher. + + Local directory is used for storing machine or user specific data. + + The location is user specific. + + Note: + This function should be called at least once on bootstrap. + + Args: + *subdirs (str): Subdirectories relative to local dir. + + Returns: + str: Path to local directory. + + """ + storage_dir = os.getenv("AYON_LAUNCHER_LOCAL_DIR") + if not storage_dir: + storage_dir = get_ayon_appdirs() + + return os.path.join(storage_dir, *subdirs) + + class AYONSecureRegistry: """Store information using keyring. From 0e95019995d6d5b077a9487692934a2ac5afe34d Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:03:17 +0200 Subject: [PATCH 027/106] use new functions in codebase --- client/ayon_core/addon/base.py | 11 ++++++----- client/ayon_core/lib/local_settings.py | 10 ++-------- client/ayon_core/pipeline/thumbnails.py | 4 ++-- .../tools/publisher/publish_report_viewer/window.py | 10 +++------- client/ayon_core/tools/tray/lib.py | 4 ++-- 5 files changed, 15 insertions(+), 24 deletions(-) diff --git a/client/ayon_core/addon/base.py b/client/ayon_core/addon/base.py index 001ec5d534..0dbbe19942 100644 --- a/client/ayon_core/addon/base.py +++ b/client/ayon_core/addon/base.py @@ -17,7 +17,11 @@ from semver import VersionInfo from ayon_core import AYON_CORE_ROOT -from ayon_core.lib import Logger, is_dev_mode_enabled +from ayon_core.lib import ( + Logger, + is_dev_mode_enabled, + get_launcher_storage_dir, +) from ayon_core.settings import get_studio_settings from .interfaces import ( @@ -327,10 +331,7 @@ def _load_ayon_addons(openpype_modules, modules_key, log): addons_dir = os.environ.get("AYON_ADDONS_DIR") if not addons_dir: - addons_dir = os.path.join( - appdirs.user_data_dir("AYON", "Ynput"), - "addons" - ) + addons_dir = get_launcher_storage_dir("addons") dev_mode_enabled = is_dev_mode_enabled() dev_addons_info = {} diff --git a/client/ayon_core/lib/local_settings.py b/client/ayon_core/lib/local_settings.py index 68ec48695f..a4ffdb8e39 100644 --- a/client/ayon_core/lib/local_settings.py +++ b/client/ayon_core/lib/local_settings.py @@ -519,20 +519,14 @@ def _delete_item(self, name): class AYONSettingsRegistry(JSONSettingRegistry): """Class handling AYON general settings registry. - Attributes: - vendor (str): Name used for path construction. - product (str): Additional name used for path construction. - Args: name (Optional[str]): Name of the registry. """ def __init__(self, name=None): - self.vendor = "Ynput" - self.product = "AYON" if not name: name = "AYON_settings" - path = appdirs.user_data_dir(self.product, self.vendor) + path = get_launcher_storage_dir() super(AYONSettingsRegistry, self).__init__(name, path) @@ -578,7 +572,7 @@ def get_local_site_id(): if site_id: return site_id - site_id_path = get_ayon_appdirs("site_id") + site_id_path = get_launcher_local_dir("site_id") if os.path.exists(site_id_path): with open(site_id_path, "r") as stream: site_id = stream.read() diff --git a/client/ayon_core/pipeline/thumbnails.py b/client/ayon_core/pipeline/thumbnails.py index dbb38615d8..401d95f273 100644 --- a/client/ayon_core/pipeline/thumbnails.py +++ b/client/ayon_core/pipeline/thumbnails.py @@ -4,7 +4,7 @@ import ayon_api -from ayon_core.lib.local_settings import get_ayon_appdirs +from ayon_core.lib.local_settings import get_launcher_local_dir FileInfo = collections.namedtuple( @@ -54,7 +54,7 @@ def get_thumbnails_dir(self): """ if self._thumbnails_dir is None: - self._thumbnails_dir = get_ayon_appdirs("thumbnails") + self._thumbnails_dir = get_launcher_local_dir("thumbnails") return self._thumbnails_dir thumbnails_dir = property(get_thumbnails_dir) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/window.py b/client/ayon_core/tools/publisher/publish_report_viewer/window.py index aedc3b9e31..9d1ed86a2b 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/window.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/window.py @@ -2,11 +2,11 @@ import json import uuid -import appdirs import arrow from qtpy import QtWidgets, QtCore, QtGui from ayon_core import style +from ayon_core.lib import get_launcher_local_dir from ayon_core.resources import get_ayon_icon_filepath from ayon_core.tools import resources from ayon_core.tools.utils import ( @@ -35,12 +35,8 @@ def get_reports_dir(): str: Path to directory where reports are stored. """ - report_dir = os.path.join( - appdirs.user_data_dir("AYON", "Ynput"), - "publish_report_viewer" - ) - if not os.path.exists(report_dir): - os.makedirs(report_dir) + report_dir = get_launcher_local_dir("publish_report_viewer") + os.makedirs(report_dir, exist_ok=True) return report_dir diff --git a/client/ayon_core/tools/tray/lib.py b/client/ayon_core/tools/tray/lib.py index fd84a9bd10..5f92e8a04f 100644 --- a/client/ayon_core/tools/tray/lib.py +++ b/client/ayon_core/tools/tray/lib.py @@ -19,7 +19,7 @@ run_detached_process, get_ayon_username, ) -from ayon_core.lib.local_settings import get_ayon_appdirs +from ayon_core.lib.local_settings import get_launcher_local_dir class TrayState: @@ -146,7 +146,7 @@ def get_tray_storage_dir() -> str: str: Tray storage directory where metadata files are stored. """ - return get_ayon_appdirs("tray") + return get_launcher_local_dir("tray") def _get_tray_info_filepath( From 9d2ff9637fb67ba2e1af479caee9b41d80712d73 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:05:20 +0200 Subject: [PATCH 028/106] marked 'get_ayon_appdirs' as deprecated --- client/ayon_core/lib/local_settings.py | 53 +++++++++++++++++--------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/client/ayon_core/lib/local_settings.py b/client/ayon_core/lib/local_settings.py index a4ffdb8e39..a6814f8b2f 100644 --- a/client/ayon_core/lib/local_settings.py +++ b/client/ayon_core/lib/local_settings.py @@ -3,6 +3,7 @@ import os import json import platform +import warnings from datetime import datetime from abc import ABC, abstractmethod @@ -30,6 +31,38 @@ def wrapper(*args, **kwargs): _PLACEHOLDER = object() +def _get_ayon_appdirs(*args): + return os.path.join( + appdirs.user_data_dir("AYON", "Ynput"), + *args + ) + + +def get_ayon_appdirs(*args): + """Local app data directory of AYON client. + + Deprecated: + Use 'get_launcher_local_dir' or 'get_launcher_storage_dir' based on + use-case. Deprecation added 24/08/09 (0.4.4-dev.1). + + Args: + *args (Iterable[str]): Subdirectories/files in local app data dir. + + Returns: + str: Path to directory/file in local app data dir. + + """ + warnings.warn( + ( + "Function 'get_ayon_appdirs' is deprecated. Should be replaced" + " with 'get_launcher_local_dir' or 'get_launcher_storage_dir'" + " based on use-case." + ), + DeprecationWarning + ) + return _get_ayon_appdirs(*args) + + def get_launcher_storage_dir(*subdirs: str) -> str: """Get storage directory for launcher. @@ -50,7 +83,7 @@ def get_launcher_storage_dir(*subdirs: str) -> str: """ storage_dir = os.getenv("AYON_LAUNCHER_STORAGE_DIR") if not storage_dir: - storage_dir = get_ayon_appdirs() + storage_dir = _get_ayon_appdirs() return os.path.join(storage_dir, *subdirs) @@ -74,7 +107,7 @@ def get_launcher_local_dir(*subdirs: str) -> str: """ storage_dir = os.getenv("AYON_LAUNCHER_LOCAL_DIR") if not storage_dir: - storage_dir = get_ayon_appdirs() + storage_dir = _get_ayon_appdirs() return os.path.join(storage_dir, *subdirs) @@ -546,22 +579,6 @@ def _create_local_site_id(registry=None): return new_id -def get_ayon_appdirs(*args): - """Local app data directory of AYON client. - - Args: - *args (Iterable[str]): Subdirectories/files in local app data dir. - - Returns: - str: Path to directory/file in local app data dir. - """ - - return os.path.join( - appdirs.user_data_dir("AYON", "Ynput"), - *args - ) - - def get_local_site_id(): """Get local site identifier. From f3c9ffac1a5fde32cabe419d12025bb0c1e7165d Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:05:32 +0200 Subject: [PATCH 029/106] removed unused function '_create_local_site_id' --- client/ayon_core/lib/local_settings.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/client/ayon_core/lib/local_settings.py b/client/ayon_core/lib/local_settings.py index a6814f8b2f..256e7bcd28 100644 --- a/client/ayon_core/lib/local_settings.py +++ b/client/ayon_core/lib/local_settings.py @@ -563,22 +563,6 @@ def __init__(self, name=None): super(AYONSettingsRegistry, self).__init__(name, path) -def _create_local_site_id(registry=None): - """Create a local site identifier.""" - from coolname import generate_slug - - if registry is None: - registry = AYONSettingsRegistry() - - new_id = generate_slug(3) - - print("Created local site id \"{}\"".format(new_id)) - - registry.set_item("localId", new_id) - - return new_id - - def get_local_site_id(): """Get local site identifier. From c9a2022d0c87227be96123a3074fedbfd8614baa Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:19:27 +0200 Subject: [PATCH 030/106] remove unused import --- client/ayon_core/addon/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/client/ayon_core/addon/base.py b/client/ayon_core/addon/base.py index 0dbbe19942..383703e2bc 100644 --- a/client/ayon_core/addon/base.py +++ b/client/ayon_core/addon/base.py @@ -12,7 +12,6 @@ from abc import ABC, abstractmethod from typing import Optional -import appdirs import ayon_api from semver import VersionInfo From 6e21bc4779c1ff1124ede43e55088a409bdafddc Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 9 Aug 2024 17:12:07 +0200 Subject: [PATCH 031/106] change popup text to popup icon --- client/ayon_core/resources/images/popout.png | Bin 0 -> 4224 bytes .../publish_report_viewer/widgets.py | 27 ++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 client/ayon_core/resources/images/popout.png diff --git a/client/ayon_core/resources/images/popout.png b/client/ayon_core/resources/images/popout.png new file mode 100644 index 0000000000000000000000000000000000000000..838c29483ec9309603e8bbe6b300f5a780cea681 GIT binary patch literal 4224 zcmeHKdr*_t65lVN1W^G+NK}YQ02M(Vt&kE4qM$*<_Y+YRAwE!|D1riCs?t;mQi2F5 zk5($8f}m6Z1wo_HXe2%>R;ys5XjLEx8e&N9W;%E7zjtmsb7$_{%w*2_owK`Vch5e~ zw|`#P%prqD4g!E7+*vag08nsB0qQ^;dJ-RM0f=umOrJh4e!XzI)4x3(i>A{NdThx)-|@Z=c6s84+@FL-i@k`}Et?Fw;Y6 zUB_NF&!6r#Cvih&S*gFbkHfL@6!yHfYktKGPwVQ)3V&Ol#bssI4)b?Nh85Wqt*Y5B z+?f{sXdTlz+5K76%>ikh_ET4=3MBi-k*wH#drDe2+AbN^=&MbC^mCT&;oJxLVHGDi zpSP~MZ>5kcxbLmvB+Q$pgiR?e>d-VT{cw^MBXw7FP`>VRpnlS6@#$OT+1De}Ou3VG z&4|eUW9$ASZ?@7WoC`A;K0SIkP0Aw*f~*$*}D{LX;Xrx!SxoBc>ij)I>v;Z>!> zmAjYTJawx0XvIFt-x_iM*lvE^fafk#*UlKU;CSuq2d%w>M@sH)v)D2FdQt!TcrEp( zA$_MtwQvMmSe?uD1LsfYJxkMe+{HUF=g(Rm58&=-{1b`CISBwmk8@{CTa;Mv;rF>^ zuRcde)jYY!#r^5O%yK#H893tlfgrma+ri9QtI+Vx8%Cy>hOR&Gp}ze+jUeQMk~0T1v@y`W z&0BVx>+h=>Iu5|sQpuqc&~%b+Fh`5RWSY4l0Q`wkaxF3~^w4Jy2Z+6+nH&I6<)mz+ zBJC29AJIy+~8+QG_3U!)D98|S5(U_2jccNOYGmn0>N) zLYUO7v0Ki9qR{R-CZ?s8z}`b2y<~`h5z>8}$@%8bg|sEQpa6w)-wF|@$yP+3d_-xj z$xdbo6}=|>uceJGA#p_gA>$Q6i@9?3mYk(fG^bnmCsYh0x6y5y+~l^ zt189yaXn+fFH+aXsWxkBe|e&xxDcsJ%FQ=vth_;v1`9gxv{h;eev-6!<`GXwb=ChoxoI(tbl4;X&9yfsU>l=j-HIjn zt}RNRZP5ZDDXz&KBn+X91;0!@2F9J?tCft{m@G71-|+ZV(P60~QtJ+)Lp z8jW<{TndRXJp@>I>Q~A_iLM@_>@~VNF9ND;l?rE5X!=IPIf@~&$wMEzu@p2-NZ}l< zd-5!l;71|na4&tqwNMO;OLQ^}<3TRd#4n&gq`$P-7<-Quzs7jFm8M> z=S0M-tzQZ&qegTpG$d~)V_}yqG$r*l7f+yK?s)1$rvnrS)x3!mXzdYk9-!VQqILOV z%n^H~;uln41C1=j(7wRaBF=3z%q~jzWB?Mem5MFMs-%$#K>+L`HE$;#Q$i;bxCjf>yc&di z5zYaq&sFn2BScqCL>>cAcXBKiSP^HjDG1ajFav+X9dr0GUwz^*zzRBf3PG0o1giQQ zjr<EaB6Cp6O6gaG+9jU*o>*h(4A zvjDvD@E8iv?r0?V44}z0k})`3*GK|zxT29nQoz?oX=xP8qLX=OOfzoIFa`clDZ?4- z<3ew}$5;Xi#A+ee99kENIH93<$EeXZwCRXiH~Pj1U~$m6k!K@B@u3!zQYFH-#2TW_dLXK&%%S^w>ZLzI^AEb7)cH6KTSQ-H~>t&^4x7)G=vi zQwI{P3C`?%L;Alzf_g_kq>dteJqchp*WGB*Na(mvYabb{wB+F}M-}cW$lw%Yp^siJ za@?$IlcUi2;hE>vLc-{<@Qe#;;WV5rUuqwxv@}5vOmz2qDP;^Cj^2&fF3;eEVhDx% zCOpJhAkLDW)s7>n+p&?}{j*nNJ85|y z8oo#p{%>W=dTjrju!$EGw(FGIG1G<8z!prRbyCk+*IFX5ENRGvb%p994Kp=K8Ony26Xl?o2EMtt$OkDOvV} zGKQ;9G-~>+SmgiX@3C74#>$$uh4oC?hvYm%{Uq?vwXs0^h6nfSR!d z7sQeX@+dy8EQ!d4WUlH&Hac+DCHiV&)=aj#X>}w0I zepiq6Xt~z5DPpd3-%%!Kiq;CwsEWn9P_e-wg=$u979eJ4t2S|;`{0iIt2?8gfBu~Q z+}Z16IP7dVqFNfSDY1s~SC_b{PEzulxg!78S!fi4o0{5X4=d%J&V3*6&Forr+B9IB zW?5^aOJ7~N`qqGe>Y8j_m{=k5-)9!y#)FQ}v0}vyg(=AYxHEdyCo-wao_+NI@x$m; zkFMG3x7cZQ@#57t+uCdLT24(q-grdi$Vx7?5wMcS3fp6pje^A{V_3T?Oys_36u4(4h?x7l(9jVkNJ@Csd-FES<$R`!a+~U*5|Dhu6kew{DlX zn3inOw5mTv%(>I%qU&GW81%snI(E3qEIQf#hgI6Uo8Z^p1aYNv-&%2FXm`cg_Nuh0 zW=#!6x7v6EQaxl3K2P29y6YB!)`{!0RJ~suDxLbaiQ_W;hWynpJ>>T-Gz`#k+utXg S%EFcbzzqtUaV9Ww&p!bC9@&Hd literal 0 HcmV?d00001 diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index 61a52533ba..96663a4c4a 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -1,7 +1,13 @@ from math import ceil from qtpy import QtWidgets, QtCore, QtGui -from ayon_core.tools.utils import NiceCheckbox +from ayon_core.tools.utils import ( + NiceCheckbox, + IconButton, + paint_image_with_color, +) +from ayon_core.resources import get_image_path +from ayon_core.style import get_objected_colors # from ayon_core.tools.utils import DeselectableTreeView from .constants import ( @@ -410,12 +416,27 @@ def __init__(self, parent=None): details_widget = QtWidgets.QWidget(self) details_tab_widget = QtWidgets.QTabWidget(details_widget) - details_popup_btn = QtWidgets.QPushButton("PopUp", details_widget) + + btns_widget = QtWidgets.QWidget(details_widget) + + popout_image = QtGui.QImage(get_image_path("popout.png")) + popout_color = get_objected_colors("font") + popout_icon = QtGui.QIcon( + paint_image_with_color(popout_image, popout_color.get_qcolor()) + ) + details_popup_btn = IconButton(btns_widget) + details_popup_btn.setIcon(popout_icon) + details_popup_btn.setToolTip("Pop Out") + + btns_layout = QtWidgets.QHBoxLayout(btns_widget) + btns_layout.setContentsMargins(0, 0, 0, 0) + btns_layout.addStretch(1) + btns_layout.addWidget(details_popup_btn, 0) details_layout = QtWidgets.QVBoxLayout(details_widget) details_layout.setContentsMargins(0, 0, 0, 0) details_layout.addWidget(details_tab_widget, 1) - details_layout.addWidget(details_popup_btn, 0) + details_layout.addWidget(btns_widget, 0) details_popup = DetailsPopup(self, details_tab_widget) From c02f90d5d3a3b99eb602bbff5aefff2ccf78355c Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 9 Aug 2024 17:12:54 +0200 Subject: [PATCH 032/106] change default size of window based on center widget --- .../tools/publisher/publish_report_viewer/widgets.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index 96663a4c4a..24c26baa70 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -343,11 +343,15 @@ def __init__(self, parent, center_widget): def showEvent(self, event): layout = self.layout() + cw_size = self._center_widget.size() layout.insertWidget(0, self._center_widget) - super().showEvent(event) if self._first_show: self._first_show = False - self.resize(700, 400) + self.resize( + max(cw_size.width(), 700), + max(cw_size.height(), 400) + ) + super().showEvent(event) def closeEvent(self, event): super().closeEvent(event) From fe8b57f1d3c98508a55e38e1d4bdfd5423889326 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:08:09 +0200 Subject: [PATCH 033/106] moved exceptions to single file --- client/ayon_core/pipeline/create/__init__.py | 16 ++- client/ayon_core/pipeline/create/context.py | 128 ++---------------- .../pipeline/create/creator_plugins.py | 10 -- .../ayon_core/pipeline/create/exceptions.py | 114 ++++++++++++++++ 4 files changed, 140 insertions(+), 128 deletions(-) create mode 100644 client/ayon_core/pipeline/create/exceptions.py diff --git a/client/ayon_core/pipeline/create/__init__.py b/client/ayon_core/pipeline/create/__init__.py index da9cafad5a..68e173d6b9 100644 --- a/client/ayon_core/pipeline/create/__init__.py +++ b/client/ayon_core/pipeline/create/__init__.py @@ -4,6 +4,20 @@ PRE_CREATE_THUMBNAIL_KEY, DEFAULT_VARIANT_VALUE, ) +from .exceptions import ( + UnavailableSharedData, + ImmutableKeyError, + HostMissRequiredMethod, + ConvertorsOperationFailed, + ConvertorsFindFailed, + ConvertorsConversionFailed, + CreatorError, + CreatorsCreateFailed, + CreatorsCollectionFailed, + CreatorsSaveFailed, + CreatorsRemoveFailed, + CreatorsOperationFailed, +) from .utils import ( get_last_versions_for_instances, @@ -17,8 +31,6 @@ ) from .creator_plugins import ( - CreatorError, - BaseCreator, Creator, AutoCreator, diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index 1c64d22733..0dd8ed1bd1 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -29,12 +29,23 @@ ) from ayon_core.pipeline.plugin_discover import DiscoverResult +from .exceptions import ( + CreatorError, + ImmutableKeyError, + CreatorsCreateFailed, + CreatorsCollectionFailed, + CreatorsSaveFailed, + CreatorsRemoveFailed, + ConvertorsFindFailed, + ConvertorsConversionFailed, + UnavailableSharedData, + HostMissRequiredMethod, +) from .creator_plugins import ( Creator, AutoCreator, discover_creator_plugins, discover_convertor_plugins, - CreatorError, ) # Changes of instances and context are send as tuple of 2 information @@ -42,68 +53,6 @@ _NOT_SET = object() -class UnavailableSharedData(Exception): - """Shared data are not available at the moment when are accessed.""" - pass - - -class ImmutableKeyError(TypeError): - """Accessed key is immutable so does not allow changes or removals.""" - - def __init__(self, key, msg=None): - self.immutable_key = key - if not msg: - msg = "Key \"{}\" is immutable and does not allow changes.".format( - key - ) - super(ImmutableKeyError, self).__init__(msg) - - -class HostMissRequiredMethod(Exception): - """Host does not have implemented required functions for creation.""" - - def __init__(self, host, missing_methods): - self.missing_methods = missing_methods - self.host = host - joined_methods = ", ".join( - ['"{}"'.format(name) for name in missing_methods] - ) - dirpath = os.path.dirname( - os.path.normpath(inspect.getsourcefile(host)) - ) - dirpath_parts = dirpath.split(os.path.sep) - host_name = dirpath_parts.pop(-1) - if host_name == "api": - host_name = dirpath_parts.pop(-1) - - msg = "Host \"{}\" does not have implemented method/s {}".format( - host_name, joined_methods - ) - super(HostMissRequiredMethod, self).__init__(msg) - - -class ConvertorsOperationFailed(Exception): - def __init__(self, msg, failed_info): - super(ConvertorsOperationFailed, self).__init__(msg) - self.failed_info = failed_info - - -class ConvertorsFindFailed(ConvertorsOperationFailed): - def __init__(self, failed_info): - msg = "Failed to find incompatible products" - super(ConvertorsFindFailed, self).__init__( - msg, failed_info - ) - - -class ConvertorsConversionFailed(ConvertorsOperationFailed): - def __init__(self, failed_info): - msg = "Failed to convert incompatible products" - super(ConvertorsConversionFailed, self).__init__( - msg, failed_info - ) - - def prepare_failed_convertor_operation_info(identifier, exc_info): exc_type, exc_value, exc_traceback = exc_info formatted_traceback = "".join(traceback.format_exception( @@ -117,59 +66,6 @@ def prepare_failed_convertor_operation_info(identifier, exc_info): } -class CreatorsOperationFailed(Exception): - """Raised when a creator process crashes in 'CreateContext'. - - The exception contains information about the creator and error. The data - are prepared using 'prepare_failed_creator_operation_info' and can be - serialized using json. - - Usage is for UI purposes which may not have access to exceptions directly - and would not have ability to catch exceptions 'per creator'. - - Args: - msg (str): General error message. - failed_info (list[dict[str, Any]]): List of failed creators with - exception message and optionally formatted traceback. - """ - - def __init__(self, msg, failed_info): - super(CreatorsOperationFailed, self).__init__(msg) - self.failed_info = failed_info - - -class CreatorsCollectionFailed(CreatorsOperationFailed): - def __init__(self, failed_info): - msg = "Failed to collect instances" - super(CreatorsCollectionFailed, self).__init__( - msg, failed_info - ) - - -class CreatorsSaveFailed(CreatorsOperationFailed): - def __init__(self, failed_info): - msg = "Failed update instance changes" - super(CreatorsSaveFailed, self).__init__( - msg, failed_info - ) - - -class CreatorsRemoveFailed(CreatorsOperationFailed): - def __init__(self, failed_info): - msg = "Failed to remove instances" - super(CreatorsRemoveFailed, self).__init__( - msg, failed_info - ) - - -class CreatorsCreateFailed(CreatorsOperationFailed): - def __init__(self, failed_info): - msg = "Failed to create instances" - super(CreatorsCreateFailed, self).__init__( - msg, failed_info - ) - - def prepare_failed_creator_operation_info( identifier, label, exc_info, add_traceback=True ): diff --git a/client/ayon_core/pipeline/create/creator_plugins.py b/client/ayon_core/pipeline/create/creator_plugins.py index 624f1c9588..1e09eb62a1 100644 --- a/client/ayon_core/pipeline/create/creator_plugins.py +++ b/client/ayon_core/pipeline/create/creator_plugins.py @@ -26,16 +26,6 @@ from .context import CreateContext, CreatedInstance, UpdateData # noqa: F401 -class CreatorError(Exception): - """Should be raised when creator failed because of known issue. - - Message of error should be user readable. - """ - - def __init__(self, message): - super(CreatorError, self).__init__(message) - - class ProductConvertorPlugin(ABC): """Helper for conversion of instances created using legacy creators. diff --git a/client/ayon_core/pipeline/create/exceptions.py b/client/ayon_core/pipeline/create/exceptions.py new file mode 100644 index 0000000000..24264840cb --- /dev/null +++ b/client/ayon_core/pipeline/create/exceptions.py @@ -0,0 +1,114 @@ +import os +import inspect + + +class UnavailableSharedData(Exception): + """Shared data are not available at the moment when are accessed.""" + pass + + +class ImmutableKeyError(TypeError): + """Accessed key is immutable so does not allow changes or removals.""" + + def __init__(self, key, msg=None): + self.immutable_key = key + if not msg: + msg = "Key \"{}\" is immutable and does not allow changes.".format( + key + ) + super().__init__(msg) + + +class HostMissRequiredMethod(Exception): + """Host does not have implemented required functions for creation.""" + + def __init__(self, host, missing_methods): + self.missing_methods = missing_methods + self.host = host + joined_methods = ", ".join( + ['"{}"'.format(name) for name in missing_methods] + ) + dirpath = os.path.dirname( + os.path.normpath(inspect.getsourcefile(host)) + ) + dirpath_parts = dirpath.split(os.path.sep) + host_name = dirpath_parts.pop(-1) + if host_name == "api": + host_name = dirpath_parts.pop(-1) + + msg = "Host \"{}\" does not have implemented method/s {}".format( + host_name, joined_methods + ) + super().__init__(msg) + + +class ConvertorsOperationFailed(Exception): + def __init__(self, msg, failed_info): + super().__init__(msg) + self.failed_info = failed_info + + +class ConvertorsFindFailed(ConvertorsOperationFailed): + def __init__(self, failed_info): + msg = "Failed to find incompatible products" + super().__init__(msg, failed_info) + + +class ConvertorsConversionFailed(ConvertorsOperationFailed): + def __init__(self, failed_info): + msg = "Failed to convert incompatible products" + super().__init__(msg, failed_info) + + +class CreatorError(Exception): + """Should be raised when creator failed because of known issue. + + Message of error should be artist friendly. + """ + pass + + +class CreatorsOperationFailed(Exception): + """Raised when a creator process crashes in 'CreateContext'. + + The exception contains information about the creator and error. The data + are prepared using 'prepare_failed_creator_operation_info' and can be + serialized using json. + + Usage is for UI purposes which may not have access to exceptions directly + and would not have ability to catch exceptions 'per creator'. + + Args: + msg (str): General error message. + failed_info (list[dict[str, Any]]): List of failed creators with + exception message and optionally formatted traceback. + """ + + def __init__(self, msg, failed_info): + super().__init__(msg) + self.failed_info = failed_info + + +class CreatorsCollectionFailed(CreatorsOperationFailed): + def __init__(self, failed_info): + msg = "Failed to collect instances" + super().__init__(msg, failed_info) + + +class CreatorsSaveFailed(CreatorsOperationFailed): + def __init__(self, failed_info): + msg = "Failed update instance changes" + super().__init__(msg, failed_info) + + +class CreatorsRemoveFailed(CreatorsOperationFailed): + def __init__(self, failed_info): + msg = "Failed to remove instances" + super().__init__(msg, failed_info) + + +class CreatorsCreateFailed(CreatorsOperationFailed): + def __init__(self, failed_info): + msg = "Failed to create instances" + super().__init__(msg, failed_info) + From 558cc13cdc10942334d5815829792eb078d67c27 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:10:15 +0200 Subject: [PATCH 034/106] move 'TrackChangesItem' to separate file --- client/ayon_core/pipeline/create/changes.py | 313 +++++++++++++++++++ client/ayon_core/pipeline/create/context.py | 314 +------------------- 2 files changed, 314 insertions(+), 313 deletions(-) create mode 100644 client/ayon_core/pipeline/create/changes.py diff --git a/client/ayon_core/pipeline/create/changes.py b/client/ayon_core/pipeline/create/changes.py new file mode 100644 index 0000000000..217478ee30 --- /dev/null +++ b/client/ayon_core/pipeline/create/changes.py @@ -0,0 +1,313 @@ +import copy + +_EMPTY_VALUE = object() + + +class TrackChangesItem(object): + """Helper object to track changes in data. + + Has access to full old and new data and will create deep copy of them, + so it is not needed to create copy before passed in. + + Can work as a dictionary if old or new value is a dictionary. In + that case received object is another object of 'TrackChangesItem'. + + Goal is to be able to get old or new value as was or only changed values + or get information about removed/changed keys, and all of that on + any "dictionary level". + + ``` + # Example of possible usages + >>> old_value = { + ... "key_1": "value_1", + ... "key_2": { + ... "key_sub_1": 1, + ... "key_sub_2": { + ... "enabled": True + ... } + ... }, + ... "key_3": "value_2" + ... } + >>> new_value = { + ... "key_1": "value_1", + ... "key_2": { + ... "key_sub_2": { + ... "enabled": False + ... }, + ... "key_sub_3": 3 + ... }, + ... "key_3": "value_3" + ... } + + >>> changes = TrackChangesItem(old_value, new_value) + >>> changes.changed + True + + >>> changes["key_2"]["key_sub_1"].new_value is None + True + + >>> list(sorted(changes.changed_keys)) + ['key_2', 'key_3'] + + >>> changes["key_2"]["key_sub_2"]["enabled"].changed + True + + >>> changes["key_2"].removed_keys + {'key_sub_1'} + + >>> list(sorted(changes["key_2"].available_keys)) + ['key_sub_1', 'key_sub_2', 'key_sub_3'] + + >>> changes.new_value == new_value + True + + # Get only changed values + only_changed_new_values = { + key: changes[key].new_value + for key in changes.changed_keys + } + ``` + + Args: + old_value (Any): Old value. + new_value (Any): New value. + """ + + def __init__(self, old_value, new_value): + self._changed = old_value != new_value + # Resolve if value is '_EMPTY_VALUE' after comparison of the values + if old_value is _EMPTY_VALUE: + old_value = None + if new_value is _EMPTY_VALUE: + new_value = None + self._old_value = copy.deepcopy(old_value) + self._new_value = copy.deepcopy(new_value) + + self._old_is_dict = isinstance(old_value, dict) + self._new_is_dict = isinstance(new_value, dict) + + self._old_keys = None + self._new_keys = None + self._available_keys = None + self._removed_keys = None + + self._changed_keys = None + + self._sub_items = None + + def __getitem__(self, key): + """Getter looks into subitems if object is dictionary.""" + + if self._sub_items is None: + self._prepare_sub_items() + return self._sub_items[key] + + def __bool__(self): + """Boolean of object is if old and new value are the same.""" + + return self._changed + + def get(self, key, default=None): + """Try to get sub item.""" + + if self._sub_items is None: + self._prepare_sub_items() + return self._sub_items.get(key, default) + + @property + def old_value(self): + """Get copy of old value. + + Returns: + Any: Whatever old value was. + """ + + return copy.deepcopy(self._old_value) + + @property + def new_value(self): + """Get copy of new value. + + Returns: + Any: Whatever new value was. + """ + + return copy.deepcopy(self._new_value) + + @property + def changed(self): + """Value changed. + + Returns: + bool: If data changed. + """ + + return self._changed + + @property + def is_dict(self): + """Object can be used as dictionary. + + Returns: + bool: When can be used that way. + """ + + return self._old_is_dict or self._new_is_dict + + @property + def changes(self): + """Get changes in raw data. + + This method should be used only if 'is_dict' value is 'True'. + + Returns: + Dict[str, Tuple[Any, Any]]: Changes are by key in tuple + (, ). If 'is_dict' is 'False' then + output is always empty dictionary. + """ + + output = {} + if not self.is_dict: + return output + + old_value = self.old_value + new_value = self.new_value + for key in self.changed_keys: + _old = None + _new = None + if self._old_is_dict: + _old = old_value.get(key) + if self._new_is_dict: + _new = new_value.get(key) + output[key] = (_old, _new) + return output + + # Methods/properties that can be used when 'is_dict' is 'True' + @property + def old_keys(self): + """Keys from old value. + + Empty set is returned if old value is not a dict. + + Returns: + Set[str]: Keys from old value. + """ + + if self._old_keys is None: + self._prepare_keys() + return set(self._old_keys) + + @property + def new_keys(self): + """Keys from new value. + + Empty set is returned if old value is not a dict. + + Returns: + Set[str]: Keys from new value. + """ + + if self._new_keys is None: + self._prepare_keys() + return set(self._new_keys) + + @property + def changed_keys(self): + """Keys that has changed from old to new value. + + Empty set is returned if both old and new value are not a dict. + + Returns: + Set[str]: Keys of changed keys. + """ + + if self._changed_keys is None: + self._prepare_sub_items() + return set(self._changed_keys) + + @property + def available_keys(self): + """All keys that are available in old and new value. + + Empty set is returned if both old and new value are not a dict. + Output is Union of 'old_keys' and 'new_keys'. + + Returns: + Set[str]: All keys from old and new value. + """ + + if self._available_keys is None: + self._prepare_keys() + return set(self._available_keys) + + @property + def removed_keys(self): + """Key that are not available in new value but were in old value. + + Returns: + Set[str]: All removed keys. + """ + + if self._removed_keys is None: + self._prepare_sub_items() + return set(self._removed_keys) + + def _prepare_keys(self): + old_keys = set() + new_keys = set() + if self._old_is_dict and self._new_is_dict: + old_keys = set(self._old_value.keys()) + new_keys = set(self._new_value.keys()) + + elif self._old_is_dict: + old_keys = set(self._old_value.keys()) + + elif self._new_is_dict: + new_keys = set(self._new_value.keys()) + + self._old_keys = old_keys + self._new_keys = new_keys + self._available_keys = old_keys | new_keys + self._removed_keys = old_keys - new_keys + + def _prepare_sub_items(self): + sub_items = {} + changed_keys = set() + + old_keys = self.old_keys + new_keys = self.new_keys + new_value = self.new_value + old_value = self.old_value + if self._old_is_dict and self._new_is_dict: + for key in self.available_keys: + item = TrackChangesItem( + old_value.get(key), new_value.get(key) + ) + sub_items[key] = item + if item.changed or key not in old_keys or key not in new_keys: + changed_keys.add(key) + + elif self._old_is_dict: + old_keys = set(old_value.keys()) + available_keys = set(old_keys) + changed_keys = set(available_keys) + for key in available_keys: + # NOTE Use '_EMPTY_VALUE' because old value could be 'None' + # which would result in "unchanged" item + sub_items[key] = TrackChangesItem( + old_value.get(key), _EMPTY_VALUE + ) + + elif self._new_is_dict: + new_keys = set(new_value.keys()) + available_keys = set(new_keys) + changed_keys = set(available_keys) + for key in available_keys: + # NOTE Use '_EMPTY_VALUE' because new value could be 'None' + # which would result in "unchanged" item + sub_items[key] = TrackChangesItem( + _EMPTY_VALUE, new_value.get(key) + ) + + self._sub_items = sub_items + self._changed_keys = changed_keys diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index 0dd8ed1bd1..6f802a5a6e 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -41,6 +41,7 @@ UnavailableSharedData, HostMissRequiredMethod, ) +from .changes import TrackChangesItem from .creator_plugins import ( Creator, AutoCreator, @@ -84,319 +85,6 @@ def prepare_failed_creator_operation_info( } -_EMPTY_VALUE = object() - - -class TrackChangesItem(object): - """Helper object to track changes in data. - - Has access to full old and new data and will create deep copy of them, - so it is not needed to create copy before passed in. - - Can work as a dictionary if old or new value is a dictionary. In - that case received object is another object of 'TrackChangesItem'. - - Goal is to be able to get old or new value as was or only changed values - or get information about removed/changed keys, and all of that on - any "dictionary level". - - ``` - # Example of possible usages - >>> old_value = { - ... "key_1": "value_1", - ... "key_2": { - ... "key_sub_1": 1, - ... "key_sub_2": { - ... "enabled": True - ... } - ... }, - ... "key_3": "value_2" - ... } - >>> new_value = { - ... "key_1": "value_1", - ... "key_2": { - ... "key_sub_2": { - ... "enabled": False - ... }, - ... "key_sub_3": 3 - ... }, - ... "key_3": "value_3" - ... } - - >>> changes = TrackChangesItem(old_value, new_value) - >>> changes.changed - True - - >>> changes["key_2"]["key_sub_1"].new_value is None - True - - >>> list(sorted(changes.changed_keys)) - ['key_2', 'key_3'] - - >>> changes["key_2"]["key_sub_2"]["enabled"].changed - True - - >>> changes["key_2"].removed_keys - {'key_sub_1'} - - >>> list(sorted(changes["key_2"].available_keys)) - ['key_sub_1', 'key_sub_2', 'key_sub_3'] - - >>> changes.new_value == new_value - True - - # Get only changed values - only_changed_new_values = { - key: changes[key].new_value - for key in changes.changed_keys - } - ``` - - Args: - old_value (Any): Old value. - new_value (Any): New value. - """ - - def __init__(self, old_value, new_value): - self._changed = old_value != new_value - # Resolve if value is '_EMPTY_VALUE' after comparison of the values - if old_value is _EMPTY_VALUE: - old_value = None - if new_value is _EMPTY_VALUE: - new_value = None - self._old_value = copy.deepcopy(old_value) - self._new_value = copy.deepcopy(new_value) - - self._old_is_dict = isinstance(old_value, dict) - self._new_is_dict = isinstance(new_value, dict) - - self._old_keys = None - self._new_keys = None - self._available_keys = None - self._removed_keys = None - - self._changed_keys = None - - self._sub_items = None - - def __getitem__(self, key): - """Getter looks into subitems if object is dictionary.""" - - if self._sub_items is None: - self._prepare_sub_items() - return self._sub_items[key] - - def __bool__(self): - """Boolean of object is if old and new value are the same.""" - - return self._changed - - def get(self, key, default=None): - """Try to get sub item.""" - - if self._sub_items is None: - self._prepare_sub_items() - return self._sub_items.get(key, default) - - @property - def old_value(self): - """Get copy of old value. - - Returns: - Any: Whatever old value was. - """ - - return copy.deepcopy(self._old_value) - - @property - def new_value(self): - """Get copy of new value. - - Returns: - Any: Whatever new value was. - """ - - return copy.deepcopy(self._new_value) - - @property - def changed(self): - """Value changed. - - Returns: - bool: If data changed. - """ - - return self._changed - - @property - def is_dict(self): - """Object can be used as dictionary. - - Returns: - bool: When can be used that way. - """ - - return self._old_is_dict or self._new_is_dict - - @property - def changes(self): - """Get changes in raw data. - - This method should be used only if 'is_dict' value is 'True'. - - Returns: - Dict[str, Tuple[Any, Any]]: Changes are by key in tuple - (, ). If 'is_dict' is 'False' then - output is always empty dictionary. - """ - - output = {} - if not self.is_dict: - return output - - old_value = self.old_value - new_value = self.new_value - for key in self.changed_keys: - _old = None - _new = None - if self._old_is_dict: - _old = old_value.get(key) - if self._new_is_dict: - _new = new_value.get(key) - output[key] = (_old, _new) - return output - - # Methods/properties that can be used when 'is_dict' is 'True' - @property - def old_keys(self): - """Keys from old value. - - Empty set is returned if old value is not a dict. - - Returns: - Set[str]: Keys from old value. - """ - - if self._old_keys is None: - self._prepare_keys() - return set(self._old_keys) - - @property - def new_keys(self): - """Keys from new value. - - Empty set is returned if old value is not a dict. - - Returns: - Set[str]: Keys from new value. - """ - - if self._new_keys is None: - self._prepare_keys() - return set(self._new_keys) - - @property - def changed_keys(self): - """Keys that has changed from old to new value. - - Empty set is returned if both old and new value are not a dict. - - Returns: - Set[str]: Keys of changed keys. - """ - - if self._changed_keys is None: - self._prepare_sub_items() - return set(self._changed_keys) - - @property - def available_keys(self): - """All keys that are available in old and new value. - - Empty set is returned if both old and new value are not a dict. - Output is Union of 'old_keys' and 'new_keys'. - - Returns: - Set[str]: All keys from old and new value. - """ - - if self._available_keys is None: - self._prepare_keys() - return set(self._available_keys) - - @property - def removed_keys(self): - """Key that are not available in new value but were in old value. - - Returns: - Set[str]: All removed keys. - """ - - if self._removed_keys is None: - self._prepare_sub_items() - return set(self._removed_keys) - - def _prepare_keys(self): - old_keys = set() - new_keys = set() - if self._old_is_dict and self._new_is_dict: - old_keys = set(self._old_value.keys()) - new_keys = set(self._new_value.keys()) - - elif self._old_is_dict: - old_keys = set(self._old_value.keys()) - - elif self._new_is_dict: - new_keys = set(self._new_value.keys()) - - self._old_keys = old_keys - self._new_keys = new_keys - self._available_keys = old_keys | new_keys - self._removed_keys = old_keys - new_keys - - def _prepare_sub_items(self): - sub_items = {} - changed_keys = set() - - old_keys = self.old_keys - new_keys = self.new_keys - new_value = self.new_value - old_value = self.old_value - if self._old_is_dict and self._new_is_dict: - for key in self.available_keys: - item = TrackChangesItem( - old_value.get(key), new_value.get(key) - ) - sub_items[key] = item - if item.changed or key not in old_keys or key not in new_keys: - changed_keys.add(key) - - elif self._old_is_dict: - old_keys = set(old_value.keys()) - available_keys = set(old_keys) - changed_keys = set(available_keys) - for key in available_keys: - # NOTE Use '_EMPTY_VALUE' because old value could be 'None' - # which would result in "unchanged" item - sub_items[key] = TrackChangesItem( - old_value.get(key), _EMPTY_VALUE - ) - - elif self._new_is_dict: - new_keys = set(new_value.keys()) - available_keys = set(new_keys) - changed_keys = set(available_keys) - for key in available_keys: - # NOTE Use '_EMPTY_VALUE' because new value could be 'None' - # which would result in "unchanged" item - sub_items[key] = TrackChangesItem( - _EMPTY_VALUE, new_value.get(key) - ) - - self._sub_items = sub_items - self._changed_keys = changed_keys - - class InstanceMember: """Representation of instance member. From f41a830f437d000c0f83f44765c6a5e00b25a137 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:17:27 +0200 Subject: [PATCH 035/106] move structure classes to separate file --- client/ayon_core/pipeline/create/__init__.py | 23 +- client/ayon_core/pipeline/create/context.py | 866 +---------------- .../ayon_core/pipeline/create/structures.py | 870 ++++++++++++++++++ 3 files changed, 889 insertions(+), 870 deletions(-) create mode 100644 client/ayon_core/pipeline/create/structures.py diff --git a/client/ayon_core/pipeline/create/__init__.py b/client/ayon_core/pipeline/create/__init__.py index 68e173d6b9..bb05bc6a09 100644 --- a/client/ayon_core/pipeline/create/__init__.py +++ b/client/ayon_core/pipeline/create/__init__.py @@ -18,7 +18,7 @@ CreatorsRemoveFailed, CreatorsOperationFailed, ) - +from .structures import CreatedInstance from .utils import ( get_last_versions_for_instances, get_next_versions_for_instances, @@ -48,10 +48,7 @@ cache_and_get_instances, ) -from .context import ( - CreatedInstance, - CreateContext -) +from .context import CreateContext from .legacy_create import ( LegacyCreator, @@ -65,6 +62,21 @@ "PRE_CREATE_THUMBNAIL_KEY", "DEFAULT_VARIANT_VALUE", + "UnavailableSharedData", + "ImmutableKeyError", + "HostMissRequiredMethod", + "ConvertorsOperationFailed", + "ConvertorsFindFailed", + "ConvertorsConversionFailed", + "CreatorError", + "CreatorsCreateFailed", + "CreatorsCollectionFailed", + "CreatorsSaveFailed", + "CreatorsRemoveFailed", + "CreatorsOperationFailed", + + "CreatedInstance", + "get_last_versions_for_instances", "get_next_versions_for_instances", @@ -90,7 +102,6 @@ "cache_and_get_instances", - "CreatedInstance", "CreateContext", "LegacyCreator", diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index 6f802a5a6e..a11bc311dc 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -5,7 +5,6 @@ import traceback import collections import inspect -from uuid import uuid4 from contextlib import contextmanager from typing import Optional @@ -16,22 +15,14 @@ from ayon_core.settings import get_project_settings from ayon_core.lib import is_func_signature_supported from ayon_core.lib.attribute_definitions import ( - UnknownDef, - serialize_attr_defs, - deserialize_attr_defs, get_default_values, ) from ayon_core.host import IPublishHost, IWorkfileHost -from ayon_core.pipeline import ( - Anatomy, - AYON_INSTANCE_ID, - AVALON_INSTANCE_ID, -) +from ayon_core.pipeline import Anatomy from ayon_core.pipeline.plugin_discover import DiscoverResult from .exceptions import ( CreatorError, - ImmutableKeyError, CreatorsCreateFailed, CreatorsCollectionFailed, CreatorsSaveFailed, @@ -42,6 +33,7 @@ HostMissRequiredMethod, ) from .changes import TrackChangesItem +from .structures import PublishAttributes, ConvertorItem from .creator_plugins import ( Creator, AutoCreator, @@ -85,860 +77,6 @@ def prepare_failed_creator_operation_info( } -class InstanceMember: - """Representation of instance member. - - TODO: - Implement and use! - """ - - def __init__(self, instance, name): - self.instance = instance - - instance.add_members(self) - - self.name = name - self._actions = [] - - def add_action(self, label, callback): - self._actions.append({ - "label": label, - "callback": callback - }) - - -class AttributeValues(object): - """Container which keep values of Attribute definitions. - - Goal is to have one object which hold values of attribute definitions for - single instance. - - Has dictionary like methods. Not all of them are allowed all the time. - - Args: - attr_defs(AbstractAttrDef): Definitions of value type and properties. - values(dict): Values after possible conversion. - origin_data(dict): Values loaded from host before conversion. - """ - - def __init__(self, attr_defs, values, origin_data=None): - if origin_data is None: - origin_data = copy.deepcopy(values) - self._origin_data = origin_data - - attr_defs_by_key = { - attr_def.key: attr_def - for attr_def in attr_defs - if attr_def.is_value_def - } - for key, value in values.items(): - if key not in attr_defs_by_key: - new_def = UnknownDef(key, label=key, default=value) - attr_defs.append(new_def) - attr_defs_by_key[key] = new_def - - self._attr_defs = attr_defs - self._attr_defs_by_key = attr_defs_by_key - - self._data = {} - for attr_def in attr_defs: - value = values.get(attr_def.key) - if value is not None: - self._data[attr_def.key] = value - - def __setitem__(self, key, value): - if key not in self._attr_defs_by_key: - raise KeyError("Key \"{}\" was not found.".format(key)) - - old_value = self._data.get(key) - if old_value == value: - return - self._data[key] = value - - def __getitem__(self, key): - if key not in self._attr_defs_by_key: - return self._data[key] - return self._data.get(key, self._attr_defs_by_key[key].default) - - def __contains__(self, key): - return key in self._attr_defs_by_key - - def get(self, key, default=None): - if key in self._attr_defs_by_key: - return self[key] - return default - - def keys(self): - return self._attr_defs_by_key.keys() - - def values(self): - for key in self._attr_defs_by_key.keys(): - yield self._data.get(key) - - def items(self): - for key in self._attr_defs_by_key.keys(): - yield key, self._data.get(key) - - def update(self, value): - for _key, _value in dict(value): - self[_key] = _value - - def pop(self, key, default=None): - value = self._data.pop(key, default) - # Remove attribute definition if is 'UnknownDef' - # - gives option to get rid of unknown values - attr_def = self._attr_defs_by_key.get(key) - if isinstance(attr_def, UnknownDef): - self._attr_defs_by_key.pop(key) - self._attr_defs.remove(attr_def) - return value - - def reset_values(self): - self._data = {} - - def mark_as_stored(self): - self._origin_data = copy.deepcopy(self._data) - - @property - def attr_defs(self): - """Pointer to attribute definitions. - - Returns: - List[AbstractAttrDef]: Attribute definitions. - """ - - return list(self._attr_defs) - - @property - def origin_data(self): - return copy.deepcopy(self._origin_data) - - def data_to_store(self): - """Create new dictionary with data to store. - - Returns: - Dict[str, Any]: Attribute values that should be stored. - """ - - output = {} - for key in self._data: - output[key] = self[key] - - for key, attr_def in self._attr_defs_by_key.items(): - if key not in output: - output[key] = attr_def.default - return output - - def get_serialized_attr_defs(self): - """Serialize attribute definitions to json serializable types. - - Returns: - List[Dict[str, Any]]: Serialized attribute definitions. - """ - - return serialize_attr_defs(self._attr_defs) - - -class CreatorAttributeValues(AttributeValues): - """Creator specific attribute values of an instance. - - Args: - instance (CreatedInstance): Instance for which are values hold. - """ - - def __init__(self, instance, *args, **kwargs): - self.instance = instance - super(CreatorAttributeValues, self).__init__(*args, **kwargs) - - -class PublishAttributeValues(AttributeValues): - """Publish plugin specific attribute values. - - Values are for single plugin which can be on `CreatedInstance` - or context values stored on `CreateContext`. - - Args: - publish_attributes(PublishAttributes): Wrapper for multiple publish - attributes is used as parent object. - """ - - def __init__(self, publish_attributes, *args, **kwargs): - self.publish_attributes = publish_attributes - super(PublishAttributeValues, self).__init__(*args, **kwargs) - - @property - def parent(self): - return self.publish_attributes.parent - - -class PublishAttributes: - """Wrapper for publish plugin attribute definitions. - - Cares about handling attribute definitions of multiple publish plugins. - Keep information about attribute definitions and their values. - - Args: - parent(CreatedInstance, CreateContext): Parent for which will be - data stored and from which are data loaded. - origin_data(dict): Loaded data by plugin class name. - attr_plugins(Union[List[pyblish.api.Plugin], None]): List of publish - plugins that may have defined attribute definitions. - """ - - def __init__(self, parent, origin_data, attr_plugins=None): - self.parent = parent - self._origin_data = copy.deepcopy(origin_data) - - attr_plugins = attr_plugins or [] - self.attr_plugins = attr_plugins - - self._data = copy.deepcopy(origin_data) - self._plugin_names_order = [] - self._missing_plugins = [] - - self.set_publish_plugins(attr_plugins) - - def __getitem__(self, key): - return self._data[key] - - def __contains__(self, key): - return key in self._data - - def keys(self): - return self._data.keys() - - def values(self): - return self._data.values() - - def items(self): - return self._data.items() - - def pop(self, key, default=None): - """Remove or reset value for plugin. - - Plugin values are reset to defaults if plugin is available but - data of plugin which was not found are removed. - - Args: - key(str): Plugin name. - default: Default value if plugin was not found. - """ - - if key not in self._data: - return default - - if key in self._missing_plugins: - self._missing_plugins.remove(key) - removed_item = self._data.pop(key) - return removed_item.data_to_store() - - value_item = self._data[key] - # Prepare value to return - output = value_item.data_to_store() - # Reset values - value_item.reset_values() - return output - - def plugin_names_order(self): - """Plugin names order by their 'order' attribute.""" - - for name in self._plugin_names_order: - yield name - - def mark_as_stored(self): - self._origin_data = copy.deepcopy(self.data_to_store()) - - def data_to_store(self): - """Convert attribute values to "data to store".""" - - output = {} - for key, attr_value in self._data.items(): - output[key] = attr_value.data_to_store() - return output - - @property - def origin_data(self): - return copy.deepcopy(self._origin_data) - - def set_publish_plugins(self, attr_plugins): - """Set publish plugins attribute definitions.""" - - self._plugin_names_order = [] - self._missing_plugins = [] - self.attr_plugins = attr_plugins or [] - - origin_data = self._origin_data - data = self._data - self._data = {} - added_keys = set() - for plugin in attr_plugins: - output = plugin.convert_attribute_values(data) - if output is not None: - data = output - attr_defs = plugin.get_attribute_defs() - if not attr_defs: - continue - - key = plugin.__name__ - added_keys.add(key) - self._plugin_names_order.append(key) - - value = data.get(key) or {} - orig_value = copy.deepcopy(origin_data.get(key) or {}) - self._data[key] = PublishAttributeValues( - self, attr_defs, value, orig_value - ) - - for key, value in data.items(): - if key not in added_keys: - self._missing_plugins.append(key) - self._data[key] = PublishAttributeValues( - self, [], value, value - ) - - def serialize_attributes(self): - return { - "attr_defs": { - plugin_name: attrs_value.get_serialized_attr_defs() - for plugin_name, attrs_value in self._data.items() - }, - "plugin_names_order": self._plugin_names_order, - "missing_plugins": self._missing_plugins - } - - def deserialize_attributes(self, data): - self._plugin_names_order = data["plugin_names_order"] - self._missing_plugins = data["missing_plugins"] - - attr_defs = deserialize_attr_defs(data["attr_defs"]) - - origin_data = self._origin_data - data = self._data - self._data = {} - - added_keys = set() - for plugin_name, attr_defs_data in attr_defs.items(): - attr_defs = deserialize_attr_defs(attr_defs_data) - value = data.get(plugin_name) or {} - orig_value = copy.deepcopy(origin_data.get(plugin_name) or {}) - self._data[plugin_name] = PublishAttributeValues( - self, attr_defs, value, orig_value - ) - - for key, value in data.items(): - if key not in added_keys: - self._missing_plugins.append(key) - self._data[key] = PublishAttributeValues( - self, [], value, value - ) - - -class CreatedInstance: - """Instance entity with data that will be stored to workfile. - - I think `data` must be required argument containing all minimum information - about instance like "folderPath" and "task" and all data used for filling - product name as creators may have custom data for product name filling. - - Notes: - Object have 2 possible initialization. One using 'creator' object which - is recommended for api usage. Second by passing information about - creator. - - Args: - product_type (str): Product type that will be created. - product_name (str): Name of product that will be created. - data (Dict[str, Any]): Data used for filling product name or override - data from already existing instance. - creator (Union[BaseCreator, None]): Creator responsible for instance. - creator_identifier (str): Identifier of creator plugin. - creator_label (str): Creator plugin label. - group_label (str): Default group label from creator plugin. - creator_attr_defs (List[AbstractAttrDef]): Attribute definitions from - creator. - """ - - # Keys that can't be changed or removed from data after loading using - # creator. - # - 'creator_attributes' and 'publish_attributes' can change values of - # their individual children but not on their own - __immutable_keys = ( - "id", - "instance_id", - "product_type", - "creator_identifier", - "creator_attributes", - "publish_attributes" - ) - - def __init__( - self, - product_type, - product_name, - data, - creator=None, - creator_identifier=None, - creator_label=None, - group_label=None, - creator_attr_defs=None, - ): - if creator is not None: - creator_identifier = creator.identifier - group_label = creator.get_group_label() - creator_label = creator.label - creator_attr_defs = creator.get_instance_attr_defs() - - self._creator_label = creator_label - self._group_label = group_label or creator_identifier - - # Instance members may have actions on them - # TODO implement members logic - self._members = [] - - # Data that can be used for lifetime of object - self._transient_data = {} - - # Create a copy of passed data to avoid changing them on the fly - data = copy.deepcopy(data or {}) - - # Pop dictionary values that will be converted to objects to be able - # catch changes - orig_creator_attributes = data.pop("creator_attributes", None) or {} - orig_publish_attributes = data.pop("publish_attributes", None) or {} - - # Store original value of passed data - self._orig_data = copy.deepcopy(data) - - # Pop 'productType' and 'productName' to prevent unexpected changes - data.pop("productType", None) - data.pop("productName", None) - # Backwards compatibility with OpenPype instances - data.pop("family", None) - data.pop("subset", None) - - asset_name = data.pop("asset", None) - if "folderPath" not in data: - data["folderPath"] = asset_name - - # QUESTION Does it make sense to have data stored as ordered dict? - self._data = collections.OrderedDict() - # QUESTION Do we need this "id" information on instance? - item_id = data.get("id") - # TODO use only 'AYON_INSTANCE_ID' when all hosts support it - if item_id not in {AYON_INSTANCE_ID, AVALON_INSTANCE_ID}: - item_id = AVALON_INSTANCE_ID - self._data["id"] = item_id - self._data["productType"] = product_type - self._data["productName"] = product_name - self._data["active"] = data.get("active", True) - self._data["creator_identifier"] = creator_identifier - - # Pop from source data all keys that are defined in `_data` before - # this moment and through their values away - # - they should be the same and if are not then should not change - # already set values - for key in self._data.keys(): - if key in data: - data.pop(key) - - self._data["variant"] = self._data.get("variant") or "" - # Stored creator specific attribute values - # {key: value} - creator_values = copy.deepcopy(orig_creator_attributes) - - self._data["creator_attributes"] = CreatorAttributeValues( - self, - list(creator_attr_defs), - creator_values, - orig_creator_attributes - ) - - # Stored publish specific attribute values - # {: {key: value}} - # - must be set using 'set_publish_plugins' - self._data["publish_attributes"] = PublishAttributes( - self, orig_publish_attributes, None - ) - if data: - self._data.update(data) - - if not self._data.get("instance_id"): - self._data["instance_id"] = str(uuid4()) - - self._folder_is_valid = self.has_set_folder - self._task_is_valid = self.has_set_task - - def __str__(self): - return ( - " {data}" - ).format( - creator_identifier=self.creator_identifier, - product={"name": self.product_name, "type": self.product_type}, - data=str(self._data) - ) - - # --- Dictionary like methods --- - def __getitem__(self, key): - return self._data[key] - - def __contains__(self, key): - return key in self._data - - def __setitem__(self, key, value): - # Validate immutable keys - if key not in self.__immutable_keys: - self._data[key] = value - - elif value != self._data.get(key): - # Raise exception if key is immutable and value has changed - raise ImmutableKeyError(key) - - def get(self, key, default=None): - return self._data.get(key, default) - - def pop(self, key, *args, **kwargs): - # Raise exception if is trying to pop key which is immutable - if key in self.__immutable_keys: - raise ImmutableKeyError(key) - - self._data.pop(key, *args, **kwargs) - - def keys(self): - return self._data.keys() - - def values(self): - return self._data.values() - - def items(self): - return self._data.items() - # ------ - - @property - def product_type(self): - return self._data["productType"] - - @property - def product_name(self): - return self._data["productName"] - - @property - def label(self): - label = self._data.get("label") - if not label: - label = self.product_name - return label - - @property - def group_label(self): - label = self._data.get("group") - if label: - return label - return self._group_label - - @property - def origin_data(self): - output = copy.deepcopy(self._orig_data) - output["creator_attributes"] = self.creator_attributes.origin_data - output["publish_attributes"] = self.publish_attributes.origin_data - return output - - @property - def creator_identifier(self): - return self._data["creator_identifier"] - - @property - def creator_label(self): - return self._creator_label or self.creator_identifier - - @property - def id(self): - """Instance identifier. - - Returns: - str: UUID of instance. - """ - - return self._data["instance_id"] - - @property - def data(self): - """Legacy access to data. - - Access to data is needed to modify values. - - Returns: - CreatedInstance: Object can be used as dictionary but with - validations of immutable keys. - """ - - return self - - @property - def transient_data(self): - """Data stored for lifetime of instance object. - - These data are not stored to scene and will be lost on object - deletion. - - Can be used to store objects. In some host implementations is not - possible to reference to object in scene with some unique identifier - (e.g. node in Fusion.). In that case it is handy to store the object - here. Should be used that way only if instance data are stored on the - node itself. - - Returns: - Dict[str, Any]: Dictionary object where you can store data related - to instance for lifetime of instance object. - """ - - return self._transient_data - - def changes(self): - """Calculate and return changes.""" - - return TrackChangesItem(self.origin_data, self.data_to_store()) - - def mark_as_stored(self): - """Should be called when instance data are stored. - - Origin data are replaced by current data so changes are cleared. - """ - - orig_keys = set(self._orig_data.keys()) - for key, value in self._data.items(): - orig_keys.discard(key) - if key in ("creator_attributes", "publish_attributes"): - continue - self._orig_data[key] = copy.deepcopy(value) - - for key in orig_keys: - self._orig_data.pop(key) - - self.creator_attributes.mark_as_stored() - self.publish_attributes.mark_as_stored() - - @property - def creator_attributes(self): - return self._data["creator_attributes"] - - @property - def creator_attribute_defs(self): - """Attribute definitions defined by creator plugin. - - Returns: - List[AbstractAttrDef]: Attribute definitions. - """ - - return self.creator_attributes.attr_defs - - @property - def publish_attributes(self): - return self._data["publish_attributes"] - - def data_to_store(self): - """Collect data that contain json parsable types. - - It is possible to recreate the instance using these data. - - Todos: - We probably don't need OrderedDict. When data are loaded they - are not ordered anymore. - - Returns: - OrderedDict: Ordered dictionary with instance data. - """ - - output = collections.OrderedDict() - for key, value in self._data.items(): - if key in ("creator_attributes", "publish_attributes"): - continue - output[key] = value - - output["creator_attributes"] = self.creator_attributes.data_to_store() - output["publish_attributes"] = self.publish_attributes.data_to_store() - - return output - - @classmethod - def from_existing(cls, instance_data, creator): - """Convert instance data from workfile to CreatedInstance. - - Args: - instance_data (Dict[str, Any]): Data in a structure ready for - 'CreatedInstance' object. - creator (BaseCreator): Creator plugin which is creating the - instance of for which the instance belong. - """ - - instance_data = copy.deepcopy(instance_data) - - product_type = instance_data.get("productType") - if product_type is None: - product_type = instance_data.get("family") - if product_type is None: - product_type = creator.product_type - product_name = instance_data.get("productName") - if product_name is None: - product_name = instance_data.get("subset") - - return cls( - product_type, product_name, instance_data, creator - ) - - def set_publish_plugins(self, attr_plugins): - """Set publish plugins with attribute definitions. - - This method should be called only from 'CreateContext'. - - Args: - attr_plugins (List[pyblish.api.Plugin]): Pyblish plugins which - inherit from 'AYONPyblishPluginMixin' and may contain - attribute definitions. - """ - - self.publish_attributes.set_publish_plugins(attr_plugins) - - def add_members(self, members): - """Currently unused method.""" - - for member in members: - if member not in self._members: - self._members.append(member) - - def serialize_for_remote(self): - """Serialize object into data to be possible recreated object. - - Returns: - Dict[str, Any]: Serialized data. - """ - - creator_attr_defs = self.creator_attributes.get_serialized_attr_defs() - publish_attributes = self.publish_attributes.serialize_attributes() - return { - "data": self.data_to_store(), - "orig_data": self.origin_data, - "creator_attr_defs": creator_attr_defs, - "publish_attributes": publish_attributes, - "creator_label": self._creator_label, - "group_label": self._group_label, - } - - @classmethod - def deserialize_on_remote(cls, serialized_data): - """Convert instance data to CreatedInstance. - - This is fake instance in remote process e.g. in UI process. The creator - is not a full creator and should not be used for calling methods when - instance is created from this method (matters on implementation). - - Args: - serialized_data (Dict[str, Any]): Serialized data for remote - recreating. Should contain 'data' and 'orig_data'. - """ - - instance_data = copy.deepcopy(serialized_data["data"]) - creator_identifier = instance_data["creator_identifier"] - - product_type = instance_data["productType"] - product_name = instance_data.get("productName", None) - - creator_label = serialized_data["creator_label"] - group_label = serialized_data["group_label"] - creator_attr_defs = deserialize_attr_defs( - serialized_data["creator_attr_defs"] - ) - publish_attributes = serialized_data["publish_attributes"] - - obj = cls( - product_type, - product_name, - instance_data, - creator_identifier=creator_identifier, - creator_label=creator_label, - group_label=group_label, - creator_attr_defs=creator_attr_defs - ) - obj._orig_data = serialized_data["orig_data"] - obj.publish_attributes.deserialize_attributes(publish_attributes) - - return obj - - # Context validation related methods/properties - @property - def has_set_folder(self): - """Folder path is set in data.""" - - return "folderPath" in self._data - - @property - def has_set_task(self): - """Task name is set in data.""" - - return "task" in self._data - - @property - def has_valid_context(self): - """Context data are valid for publishing.""" - - return self.has_valid_folder and self.has_valid_task - - @property - def has_valid_folder(self): - """Folder set in context exists in project.""" - - if not self.has_set_folder: - return False - return self._folder_is_valid - - @property - def has_valid_task(self): - """Task set in context exists in project.""" - - if not self.has_set_task: - return False - return self._task_is_valid - - def set_folder_invalid(self, invalid): - # TODO replace with `set_folder_path` - self._folder_is_valid = not invalid - - def set_task_invalid(self, invalid): - # TODO replace with `set_task_name` - self._task_is_valid = not invalid - - -class ConvertorItem(object): - """Item representing convertor plugin. - - Args: - identifier (str): Identifier of convertor. - label (str): Label which will be shown in UI. - """ - - def __init__(self, identifier, label): - self._id = str(uuid4()) - self.identifier = identifier - self.label = label - - @property - def id(self): - return self._id - - def to_data(self): - return { - "id": self.id, - "identifier": self.identifier, - "label": self.label - } - - @classmethod - def from_data(cls, data): - obj = cls(data["identifier"], data["label"]) - obj._id = data["id"] - return obj - - class CreateContext: """Context of instance creation. diff --git a/client/ayon_core/pipeline/create/structures.py b/client/ayon_core/pipeline/create/structures.py new file mode 100644 index 0000000000..7fe854c4fc --- /dev/null +++ b/client/ayon_core/pipeline/create/structures.py @@ -0,0 +1,870 @@ +import copy +import collections +from uuid import uuid4 + +from ayon_core.lib.attribute_definitions import ( + UnknownDef, + serialize_attr_defs, + deserialize_attr_defs, +) +from ayon_core.pipeline import ( + AYON_INSTANCE_ID, + AVALON_INSTANCE_ID, +) + +from .exceptions import ImmutableKeyError +from .changes import TrackChangesItem + + +class ConvertorItem(object): + """Item representing convertor plugin. + + Args: + identifier (str): Identifier of convertor. + label (str): Label which will be shown in UI. + """ + + def __init__(self, identifier, label): + self._id = str(uuid4()) + self.identifier = identifier + self.label = label + + @property + def id(self): + return self._id + + def to_data(self): + return { + "id": self.id, + "identifier": self.identifier, + "label": self.label + } + + @classmethod + def from_data(cls, data): + obj = cls(data["identifier"], data["label"]) + obj._id = data["id"] + return obj + + +class InstanceMember: + """Representation of instance member. + + TODO: + Implement and use! + """ + + def __init__(self, instance, name): + self.instance = instance + + instance.add_members(self) + + self.name = name + self._actions = [] + + def add_action(self, label, callback): + self._actions.append({ + "label": label, + "callback": callback + }) + + +class AttributeValues(object): + """Container which keep values of Attribute definitions. + + Goal is to have one object which hold values of attribute definitions for + single instance. + + Has dictionary like methods. Not all of them are allowed all the time. + + Args: + attr_defs(AbstractAttrDef): Definitions of value type and properties. + values(dict): Values after possible conversion. + origin_data(dict): Values loaded from host before conversion. + """ + + def __init__(self, attr_defs, values, origin_data=None): + if origin_data is None: + origin_data = copy.deepcopy(values) + self._origin_data = origin_data + + attr_defs_by_key = { + attr_def.key: attr_def + for attr_def in attr_defs + if attr_def.is_value_def + } + for key, value in values.items(): + if key not in attr_defs_by_key: + new_def = UnknownDef(key, label=key, default=value) + attr_defs.append(new_def) + attr_defs_by_key[key] = new_def + + self._attr_defs = attr_defs + self._attr_defs_by_key = attr_defs_by_key + + self._data = {} + for attr_def in attr_defs: + value = values.get(attr_def.key) + if value is not None: + self._data[attr_def.key] = value + + def __setitem__(self, key, value): + if key not in self._attr_defs_by_key: + raise KeyError("Key \"{}\" was not found.".format(key)) + + old_value = self._data.get(key) + if old_value == value: + return + self._data[key] = value + + def __getitem__(self, key): + if key not in self._attr_defs_by_key: + return self._data[key] + return self._data.get(key, self._attr_defs_by_key[key].default) + + def __contains__(self, key): + return key in self._attr_defs_by_key + + def get(self, key, default=None): + if key in self._attr_defs_by_key: + return self[key] + return default + + def keys(self): + return self._attr_defs_by_key.keys() + + def values(self): + for key in self._attr_defs_by_key.keys(): + yield self._data.get(key) + + def items(self): + for key in self._attr_defs_by_key.keys(): + yield key, self._data.get(key) + + def update(self, value): + for _key, _value in dict(value): + self[_key] = _value + + def pop(self, key, default=None): + value = self._data.pop(key, default) + # Remove attribute definition if is 'UnknownDef' + # - gives option to get rid of unknown values + attr_def = self._attr_defs_by_key.get(key) + if isinstance(attr_def, UnknownDef): + self._attr_defs_by_key.pop(key) + self._attr_defs.remove(attr_def) + return value + + def reset_values(self): + self._data = {} + + def mark_as_stored(self): + self._origin_data = copy.deepcopy(self._data) + + @property + def attr_defs(self): + """Pointer to attribute definitions. + + Returns: + List[AbstractAttrDef]: Attribute definitions. + """ + + return list(self._attr_defs) + + @property + def origin_data(self): + return copy.deepcopy(self._origin_data) + + def data_to_store(self): + """Create new dictionary with data to store. + + Returns: + Dict[str, Any]: Attribute values that should be stored. + """ + + output = {} + for key in self._data: + output[key] = self[key] + + for key, attr_def in self._attr_defs_by_key.items(): + if key not in output: + output[key] = attr_def.default + return output + + def get_serialized_attr_defs(self): + """Serialize attribute definitions to json serializable types. + + Returns: + List[Dict[str, Any]]: Serialized attribute definitions. + """ + + return serialize_attr_defs(self._attr_defs) + + +class CreatorAttributeValues(AttributeValues): + """Creator specific attribute values of an instance. + + Args: + instance (CreatedInstance): Instance for which are values hold. + """ + + def __init__(self, instance, *args, **kwargs): + self.instance = instance + super(CreatorAttributeValues, self).__init__(*args, **kwargs) + + +class PublishAttributeValues(AttributeValues): + """Publish plugin specific attribute values. + + Values are for single plugin which can be on `CreatedInstance` + or context values stored on `CreateContext`. + + Args: + publish_attributes(PublishAttributes): Wrapper for multiple publish + attributes is used as parent object. + """ + + def __init__(self, publish_attributes, *args, **kwargs): + self.publish_attributes = publish_attributes + super(PublishAttributeValues, self).__init__(*args, **kwargs) + + @property + def parent(self): + return self.publish_attributes.parent + + +class PublishAttributes: + """Wrapper for publish plugin attribute definitions. + + Cares about handling attribute definitions of multiple publish plugins. + Keep information about attribute definitions and their values. + + Args: + parent(CreatedInstance, CreateContext): Parent for which will be + data stored and from which are data loaded. + origin_data(dict): Loaded data by plugin class name. + attr_plugins(Union[List[pyblish.api.Plugin], None]): List of publish + plugins that may have defined attribute definitions. + """ + + def __init__(self, parent, origin_data, attr_plugins=None): + self.parent = parent + self._origin_data = copy.deepcopy(origin_data) + + attr_plugins = attr_plugins or [] + self.attr_plugins = attr_plugins + + self._data = copy.deepcopy(origin_data) + self._plugin_names_order = [] + self._missing_plugins = [] + + self.set_publish_plugins(attr_plugins) + + def __getitem__(self, key): + return self._data[key] + + def __contains__(self, key): + return key in self._data + + def keys(self): + return self._data.keys() + + def values(self): + return self._data.values() + + def items(self): + return self._data.items() + + def pop(self, key, default=None): + """Remove or reset value for plugin. + + Plugin values are reset to defaults if plugin is available but + data of plugin which was not found are removed. + + Args: + key(str): Plugin name. + default: Default value if plugin was not found. + """ + + if key not in self._data: + return default + + if key in self._missing_plugins: + self._missing_plugins.remove(key) + removed_item = self._data.pop(key) + return removed_item.data_to_store() + + value_item = self._data[key] + # Prepare value to return + output = value_item.data_to_store() + # Reset values + value_item.reset_values() + return output + + def plugin_names_order(self): + """Plugin names order by their 'order' attribute.""" + + for name in self._plugin_names_order: + yield name + + def mark_as_stored(self): + self._origin_data = copy.deepcopy(self.data_to_store()) + + def data_to_store(self): + """Convert attribute values to "data to store".""" + + output = {} + for key, attr_value in self._data.items(): + output[key] = attr_value.data_to_store() + return output + + @property + def origin_data(self): + return copy.deepcopy(self._origin_data) + + def set_publish_plugins(self, attr_plugins): + """Set publish plugins attribute definitions.""" + + self._plugin_names_order = [] + self._missing_plugins = [] + self.attr_plugins = attr_plugins or [] + + origin_data = self._origin_data + data = self._data + self._data = {} + added_keys = set() + for plugin in attr_plugins: + output = plugin.convert_attribute_values(data) + if output is not None: + data = output + attr_defs = plugin.get_attribute_defs() + if not attr_defs: + continue + + key = plugin.__name__ + added_keys.add(key) + self._plugin_names_order.append(key) + + value = data.get(key) or {} + orig_value = copy.deepcopy(origin_data.get(key) or {}) + self._data[key] = PublishAttributeValues( + self, attr_defs, value, orig_value + ) + + for key, value in data.items(): + if key not in added_keys: + self._missing_plugins.append(key) + self._data[key] = PublishAttributeValues( + self, [], value, value + ) + + def serialize_attributes(self): + return { + "attr_defs": { + plugin_name: attrs_value.get_serialized_attr_defs() + for plugin_name, attrs_value in self._data.items() + }, + "plugin_names_order": self._plugin_names_order, + "missing_plugins": self._missing_plugins + } + + def deserialize_attributes(self, data): + self._plugin_names_order = data["plugin_names_order"] + self._missing_plugins = data["missing_plugins"] + + attr_defs = deserialize_attr_defs(data["attr_defs"]) + + origin_data = self._origin_data + data = self._data + self._data = {} + + added_keys = set() + for plugin_name, attr_defs_data in attr_defs.items(): + attr_defs = deserialize_attr_defs(attr_defs_data) + value = data.get(plugin_name) or {} + orig_value = copy.deepcopy(origin_data.get(plugin_name) or {}) + self._data[plugin_name] = PublishAttributeValues( + self, attr_defs, value, orig_value + ) + + for key, value in data.items(): + if key not in added_keys: + self._missing_plugins.append(key) + self._data[key] = PublishAttributeValues( + self, [], value, value + ) + + +class CreatedInstance: + """Instance entity with data that will be stored to workfile. + + I think `data` must be required argument containing all minimum information + about instance like "folderPath" and "task" and all data used for filling + product name as creators may have custom data for product name filling. + + Notes: + Object have 2 possible initialization. One using 'creator' object which + is recommended for api usage. Second by passing information about + creator. + + Args: + product_type (str): Product type that will be created. + product_name (str): Name of product that will be created. + data (Dict[str, Any]): Data used for filling product name or override + data from already existing instance. + creator (Union[BaseCreator, None]): Creator responsible for instance. + creator_identifier (str): Identifier of creator plugin. + creator_label (str): Creator plugin label. + group_label (str): Default group label from creator plugin. + creator_attr_defs (List[AbstractAttrDef]): Attribute definitions from + creator. + """ + + # Keys that can't be changed or removed from data after loading using + # creator. + # - 'creator_attributes' and 'publish_attributes' can change values of + # their individual children but not on their own + __immutable_keys = ( + "id", + "instance_id", + "product_type", + "creator_identifier", + "creator_attributes", + "publish_attributes" + ) + + def __init__( + self, + product_type, + product_name, + data, + creator=None, + creator_identifier=None, + creator_label=None, + group_label=None, + creator_attr_defs=None, + ): + if creator is not None: + creator_identifier = creator.identifier + group_label = creator.get_group_label() + creator_label = creator.label + creator_attr_defs = creator.get_instance_attr_defs() + + self._creator_label = creator_label + self._group_label = group_label or creator_identifier + + # Instance members may have actions on them + # TODO implement members logic + self._members = [] + + # Data that can be used for lifetime of object + self._transient_data = {} + + # Create a copy of passed data to avoid changing them on the fly + data = copy.deepcopy(data or {}) + + # Pop dictionary values that will be converted to objects to be able + # catch changes + orig_creator_attributes = data.pop("creator_attributes", None) or {} + orig_publish_attributes = data.pop("publish_attributes", None) or {} + + # Store original value of passed data + self._orig_data = copy.deepcopy(data) + + # Pop 'productType' and 'productName' to prevent unexpected changes + data.pop("productType", None) + data.pop("productName", None) + # Backwards compatibility with OpenPype instances + data.pop("family", None) + data.pop("subset", None) + + asset_name = data.pop("asset", None) + if "folderPath" not in data: + data["folderPath"] = asset_name + + # QUESTION Does it make sense to have data stored as ordered dict? + self._data = collections.OrderedDict() + # QUESTION Do we need this "id" information on instance? + item_id = data.get("id") + # TODO use only 'AYON_INSTANCE_ID' when all hosts support it + if item_id not in {AYON_INSTANCE_ID, AVALON_INSTANCE_ID}: + item_id = AVALON_INSTANCE_ID + self._data["id"] = item_id + self._data["productType"] = product_type + self._data["productName"] = product_name + self._data["active"] = data.get("active", True) + self._data["creator_identifier"] = creator_identifier + + # Pop from source data all keys that are defined in `_data` before + # this moment and through their values away + # - they should be the same and if are not then should not change + # already set values + for key in self._data.keys(): + if key in data: + data.pop(key) + + self._data["variant"] = self._data.get("variant") or "" + # Stored creator specific attribute values + # {key: value} + creator_values = copy.deepcopy(orig_creator_attributes) + + self._data["creator_attributes"] = CreatorAttributeValues( + self, + list(creator_attr_defs), + creator_values, + orig_creator_attributes + ) + + # Stored publish specific attribute values + # {: {key: value}} + # - must be set using 'set_publish_plugins' + self._data["publish_attributes"] = PublishAttributes( + self, orig_publish_attributes, None + ) + if data: + self._data.update(data) + + if not self._data.get("instance_id"): + self._data["instance_id"] = str(uuid4()) + + self._folder_is_valid = self.has_set_folder + self._task_is_valid = self.has_set_task + + def __str__(self): + return ( + " {data}" + ).format( + creator_identifier=self.creator_identifier, + product={"name": self.product_name, "type": self.product_type}, + data=str(self._data) + ) + + # --- Dictionary like methods --- + def __getitem__(self, key): + return self._data[key] + + def __contains__(self, key): + return key in self._data + + def __setitem__(self, key, value): + # Validate immutable keys + if key not in self.__immutable_keys: + self._data[key] = value + + elif value != self._data.get(key): + # Raise exception if key is immutable and value has changed + raise ImmutableKeyError(key) + + def get(self, key, default=None): + return self._data.get(key, default) + + def pop(self, key, *args, **kwargs): + # Raise exception if is trying to pop key which is immutable + if key in self.__immutable_keys: + raise ImmutableKeyError(key) + + self._data.pop(key, *args, **kwargs) + + def keys(self): + return self._data.keys() + + def values(self): + return self._data.values() + + def items(self): + return self._data.items() + # ------ + + @property + def product_type(self): + return self._data["productType"] + + @property + def product_name(self): + return self._data["productName"] + + @property + def label(self): + label = self._data.get("label") + if not label: + label = self.product_name + return label + + @property + def group_label(self): + label = self._data.get("group") + if label: + return label + return self._group_label + + @property + def origin_data(self): + output = copy.deepcopy(self._orig_data) + output["creator_attributes"] = self.creator_attributes.origin_data + output["publish_attributes"] = self.publish_attributes.origin_data + return output + + @property + def creator_identifier(self): + return self._data["creator_identifier"] + + @property + def creator_label(self): + return self._creator_label or self.creator_identifier + + @property + def id(self): + """Instance identifier. + + Returns: + str: UUID of instance. + """ + + return self._data["instance_id"] + + @property + def data(self): + """Legacy access to data. + + Access to data is needed to modify values. + + Returns: + CreatedInstance: Object can be used as dictionary but with + validations of immutable keys. + """ + + return self + + @property + def transient_data(self): + """Data stored for lifetime of instance object. + + These data are not stored to scene and will be lost on object + deletion. + + Can be used to store objects. In some host implementations is not + possible to reference to object in scene with some unique identifier + (e.g. node in Fusion.). In that case it is handy to store the object + here. Should be used that way only if instance data are stored on the + node itself. + + Returns: + Dict[str, Any]: Dictionary object where you can store data related + to instance for lifetime of instance object. + """ + + return self._transient_data + + def changes(self): + """Calculate and return changes.""" + + return TrackChangesItem(self.origin_data, self.data_to_store()) + + def mark_as_stored(self): + """Should be called when instance data are stored. + + Origin data are replaced by current data so changes are cleared. + """ + + orig_keys = set(self._orig_data.keys()) + for key, value in self._data.items(): + orig_keys.discard(key) + if key in ("creator_attributes", "publish_attributes"): + continue + self._orig_data[key] = copy.deepcopy(value) + + for key in orig_keys: + self._orig_data.pop(key) + + self.creator_attributes.mark_as_stored() + self.publish_attributes.mark_as_stored() + + @property + def creator_attributes(self): + return self._data["creator_attributes"] + + @property + def creator_attribute_defs(self): + """Attribute definitions defined by creator plugin. + + Returns: + List[AbstractAttrDef]: Attribute definitions. + """ + + return self.creator_attributes.attr_defs + + @property + def publish_attributes(self): + return self._data["publish_attributes"] + + def data_to_store(self): + """Collect data that contain json parsable types. + + It is possible to recreate the instance using these data. + + Todos: + We probably don't need OrderedDict. When data are loaded they + are not ordered anymore. + + Returns: + OrderedDict: Ordered dictionary with instance data. + """ + + output = collections.OrderedDict() + for key, value in self._data.items(): + if key in ("creator_attributes", "publish_attributes"): + continue + output[key] = value + + output["creator_attributes"] = self.creator_attributes.data_to_store() + output["publish_attributes"] = self.publish_attributes.data_to_store() + + return output + + @classmethod + def from_existing(cls, instance_data, creator): + """Convert instance data from workfile to CreatedInstance. + + Args: + instance_data (Dict[str, Any]): Data in a structure ready for + 'CreatedInstance' object. + creator (BaseCreator): Creator plugin which is creating the + instance of for which the instance belong. + """ + + instance_data = copy.deepcopy(instance_data) + + product_type = instance_data.get("productType") + if product_type is None: + product_type = instance_data.get("family") + if product_type is None: + product_type = creator.product_type + product_name = instance_data.get("productName") + if product_name is None: + product_name = instance_data.get("subset") + + return cls( + product_type, product_name, instance_data, creator + ) + + def set_publish_plugins(self, attr_plugins): + """Set publish plugins with attribute definitions. + + This method should be called only from 'CreateContext'. + + Args: + attr_plugins (List[pyblish.api.Plugin]): Pyblish plugins which + inherit from 'AYONPyblishPluginMixin' and may contain + attribute definitions. + """ + + self.publish_attributes.set_publish_plugins(attr_plugins) + + def add_members(self, members): + """Currently unused method.""" + + for member in members: + if member not in self._members: + self._members.append(member) + + def serialize_for_remote(self): + """Serialize object into data to be possible recreated object. + + Returns: + Dict[str, Any]: Serialized data. + """ + + creator_attr_defs = self.creator_attributes.get_serialized_attr_defs() + publish_attributes = self.publish_attributes.serialize_attributes() + return { + "data": self.data_to_store(), + "orig_data": self.origin_data, + "creator_attr_defs": creator_attr_defs, + "publish_attributes": publish_attributes, + "creator_label": self._creator_label, + "group_label": self._group_label, + } + + @classmethod + def deserialize_on_remote(cls, serialized_data): + """Convert instance data to CreatedInstance. + + This is fake instance in remote process e.g. in UI process. The creator + is not a full creator and should not be used for calling methods when + instance is created from this method (matters on implementation). + + Args: + serialized_data (Dict[str, Any]): Serialized data for remote + recreating. Should contain 'data' and 'orig_data'. + """ + + instance_data = copy.deepcopy(serialized_data["data"]) + creator_identifier = instance_data["creator_identifier"] + + product_type = instance_data["productType"] + product_name = instance_data.get("productName", None) + + creator_label = serialized_data["creator_label"] + group_label = serialized_data["group_label"] + creator_attr_defs = deserialize_attr_defs( + serialized_data["creator_attr_defs"] + ) + publish_attributes = serialized_data["publish_attributes"] + + obj = cls( + product_type, + product_name, + instance_data, + creator_identifier=creator_identifier, + creator_label=creator_label, + group_label=group_label, + creator_attr_defs=creator_attr_defs + ) + obj._orig_data = serialized_data["orig_data"] + obj.publish_attributes.deserialize_attributes(publish_attributes) + + return obj + + # Context validation related methods/properties + @property + def has_set_folder(self): + """Folder path is set in data.""" + + return "folderPath" in self._data + + @property + def has_set_task(self): + """Task name is set in data.""" + + return "task" in self._data + + @property + def has_valid_context(self): + """Context data are valid for publishing.""" + + return self.has_valid_folder and self.has_valid_task + + @property + def has_valid_folder(self): + """Folder set in context exists in project.""" + + if not self.has_set_folder: + return False + return self._folder_is_valid + + @property + def has_valid_task(self): + """Task set in context exists in project.""" + + if not self.has_set_task: + return False + return self._task_is_valid + + def set_folder_invalid(self, invalid): + # TODO replace with `set_folder_path` + self._folder_is_valid = not invalid + + def set_task_invalid(self, invalid): + # TODO replace with `set_task_name` + self._task_is_valid = not invalid From b0abbf36fb57d6238a1ee8a29669301c8697ede8 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:19:57 +0200 Subject: [PATCH 036/106] moved exceptions from product name too --- client/ayon_core/pipeline/create/__init__.py | 6 ++++-- client/ayon_core/pipeline/create/exceptions.py | 13 +++++++++++++ client/ayon_core/pipeline/create/product_name.py | 15 +-------------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/client/ayon_core/pipeline/create/__init__.py b/client/ayon_core/pipeline/create/__init__.py index bb05bc6a09..fa8d639c6f 100644 --- a/client/ayon_core/pipeline/create/__init__.py +++ b/client/ayon_core/pipeline/create/__init__.py @@ -17,6 +17,8 @@ CreatorsSaveFailed, CreatorsRemoveFailed, CreatorsOperationFailed, + TaskNotSetError, + TemplateFillError, ) from .structures import CreatedInstance from .utils import ( @@ -25,7 +27,6 @@ ) from .product_name import ( - TaskNotSetError, get_product_name, get_product_name_template, ) @@ -74,13 +75,14 @@ "CreatorsSaveFailed", "CreatorsRemoveFailed", "CreatorsOperationFailed", + "TaskNotSetError", + "TemplateFillError", "CreatedInstance", "get_last_versions_for_instances", "get_next_versions_for_instances", - "TaskNotSetError", "get_product_name", "get_product_name_template", diff --git a/client/ayon_core/pipeline/create/exceptions.py b/client/ayon_core/pipeline/create/exceptions.py index 24264840cb..8910d3fa09 100644 --- a/client/ayon_core/pipeline/create/exceptions.py +++ b/client/ayon_core/pipeline/create/exceptions.py @@ -112,3 +112,16 @@ def __init__(self, failed_info): msg = "Failed to create instances" super().__init__(msg, failed_info) + +class TaskNotSetError(KeyError): + def __init__(self, msg=None): + if not msg: + msg = "Creator's product name template requires task name." + super().__init__(msg) + + +class TemplateFillError(Exception): + def __init__(self, msg=None): + if not msg: + msg = "Creator's product name template is missing key value." + super().__init__(msg) diff --git a/client/ayon_core/pipeline/create/product_name.py b/client/ayon_core/pipeline/create/product_name.py index 8a08bdc36c..0c6fb70169 100644 --- a/client/ayon_core/pipeline/create/product_name.py +++ b/client/ayon_core/pipeline/create/product_name.py @@ -4,20 +4,7 @@ from ayon_core.lib import filter_profiles, prepare_template_data from .constants import DEFAULT_PRODUCT_TEMPLATE - - -class TaskNotSetError(KeyError): - def __init__(self, msg=None): - if not msg: - msg = "Creator's product name template requires task name." - super(TaskNotSetError, self).__init__(msg) - - -class TemplateFillError(Exception): - def __init__(self, msg=None): - if not msg: - msg = "Creator's product name template is missing key value." - super(TemplateFillError, self).__init__(msg) +from .exceptions import TaskNotSetError, TemplateFillError def get_product_name_template( From 5d4e086978e7411b0705fcb340c3e8bf9ba2f9ff Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:21:50 +0200 Subject: [PATCH 037/106] remove python 2 compatibility --- client/ayon_core/pipeline/create/changes.py | 2 +- client/ayon_core/pipeline/create/creator_plugins.py | 2 +- client/ayon_core/pipeline/create/legacy_create.py | 2 +- client/ayon_core/pipeline/create/structures.py | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/client/ayon_core/pipeline/create/changes.py b/client/ayon_core/pipeline/create/changes.py index 217478ee30..c8b81cac48 100644 --- a/client/ayon_core/pipeline/create/changes.py +++ b/client/ayon_core/pipeline/create/changes.py @@ -3,7 +3,7 @@ _EMPTY_VALUE = object() -class TrackChangesItem(object): +class TrackChangesItem: """Helper object to track changes in data. Has access to full old and new data and will create deep copy of them, diff --git a/client/ayon_core/pipeline/create/creator_plugins.py b/client/ayon_core/pipeline/create/creator_plugins.py index 1e09eb62a1..61c10ee736 100644 --- a/client/ayon_core/pipeline/create/creator_plugins.py +++ b/client/ayon_core/pipeline/create/creator_plugins.py @@ -644,7 +644,7 @@ def __init__(self, *args, **kwargs): cls._get_default_variant_wrap, cls._set_default_variant_wrap ) - super(Creator, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) @property def show_order(self): diff --git a/client/ayon_core/pipeline/create/legacy_create.py b/client/ayon_core/pipeline/create/legacy_create.py index fc24bcf934..ec9b23ac62 100644 --- a/client/ayon_core/pipeline/create/legacy_create.py +++ b/client/ayon_core/pipeline/create/legacy_create.py @@ -14,7 +14,7 @@ from .product_name import get_product_name -class LegacyCreator(object): +class LegacyCreator: """Determine how assets are created""" label = None product_type = None diff --git a/client/ayon_core/pipeline/create/structures.py b/client/ayon_core/pipeline/create/structures.py index 7fe854c4fc..41c130214d 100644 --- a/client/ayon_core/pipeline/create/structures.py +++ b/client/ayon_core/pipeline/create/structures.py @@ -16,7 +16,7 @@ from .changes import TrackChangesItem -class ConvertorItem(object): +class ConvertorItem: """Item representing convertor plugin. Args: @@ -69,7 +69,7 @@ def add_action(self, label, callback): }) -class AttributeValues(object): +class AttributeValues: """Container which keep values of Attribute definitions. Goal is to have one object which hold values of attribute definitions for @@ -210,7 +210,7 @@ class CreatorAttributeValues(AttributeValues): def __init__(self, instance, *args, **kwargs): self.instance = instance - super(CreatorAttributeValues, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) class PublishAttributeValues(AttributeValues): @@ -226,7 +226,7 @@ class PublishAttributeValues(AttributeValues): def __init__(self, publish_attributes, *args, **kwargs): self.publish_attributes = publish_attributes - super(PublishAttributeValues, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) @property def parent(self): From 7ef60ad4c91af830376d3ffeccd825dd5133e3f1 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:22:03 +0200 Subject: [PATCH 038/106] fix 'update' method --- client/ayon_core/pipeline/create/structures.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/client/ayon_core/pipeline/create/structures.py b/client/ayon_core/pipeline/create/structures.py index 41c130214d..4f7caa6e11 100644 --- a/client/ayon_core/pipeline/create/structures.py +++ b/client/ayon_core/pipeline/create/structures.py @@ -112,10 +112,7 @@ def __setitem__(self, key, value): if key not in self._attr_defs_by_key: raise KeyError("Key \"{}\" was not found.".format(key)) - old_value = self._data.get(key) - if old_value == value: - return - self._data[key] = value + self.update({key: value}) def __getitem__(self, key): if key not in self._attr_defs_by_key: @@ -142,8 +139,12 @@ def items(self): yield key, self._data.get(key) def update(self, value): - for _key, _value in dict(value): - self[_key] = _value + changes = {} + for _key, _value in dict(value).items(): + if _key in self._data and self._data.get(_key) == _value: + continue + self._data[_key] = _value + changes[_key] = _value def pop(self, key, default=None): value = self._data.pop(key, default) From d5602cb89a3123dcc5d7b457b40e652db9133c78 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:27:30 +0200 Subject: [PATCH 039/106] simpler import --- client/ayon_core/pipeline/create/context.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index a11bc311dc..76eb620b4d 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -14,9 +14,7 @@ from ayon_core.settings import get_project_settings from ayon_core.lib import is_func_signature_supported -from ayon_core.lib.attribute_definitions import ( - get_default_values, -) +from ayon_core.lib.attribute_definitions import get_default_values from ayon_core.host import IPublishHost, IWorkfileHost from ayon_core.pipeline import Anatomy from ayon_core.pipeline.plugin_discover import DiscoverResult From 4b8b57e39a47cf446b9368f6a8de146d0de04b6c Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:27:41 +0200 Subject: [PATCH 040/106] remove unecessary line --- client/ayon_core/pipeline/create/context.py | 1 - 1 file changed, 1 deletion(-) diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index 76eb620b4d..f5ba7b4774 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -373,7 +373,6 @@ def get_current_task_entity(self): self._current_task_entity = task_entity return copy.deepcopy(self._current_task_entity) - def get_current_workfile_path(self): """Workfile path which was opened on context reset. From 3296079df689acff6d2d950043428b3ebaaa1b91 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:27:50 +0200 Subject: [PATCH 041/106] make sure exc_info is defined --- client/ayon_core/pipeline/create/context.py | 1 + 1 file changed, 1 insertion(+) diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index f5ba7b4774..2326a829e3 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -871,6 +871,7 @@ def _create_with_unified_error( add_traceback = False result = None fail_info = None + exc_info = None success = False try: From 04b37b83c64e294da9255698c01c227fe443cb29 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:27:59 +0200 Subject: [PATCH 042/106] fix bulk processing --- client/ayon_core/pipeline/create/context.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index 2326a829e3..b3a46bb778 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -965,9 +965,11 @@ def bulk_instances_collection(self): finally: self._bulk_counter -= 1 - # Trigger validation if there is no more context manager for bulk - # instance validation - if self._bulk_counter == 0: + # Trigger validation if there is no more context manager for bulk + # instance validation + if self._bulk_counter != 0: + return + ( self._bulk_instances_to_process, instances_to_validate From eaa1b503b7e3e956ed753d83644dad8023765d24 Mon Sep 17 00:00:00 2001 From: robin Date: Wed, 14 Aug 2024 17:52:29 -0400 Subject: [PATCH 043/106] Validate opening and closing brackets on Anatomy keys. --- client/ayon_core/lib/path_templates.py | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/client/ayon_core/lib/path_templates.py b/client/ayon_core/lib/path_templates.py index 01a6985a25..0a39d05e1d 100644 --- a/client/ayon_core/lib/path_templates.py +++ b/client/ayon_core/lib/path_templates.py @@ -460,6 +460,30 @@ def validate_value_type(value): return True return False + @staticmethod + def validate_key_is_matched(key): + """ + Finds out how balanced an expression is. + With a string containing only brackets. + + >>> is_matched('[]()()(((([])))') + False + >>> is_matched('[](){{{[]}}}') + True + """ + opening = tuple('({[') + closing = tuple(')}]') + mapping = dict(zip(opening, closing)) + queue = [] + + for letter in key: + if letter in opening: + queue.append(mapping[letter]) + elif letter in closing: + if not queue or letter != queue.pop(): + return False + return not queue + def format(self, data, result): """Format the formattings string. @@ -472,6 +496,12 @@ def format(self, data, result): result.add_output(result.realy_used_values[key]) return result + # ensure key is properly formed [({})] properly closed. + if not self.validate_key_is_matched(key): + result.add_missing_key(key) + result.add_output(self.template) + return result + # check if key expects subdictionary keys (e.g. project[name]) existence_check = key key_padding = list(KEY_PADDING_PATTERN.findall(existence_check)) From 44c417fdb0e960c6f8af2bae56309efd70724dc6 Mon Sep 17 00:00:00 2001 From: __robin__ Date: Mon, 19 Aug 2024 08:08:33 -0400 Subject: [PATCH 044/106] Update client/ayon_core/lib/path_templates.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/lib/path_templates.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/client/ayon_core/lib/path_templates.py b/client/ayon_core/lib/path_templates.py index 0a39d05e1d..46dd997da2 100644 --- a/client/ayon_core/lib/path_templates.py +++ b/client/ayon_core/lib/path_templates.py @@ -462,14 +462,17 @@ def validate_value_type(value): @staticmethod def validate_key_is_matched(key): - """ - Finds out how balanced an expression is. - With a string containing only brackets. + """Validate that opening has closing at correct place. + + Example: + >>> is_matched("[]()()(((([])))") + False + >>> is_matched("[](){{{[]}}}") + True + + Returns: + bool: Openings and closinga are valid. - >>> is_matched('[]()()(((([])))') - False - >>> is_matched('[](){{{[]}}}') - True """ opening = tuple('({[') closing = tuple(')}]') From 4d884db269de1f8de4b5824bfa9fb5a7b728220f Mon Sep 17 00:00:00 2001 From: __robin__ Date: Mon, 19 Aug 2024 08:08:50 -0400 Subject: [PATCH 045/106] Update client/ayon_core/lib/path_templates.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/lib/path_templates.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/lib/path_templates.py b/client/ayon_core/lib/path_templates.py index 46dd997da2..edc7478cef 100644 --- a/client/ayon_core/lib/path_templates.py +++ b/client/ayon_core/lib/path_templates.py @@ -474,8 +474,8 @@ def validate_key_is_matched(key): bool: Openings and closinga are valid. """ - opening = tuple('({[') - closing = tuple(')}]') + opening = tuple("({[") + closing = tuple(")}]") mapping = dict(zip(opening, closing)) queue = [] From b0490fd15dbd24534c15e1f80ccf116b5ef2003f Mon Sep 17 00:00:00 2001 From: robin Date: Mon, 19 Aug 2024 08:13:55 -0400 Subject: [PATCH 046/106] Adjust docstring from PR feedback. --- client/ayon_core/lib/path_templates.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/lib/path_templates.py b/client/ayon_core/lib/path_templates.py index edc7478cef..3e3bdd8f78 100644 --- a/client/ayon_core/lib/path_templates.py +++ b/client/ayon_core/lib/path_templates.py @@ -463,6 +463,7 @@ def validate_value_type(value): @staticmethod def validate_key_is_matched(key): """Validate that opening has closing at correct place. + Future-proof, only square brackets are currently used in keys. Example: >>> is_matched("[]()()(((([])))") @@ -471,7 +472,7 @@ def validate_key_is_matched(key): True Returns: - bool: Openings and closinga are valid. + bool: Openings and closing are valid. """ opening = tuple("({[") From b2c9ea31258cb763069c89c77726c7471e1dfa74 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 19 Aug 2024 14:39:22 +0200 Subject: [PATCH 047/106] added default iterator on initialization --- .../ayon_core/tools/publisher/models/publish.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/client/ayon_core/tools/publisher/models/publish.py b/client/ayon_core/tools/publisher/models/publish.py index ef207bfb79..ab8a041414 100644 --- a/client/ayon_core/tools/publisher/models/publish.py +++ b/client/ayon_core/tools/publisher/models/publish.py @@ -829,7 +829,7 @@ def __init__(self, controller: AbstractPublisherBackend): ) # Plugin iterator - self._main_thread_iter: Iterable[partial] = [] + self._main_thread_iter: Iterable[partial] = self._default_iterator() def reset(self): create_context = self._controller.get_create_context() @@ -900,10 +900,9 @@ def get_next_process_func(self) -> partial: # only in specific cases (e.g. when it happens for a first time) if ( - self._main_thread_iter is None # There are validation errors and validation is passed # - can't do any progree - or ( + ( self._publish_has_validated and self._publish_has_validation_errors ) @@ -1070,6 +1069,18 @@ def _set_publish_error_msg(self, value: Optional[str]): {"value": value} ) + def _default_iterator(self): + """Iterator used on initialization. + + Should be replaced by real iterator when 'reset' is called. + + Yields: + partial: Function that will be called in main thread. + + """ + while True: + yield partial(self.stop_publish) + def _start_publish(self): """Start or continue in publishing.""" if self._publish_is_running: From f0cfc968d83294fe8d0a0c93dfca17c61a71c41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= <33513211+antirotor@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:01:22 +0200 Subject: [PATCH 048/106] Update client/ayon_core/pipeline/create/product_name.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/pipeline/create/product_name.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/create/product_name.py b/client/ayon_core/pipeline/create/product_name.py index 597c9f4862..3ca6611644 100644 --- a/client/ayon_core/pipeline/create/product_name.py +++ b/client/ayon_core/pipeline/create/product_name.py @@ -182,7 +182,7 @@ def get_product_name( fill_pairs[key] = value try: - return StringTemplate.format_template( + return StringTemplate.format_strict_template( template=template, data=prepare_template_data(fill_pairs) ) From 2e79075fe35430d754e01d98496fc708960bb11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= <33513211+antirotor@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:17:12 +0200 Subject: [PATCH 049/106] Update server/settings/tools.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- server/settings/tools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/settings/tools.py b/server/settings/tools.py index 5e9c8e14a0..a2785c1edf 100644 --- a/server/settings/tools.py +++ b/server/settings/tools.py @@ -68,7 +68,8 @@ class CreatorToolModel(BaseSettingsModel): ) # TODO: change to False in next releases use_legacy_product_names_for_renders: bool = SettingsField( - True, title="Use legacy product names for renders", + True, + title="Use legacy product names for renders", description="Use product naming templates for renders. " "This is for backwards compatibility enabled by default." "When enabled, it will ignore any templates for renders " From 1f45f8e0a07f91081defcf2e74693d8a005c5fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= <33513211+antirotor@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:17:29 +0200 Subject: [PATCH 050/106] Update client/ayon_core/pipeline/farm/pyblish_functions.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/pipeline/farm/pyblish_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index 91e155469d..fc9371f719 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -563,7 +563,7 @@ def _get_legacy_product_name_and_group( else: resulting_group_name = source_product_name - resulting_product_name = '{}'.format(resulting_group_name) + resulting_product_name = resulting_group_name camera = dynamic_data.get("camera") aov = dynamic_data.get("aov") if camera: From 51c51eeef0415fc65b52d1bc35949926cd996526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= <33513211+antirotor@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:18:29 +0200 Subject: [PATCH 051/106] Update client/ayon_core/pipeline/farm/pyblish_functions.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/pipeline/farm/pyblish_functions.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index fc9371f719..b9a927f02d 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -679,8 +679,9 @@ def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, for aov, files in expected_files[0].items(): collected_files = _collect_expected_files_for_aov(files) - expected_filepath = collected_files[0] \ - if isinstance(collected_files, (list, tuple)) else collected_files + expected_filepath = collected_files + if isinstance(collected_files, (list, tuple)): + expected_filepath = collected_files[0] dynamic_data = { "aov": aov, From 009ab46be04be91c3f94e2e93af5c36476175e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= <33513211+antirotor@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:37:18 +0200 Subject: [PATCH 052/106] Update client/ayon_core/pipeline/farm/pyblish_functions.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/pipeline/farm/pyblish_functions.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index b9a927f02d..b61007d0cb 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -619,8 +619,7 @@ def get_product_name_and_group_from_template( # remove 'aov' from data used to format group. See todo comment above # for possible solution. _dynamic_data = deepcopy(dynamic_data) or {} - if _dynamic_data["aov"]: - del _dynamic_data["aov"] + _dynamic_data.pop("aov", None) resulting_group_name = get_product_name( project_name=project_name, task_name=task_entity["name"], From cb4af77a429077bc92ead11bda6b50521e31f2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= <33513211+antirotor@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:37:29 +0200 Subject: [PATCH 053/106] Update client/ayon_core/pipeline/farm/pyblish_functions.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/pipeline/farm/pyblish_functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index b61007d0cb..f9ce2d3cf5 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -585,11 +585,11 @@ def _get_legacy_product_name_and_group( def get_product_name_and_group_from_template( - task_entity, project_name, - host_name, + task_entity, product_type, variant, + host_name, dynamic_data=None): """Get product name and group name from template. From e784c0073532414dfb5020af659954ef24c57db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= <33513211+antirotor@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:38:12 +0200 Subject: [PATCH 054/106] Update client/ayon_core/pipeline/farm/pyblish_functions.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/pipeline/farm/pyblish_functions.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index f9ce2d3cf5..e071d46321 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -855,12 +855,11 @@ def _collect_expected_files_for_aov(files): "to render, don't know what to do " "with them.") return rem[0] - else: - # but we really expect only one collection. - # Nothing else make sense. - if len(cols) != 1: - raise ValueError("Only one image sequence type is expected.") # noqa: E501 - return list(cols[0]) + # but we really expect only one collection. + # Nothing else make sense. + if len(cols) != 1: + raise ValueError("Only one image sequence type is expected.") # noqa: E501 + return list(cols[0]) def get_resources(project_name, version_entity, extension=None): From caf674c00827a0338b035a5d9c8b033124a2b25d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= <33513211+antirotor@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:38:28 +0200 Subject: [PATCH 055/106] Update client/ayon_core/pipeline/farm/pyblish_functions.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/pipeline/farm/pyblish_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index e071d46321..b218dc78e5 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -725,7 +725,7 @@ def _create_instances_for_aov(instance, skeleton, aov_filter, additional_data, project_name=instance.context.data["projectName"], host_name=instance.context.data["hostName"], product_type=skeleton["productType"], - variant=instance.data.get('variant', source_product_name), + variant=instance.data.get("variant", source_product_name), dynamic_data=dynamic_data ) From f752940c1175cfd2bd9665264e218ed0732622c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Mon, 19 Aug 2024 16:10:33 +0200 Subject: [PATCH 056/106] :memo: added help for product templates --- .../plugins/publish/help/validate_unique_subsets.xml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/plugins/publish/help/validate_unique_subsets.xml b/client/ayon_core/plugins/publish/help/validate_unique_subsets.xml index e163fc39fe..96b07979b7 100644 --- a/client/ayon_core/plugins/publish/help/validate_unique_subsets.xml +++ b/client/ayon_core/plugins/publish/help/validate_unique_subsets.xml @@ -11,7 +11,11 @@ Multiples instances from your scene are set to publish into the same folder > pr ### How to repair? -Remove the offending instances or rename to have a unique name. +Remove the offending instances or rename to have a unique name. Also, please + check your product name templates to ensure that resolved names are + sufficiently unique. You can find that settings: + + ayon+settings://core/tools/creator/product_name_profiles - \ No newline at end of file + From a39c96ea068463360ffa475f8b7c260262dbedac Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 19 Aug 2024 16:59:09 +0200 Subject: [PATCH 057/106] move some generic checks from iterator --- .../tools/publisher/models/publish.py | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/client/ayon_core/tools/publisher/models/publish.py b/client/ayon_core/tools/publisher/models/publish.py index ab8a041414..c909fd1ef2 100644 --- a/client/ayon_core/tools/publisher/models/publish.py +++ b/client/ayon_core/tools/publisher/models/publish.py @@ -829,7 +829,9 @@ def __init__(self, controller: AbstractPublisherBackend): ) # Plugin iterator - self._main_thread_iter: Iterable[partial] = self._default_iterator() + self._main_thread_iter: collections.abc.Generator[partial] = ( + self._default_iterator() + ) def reset(self): create_context = self._controller.get_create_context() @@ -898,17 +900,19 @@ def get_next_process_func(self) -> partial: # Validations of progress before using iterator # - same conditions may be inside iterator but they may be used # only in specific cases (e.g. when it happens for a first time) - if ( - # There are validation errors and validation is passed - # - can't do any progree - ( - self._publish_has_validated - and self._publish_has_validation_errors - ) # Any unexpected error happened # - everything should stop - or self._publish_has_crashed + self._publish_has_crashed + # Stop if validation is over and validation errors happened + # or publishing should stop at validation + or ( + self._publish_has_validated + and ( + self._publish_has_validation_errors + or self._publish_up_validation + ) + ) ): item = partial(self.stop_publish) @@ -1074,8 +1078,9 @@ def _default_iterator(self): Should be replaced by real iterator when 'reset' is called. - Yields: - partial: Function that will be called in main thread. + Returns: + collections.abc.Generator[partial]: Generator with partial + functions that should be called in main thread. """ while True: @@ -1117,18 +1122,6 @@ def _publish_iterator(self) -> Iterable[partial]: plugin.order >= self._validation_order ) - # Stop if plugin is over validation order and process - # should process up to validation. - if self._publish_up_validation and self._publish_has_validated: - yield partial(self.stop_publish) - - # Stop if validation is over and validation errors happened - if ( - self._publish_has_validated - and self.has_validation_errors() - ): - yield partial(self.stop_publish) - # Add plugin to publish report self._publish_report.add_plugin_iter( plugin.id, self._publish_context) From e271b06c9fe50b90275740a38cd162763f6d5b91 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 19 Aug 2024 17:00:52 +0200 Subject: [PATCH 058/106] simplify clear --- client/ayon_core/tools/publisher/control_qt.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/ayon_core/tools/publisher/control_qt.py b/client/ayon_core/tools/publisher/control_qt.py index b42b9afea3..f769fab91e 100644 --- a/client/ayon_core/tools/publisher/control_qt.py +++ b/client/ayon_core/tools/publisher/control_qt.py @@ -60,9 +60,8 @@ def stop(self): self._timer.stop() def clear(self): - if self._timer.isActive(): - self._timer.stop() self._items_to_process = collections.deque() + self.stop() class QtPublisherController(PublisherController): From 5442cacdc346b7ef1c34c5493f116ea82300d531 Mon Sep 17 00:00:00 2001 From: Robin De Lillo Date: Mon, 19 Aug 2024 11:08:44 -0400 Subject: [PATCH 059/106] Update client/ayon_core/lib/path_templates.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/lib/path_templates.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/ayon_core/lib/path_templates.py b/client/ayon_core/lib/path_templates.py index 3e3bdd8f78..33af503dd5 100644 --- a/client/ayon_core/lib/path_templates.py +++ b/client/ayon_core/lib/path_templates.py @@ -475,9 +475,9 @@ def validate_key_is_matched(key): bool: Openings and closing are valid. """ - opening = tuple("({[") - closing = tuple(")}]") - mapping = dict(zip(opening, closing)) + mapping = dict(zip("({[", ")}]")) + opening = set(mapping.keys()) + closing = set(mapping.values()) queue = [] for letter in key: From 29825b6d0ebaafe900cd55ee05a1ee4fadd19283 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 19 Aug 2024 17:11:01 +0200 Subject: [PATCH 060/106] more readable code --- .../tools/publisher/models/publish.py | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/client/ayon_core/tools/publisher/models/publish.py b/client/ayon_core/tools/publisher/models/publish.py index c909fd1ef2..c80e49d91f 100644 --- a/client/ayon_core/tools/publisher/models/publish.py +++ b/client/ayon_core/tools/publisher/models/publish.py @@ -898,29 +898,24 @@ def start_publish(self, wait: Optional[bool] = True): def get_next_process_func(self) -> partial: # Validations of progress before using iterator - # - same conditions may be inside iterator but they may be used - # only in specific cases (e.g. when it happens for a first time) + # Any unexpected error happened + # - everything should stop + if self._publish_has_crashed: + return partial(self.stop_publish) + + # Stop if validation is over and validation errors happened + # or publishing should stop at validation if ( - # Any unexpected error happened - # - everything should stop - self._publish_has_crashed - # Stop if validation is over and validation errors happened - # or publishing should stop at validation - or ( - self._publish_has_validated - and ( - self._publish_has_validation_errors - or self._publish_up_validation - ) + self._publish_has_validated + and ( + self._publish_has_validation_errors + or self._publish_up_validation ) ): - item = partial(self.stop_publish) + return partial(self.stop_publish) # Everything is ok so try to get new processing item - else: - item = next(self._main_thread_iter) - - return item + return next(self._main_thread_iter) def stop_publish(self): if self._publish_is_running: From 4041d7b8705879df0a8d9667c5d6143af1c617de Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 19 Aug 2024 17:11:27 +0200 Subject: [PATCH 061/106] raise error when 'get_next_process_func' is called and publishing did not start --- client/ayon_core/tools/publisher/models/publish.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/ayon_core/tools/publisher/models/publish.py b/client/ayon_core/tools/publisher/models/publish.py index c80e49d91f..3bd6b33f49 100644 --- a/client/ayon_core/tools/publisher/models/publish.py +++ b/client/ayon_core/tools/publisher/models/publish.py @@ -897,6 +897,11 @@ def start_publish(self, wait: Optional[bool] = True): func() def get_next_process_func(self) -> partial: + # Raise error if this function is called when publishing + # is not running + if not self._publish_is_running: + raise ValueError("Publish is not running") + # Validations of progress before using iterator # Any unexpected error happened # - everything should stop From 9331187000e18c70d4a1d38f159f0ebc4c483f6b Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:09:29 +0200 Subject: [PATCH 062/106] ProcessContext also has information about preparation state --- client/ayon_core/addon/base.py | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/client/ayon_core/addon/base.py b/client/ayon_core/addon/base.py index 383703e2bc..41ba7d4a0e 100644 --- a/client/ayon_core/addon/base.py +++ b/client/ayon_core/addon/base.py @@ -116,6 +116,47 @@ def __init__( if kwargs: unknown_keys = ", ".join([f'"{key}"' for key in kwargs.keys()]) print(f"Unknown keys in ProcessContext: {unknown_keys}") + self._prepared: bool = False + self._exception: Optional[Exception] = None + + def is_prepared(self) -> bool: + """Preparation of process finished. + + Returns: + bool: Preparation is done. + """ + return self._prepared + + def set_prepared(self): + """Mark process as prepared.""" + self._prepared = True + + def preparation_failed(self) -> bool: + """Preparation failed. + + Returns: + bool: Preparation failed. + + """ + return self._exception is not None + + def get_exception(self) -> Optional[Exception]: + """Get exception that occurred during preparation. + + Returns: + Optional[Exception]: Exception that caused preparation fail. + + """ + return self._exception + + def set_exception(self, exception: Exception): + """Set exception that occurred during preparation. + + Args: + exception (Exception): Exception that caused preparation fail. + + """ + self._exception = exception # Inherit from `object` for Python 2 hosts From 501cacc4b8e5e081d7211ddae7a11ad492348e3c Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:09:46 +0200 Subject: [PATCH 063/106] change state of context when is done --- client/ayon_core/addon/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/ayon_core/addon/utils.py b/client/ayon_core/addon/utils.py index ac5ff25984..5f6922b924 100644 --- a/client/ayon_core/addon/utils.py +++ b/client/ayon_core/addon/utils.py @@ -134,6 +134,8 @@ def ensure_addons_are_process_context_ready( failed = True break + process_context.set_prepared() + process_context.set_exception(exception) output_str = output.getvalue() # Print stdout/stderr to console as it was redirected print(output_str) From 8e9c28a84a416d51169ccc160d269481b4a026b0 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:10:02 +0200 Subject: [PATCH 064/106] 'ensure_addons_are_process_ready' returns ProcessContext --- client/ayon_core/addon/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/addon/utils.py b/client/ayon_core/addon/utils.py index 5f6922b924..b301c70564 100644 --- a/client/ayon_core/addon/utils.py +++ b/client/ayon_core/addon/utils.py @@ -161,7 +161,7 @@ def ensure_addons_are_process_ready( addons_manager: Optional[AddonsManager] = None, exit_on_failure: bool = True, **kwargs, -) -> Optional[Exception]: +) -> ProcessContext: """Ensure all enabled addons are ready to be used in the given context. Call this method only in AYON launcher process and as first thing @@ -181,6 +181,7 @@ def ensure_addons_are_process_ready( """ context: ProcessContext = ProcessContext(**kwargs) - return ensure_addons_are_process_context_ready( + ensure_addons_are_process_context_ready( context, addons_manager, exit_on_failure ) + return context From f3cccccab73bc58e0b8c9daa53ebd9b37b80e74c Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:10:16 +0200 Subject: [PATCH 065/106] do not return exception on fail --- client/ayon_core/addon/utils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/addon/utils.py b/client/ayon_core/addon/utils.py index b301c70564..0481ed4cad 100644 --- a/client/ayon_core/addon/utils.py +++ b/client/ayon_core/addon/utils.py @@ -72,7 +72,7 @@ def ensure_addons_are_process_context_ready( process_context: ProcessContext, addons_manager: Optional[AddonsManager] = None, exit_on_failure: bool = True, -) -> Optional[Exception]: +): """Ensure all enabled addons are ready to be used in the given context. Call this method only in AYON launcher process and as first thing @@ -152,9 +152,8 @@ def ensure_addons_are_process_context_ready( detail = output_str _handle_error(process_context, message, detail) - if not exit_on_failure: - return exception - sys.exit(1) + if exit_on_failure: + sys.exit(1) def ensure_addons_are_process_ready( From 2b46eee1dd2d074e979923ba313086cbbd90a271 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:19:52 +0200 Subject: [PATCH 066/106] added ProcessContext arguments to 'ensure_addons_are_process_ready' --- client/ayon_core/addon/base.py | 3 ++- client/ayon_core/addon/utils.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/addon/base.py b/client/ayon_core/addon/base.py index 41ba7d4a0e..e5b5087423 100644 --- a/client/ayon_core/addon/base.py +++ b/client/ayon_core/addon/base.py @@ -94,7 +94,8 @@ class ProcessContext: project_name (Optional[str]): Project name. Can be filled in case process is triggered for specific project. Some addons can have different behavior based on project. - headless (Optional[bool]): Is process running in headless mode. + headless (Optional[bool]): Is process running in headless mode. Value + is filled with value based on state set in AYON launcher. """ def __init__( diff --git a/client/ayon_core/addon/utils.py b/client/ayon_core/addon/utils.py index 0481ed4cad..ad04586019 100644 --- a/client/ayon_core/addon/utils.py +++ b/client/ayon_core/addon/utils.py @@ -157,6 +157,10 @@ def ensure_addons_are_process_context_ready( def ensure_addons_are_process_ready( + addon_name: Optional[str] = None, + addon_version: Optional[str] = None, + project_name: Optional[str] = None, + headless: Optional[bool] = None, addons_manager: Optional[AddonsManager] = None, exit_on_failure: bool = True, **kwargs, @@ -168,6 +172,13 @@ def ensure_addons_are_process_ready( should not be created. Args: + addon_name (Optional[str]): Addon name which triggered process. + addon_version (Optional[str]): Addon version which triggered process. + project_name (Optional[str]): Project name. Can be filled in case + process is triggered for specific project. Some addons can have + different behavior based on project. + headless (Optional[bool]): Is process running in headless mode. Value + is filled with value based on state set in AYON launcher. addons_manager (Optional[AddonsManager]): The addons manager to use. If not provided, a new one will be created. exit_on_failure (bool, optional): If True, the process will exit @@ -179,7 +190,13 @@ def ensure_addons_are_process_ready( preparation, if any. """ - context: ProcessContext = ProcessContext(**kwargs) + context: ProcessContext = ProcessContext( + addon_name, + addon_version, + project_name, + headless, + **kwargs + ) ensure_addons_are_process_context_ready( context, addons_manager, exit_on_failure ) From d983879ccd7f4215c63d9baa52b4e0b16607c62e Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:39:56 +0200 Subject: [PATCH 067/106] added comment to project name --- client/ayon_core/addon/base.py | 2 +- client/ayon_core/addon/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/addon/base.py b/client/ayon_core/addon/base.py index e5b5087423..5662375c0a 100644 --- a/client/ayon_core/addon/base.py +++ b/client/ayon_core/addon/base.py @@ -93,7 +93,7 @@ class ProcessContext: addon_version (Optional[str]): Addon version which triggered process. project_name (Optional[str]): Project name. Can be filled in case process is triggered for specific project. Some addons can have - different behavior based on project. + different behavior based on project. Value is NOT autofilled. headless (Optional[bool]): Is process running in headless mode. Value is filled with value based on state set in AYON launcher. diff --git a/client/ayon_core/addon/utils.py b/client/ayon_core/addon/utils.py index ad04586019..43118bff7e 100644 --- a/client/ayon_core/addon/utils.py +++ b/client/ayon_core/addon/utils.py @@ -176,7 +176,7 @@ def ensure_addons_are_process_ready( addon_version (Optional[str]): Addon version which triggered process. project_name (Optional[str]): Project name. Can be filled in case process is triggered for specific project. Some addons can have - different behavior based on project. + different behavior based on project. Value is NOT autofilled. headless (Optional[bool]): Is process running in headless mode. Value is filled with value based on state set in AYON launcher. addons_manager (Optional[AddonsManager]): The addons From eb4407b9efb55bf76bdb5b8040422f943bc2410f Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:57:56 +0200 Subject: [PATCH 068/106] fix returns in docstrings --- client/ayon_core/addon/utils.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/client/ayon_core/addon/utils.py b/client/ayon_core/addon/utils.py index 43118bff7e..f2441e37be 100644 --- a/client/ayon_core/addon/utils.py +++ b/client/ayon_core/addon/utils.py @@ -87,10 +87,6 @@ def ensure_addons_are_process_context_ready( exit_on_failure (bool, optional): If True, the process will exit if an error occurs. Defaults to True. - Returns: - Optional[Exception]: The exception that occurred during the - preparation, if any. - """ if addons_manager is None: addons_manager = AddonsManager() @@ -186,7 +182,7 @@ def ensure_addons_are_process_ready( kwargs: The keyword arguments to pass to the ProcessContext. Returns: - Optional[Exception]: The exception that occurred during the + ProcessContext: The exception that occurred during the preparation, if any. """ From 92ce331a302c26a6a9a9fd47361269225d07b098 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 18:45:54 +0200 Subject: [PATCH 069/106] added 'is_headless_mode_enabled' function --- client/ayon_core/addon/base.py | 4 ++-- client/ayon_core/lib/__init__.py | 2 ++ client/ayon_core/lib/ayon_info.py | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/addon/base.py b/client/ayon_core/addon/base.py index 5662375c0a..6343166ac8 100644 --- a/client/ayon_core/addon/base.py +++ b/client/ayon_core/addon/base.py @@ -20,6 +20,7 @@ Logger, is_dev_mode_enabled, get_launcher_storage_dir, + is_headless_mode_enabled, ) from ayon_core.settings import get_studio_settings @@ -107,8 +108,7 @@ def __init__( **kwargs, ): if headless is None: - # TODO use lib function to get headless mode - headless = os.getenv("AYON_HEADLESS_MODE") == "1" + headless = is_headless_mode_enabled() self.addon_name: Optional[str] = addon_name self.addon_version: Optional[str] = addon_version self.project_name: Optional[str] = project_name diff --git a/client/ayon_core/lib/__init__.py b/client/ayon_core/lib/__init__.py index d4b161031e..0074c4d2bd 100644 --- a/client/ayon_core/lib/__init__.py +++ b/client/ayon_core/lib/__init__.py @@ -132,6 +132,7 @@ is_in_ayon_launcher_process, is_running_from_build, is_using_ayon_console, + is_headless_mode_enabled, is_staging_enabled, is_dev_mode_enabled, is_in_tests, @@ -245,6 +246,7 @@ "is_in_ayon_launcher_process", "is_running_from_build", "is_using_ayon_console", + "is_headless_mode_enabled", "is_staging_enabled", "is_dev_mode_enabled", "is_in_tests", diff --git a/client/ayon_core/lib/ayon_info.py b/client/ayon_core/lib/ayon_info.py index c4333fab95..7e194a824e 100644 --- a/client/ayon_core/lib/ayon_info.py +++ b/client/ayon_core/lib/ayon_info.py @@ -78,6 +78,10 @@ def is_using_ayon_console(): return "ayon_console" in executable_filename +def is_headless_mode_enabled(): + return os.getenv("AYON_HEADLESS_MODE") == "1" + + def is_staging_enabled(): return os.getenv("AYON_USE_STAGING") == "1" From 3bc993399117f5690d6597a26947603fafa8d206 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 19:10:57 +0200 Subject: [PATCH 070/106] return bool all the time --- client/ayon_core/addon/utils.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/client/ayon_core/addon/utils.py b/client/ayon_core/addon/utils.py index f2441e37be..31cb128e4b 100644 --- a/client/ayon_core/addon/utils.py +++ b/client/ayon_core/addon/utils.py @@ -72,7 +72,7 @@ def ensure_addons_are_process_context_ready( process_context: ProcessContext, addons_manager: Optional[AddonsManager] = None, exit_on_failure: bool = True, -): +) -> bool: """Ensure all enabled addons are ready to be used in the given context. Call this method only in AYON launcher process and as first thing @@ -87,6 +87,9 @@ def ensure_addons_are_process_context_ready( exit_on_failure (bool, optional): If True, the process will exit if an error occurs. Defaults to True. + Returns: + bool: True if all addons are ready, False otherwise. + """ if addons_manager is None: addons_manager = AddonsManager() @@ -138,7 +141,7 @@ def ensure_addons_are_process_context_ready( if not failed: if not process_context.headless: _start_tray() - return None + return True detail = None if use_detail: @@ -150,6 +153,7 @@ def ensure_addons_are_process_context_ready( _handle_error(process_context, message, detail) if exit_on_failure: sys.exit(1) + return False def ensure_addons_are_process_ready( @@ -160,7 +164,7 @@ def ensure_addons_are_process_ready( addons_manager: Optional[AddonsManager] = None, exit_on_failure: bool = True, **kwargs, -) -> ProcessContext: +) -> bool: """Ensure all enabled addons are ready to be used in the given context. Call this method only in AYON launcher process and as first thing @@ -182,8 +186,7 @@ def ensure_addons_are_process_ready( kwargs: The keyword arguments to pass to the ProcessContext. Returns: - ProcessContext: The exception that occurred during the - preparation, if any. + bool: True if all addons are ready, False otherwise. """ context: ProcessContext = ProcessContext( @@ -193,7 +196,6 @@ def ensure_addons_are_process_ready( headless, **kwargs ) - ensure_addons_are_process_context_ready( + return ensure_addons_are_process_context_ready( context, addons_manager, exit_on_failure ) - return context From 173b2f27272cb408e4ae496eb5fe40bf3eb4c266 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 19:14:22 +0200 Subject: [PATCH 071/106] remove ProcessContext methods --- client/ayon_core/addon/base.py | 41 --------------------------------- client/ayon_core/addon/utils.py | 7 +----- 2 files changed, 1 insertion(+), 47 deletions(-) diff --git a/client/ayon_core/addon/base.py b/client/ayon_core/addon/base.py index 6343166ac8..e627fb2b38 100644 --- a/client/ayon_core/addon/base.py +++ b/client/ayon_core/addon/base.py @@ -117,47 +117,6 @@ def __init__( if kwargs: unknown_keys = ", ".join([f'"{key}"' for key in kwargs.keys()]) print(f"Unknown keys in ProcessContext: {unknown_keys}") - self._prepared: bool = False - self._exception: Optional[Exception] = None - - def is_prepared(self) -> bool: - """Preparation of process finished. - - Returns: - bool: Preparation is done. - """ - return self._prepared - - def set_prepared(self): - """Mark process as prepared.""" - self._prepared = True - - def preparation_failed(self) -> bool: - """Preparation failed. - - Returns: - bool: Preparation failed. - - """ - return self._exception is not None - - def get_exception(self) -> Optional[Exception]: - """Get exception that occurred during preparation. - - Returns: - Optional[Exception]: Exception that caused preparation fail. - - """ - return self._exception - - def set_exception(self, exception: Exception): - """Set exception that occurred during preparation. - - Args: - exception (Exception): Exception that caused preparation fail. - - """ - self._exception = exception # Inherit from `object` for Python 2 hosts diff --git a/client/ayon_core/addon/utils.py b/client/ayon_core/addon/utils.py index 31cb128e4b..32b42bf1e2 100644 --- a/client/ayon_core/addon/utils.py +++ b/client/ayon_core/addon/utils.py @@ -94,7 +94,6 @@ def ensure_addons_are_process_context_ready( if addons_manager is None: addons_manager = AddonsManager() - exception = None message = None failed = False use_detail = False @@ -111,13 +110,11 @@ def ensure_addons_are_process_context_ready( addon.ensure_is_process_ready(process_context) addon_failed = False except ProcessPreparationError as exc: - exception = exc message = str(exc) print(f"Addon preparation failed: '{addon.name}'") print(message) - except BaseException as exc: - exception = exc + except BaseException: use_detail = True message = "An unexpected error occurred." formatted_traceback = "".join(traceback.format_exception( @@ -133,8 +130,6 @@ def ensure_addons_are_process_context_ready( failed = True break - process_context.set_prepared() - process_context.set_exception(exception) output_str = output.getvalue() # Print stdout/stderr to console as it was redirected print(output_str) From 9260a80cb0becbf322a78ad431a7de45b8f29836 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 19:14:53 +0200 Subject: [PATCH 072/106] require addon name and version --- client/ayon_core/addon/base.py | 29 +++++++++++++++++------------ client/ayon_core/addon/utils.py | 8 ++++---- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/client/ayon_core/addon/base.py b/client/ayon_core/addon/base.py index e627fb2b38..494c0f3da7 100644 --- a/client/ayon_core/addon/base.py +++ b/client/ayon_core/addon/base.py @@ -81,17 +81,22 @@ class ProcessPreparationError(Exception): class ProcessContext: - """Context of child process. + """Hold context of process that is going to be started. - Notes: - This class is used to pass context to child process. It can be used - to use different behavior of addon based on information in - the context. - The context can be enhanced in future versions. + Right now the context is simple, having information about addon that wants + to trigger preparation and possibly project name for which it should + happen. + + Preparation for process can be required for ayon-core or any other addon. + It can be, change of environment variables, or request login to + a project management. + + At the moment of creation is 'ProcessContext' only data holder, but that + might change in future if there will be need. Args: - addon_name (Optional[str]): Addon name which triggered process. - addon_version (Optional[str]): Addon version which triggered process. + addon_name (str): Addon name which triggered process. + addon_version (str): Addon version which triggered process. project_name (Optional[str]): Project name. Can be filled in case process is triggered for specific project. Some addons can have different behavior based on project. Value is NOT autofilled. @@ -101,16 +106,16 @@ class ProcessContext: """ def __init__( self, - addon_name: Optional[str] = None, - addon_version: Optional[str] = None, + addon_name: str = None, + addon_version: str = None, project_name: Optional[str] = None, headless: Optional[bool] = None, **kwargs, ): if headless is None: headless = is_headless_mode_enabled() - self.addon_name: Optional[str] = addon_name - self.addon_version: Optional[str] = addon_version + self.addon_name: str = addon_name + self.addon_version: str = addon_version self.project_name: Optional[str] = project_name self.headless: bool = headless diff --git a/client/ayon_core/addon/utils.py b/client/ayon_core/addon/utils.py index 32b42bf1e2..1dea4cc4fe 100644 --- a/client/ayon_core/addon/utils.py +++ b/client/ayon_core/addon/utils.py @@ -152,8 +152,8 @@ def ensure_addons_are_process_context_ready( def ensure_addons_are_process_ready( - addon_name: Optional[str] = None, - addon_version: Optional[str] = None, + addon_name: str, + addon_version: str, project_name: Optional[str] = None, headless: Optional[bool] = None, addons_manager: Optional[AddonsManager] = None, @@ -167,8 +167,8 @@ def ensure_addons_are_process_ready( should not be created. Args: - addon_name (Optional[str]): Addon name which triggered process. - addon_version (Optional[str]): Addon version which triggered process. + addon_name (str): Addon name which triggered process. + addon_version (str): Addon version which triggered process. project_name (Optional[str]): Project name. Can be filled in case process is triggered for specific project. Some addons can have different behavior based on project. Value is NOT autofilled. From e5eefc81fc10db24c232157eb0ab0b08b5ef5017 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 19:15:07 +0200 Subject: [PATCH 073/106] added todo --- client/ayon_core/addon/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/ayon_core/addon/utils.py b/client/ayon_core/addon/utils.py index 1dea4cc4fe..8e8c2bd8d7 100644 --- a/client/ayon_core/addon/utils.py +++ b/client/ayon_core/addon/utils.py @@ -79,6 +79,10 @@ def ensure_addons_are_process_context_ready( to avoid possible clashes with preparation. For example 'QApplication' should not be created. + Todos: + Run all preparations and allow to "ignore" failed preparations. + Right now single addon can block using certain actions. + Args: process_context (ProcessContext): The context in which the addons should be prepared. From e0339aeb104c13b8aada5a728d67104d3041dc3e Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 20 Aug 2024 19:25:45 +0200 Subject: [PATCH 074/106] require addons_manager and exit_on_failure as kwargs --- client/ayon_core/addon/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/client/ayon_core/addon/utils.py b/client/ayon_core/addon/utils.py index 8e8c2bd8d7..f983e37d3c 100644 --- a/client/ayon_core/addon/utils.py +++ b/client/ayon_core/addon/utils.py @@ -160,6 +160,7 @@ def ensure_addons_are_process_ready( addon_version: str, project_name: Optional[str] = None, headless: Optional[bool] = None, + *, addons_manager: Optional[AddonsManager] = None, exit_on_failure: bool = True, **kwargs, From 723198c2a03be93e4408c5c4179bc48b8724ca5d Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:19:12 +0200 Subject: [PATCH 075/106] use 'title' instead of 'topic' --- server/settings/publish_plugins.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/settings/publish_plugins.py b/server/settings/publish_plugins.py index a5ea7bd762..8ca96432f4 100644 --- a/server/settings/publish_plugins.py +++ b/server/settings/publish_plugins.py @@ -562,12 +562,12 @@ class ExtractBurninDef(BaseSettingsModel): _isGroup = True _layout = "expanded" name: str = SettingsField("") - TOP_LEFT: str = SettingsField("", topic="Top Left") - TOP_CENTERED: str = SettingsField("", topic="Top Centered") - TOP_RIGHT: str = SettingsField("", topic="Top Right") - BOTTOM_LEFT: str = SettingsField("", topic="Bottom Left") - BOTTOM_CENTERED: str = SettingsField("", topic="Bottom Centered") - BOTTOM_RIGHT: str = SettingsField("", topic="Bottom Right") + TOP_LEFT: str = SettingsField("", title="Top Left") + TOP_CENTERED: str = SettingsField("", title="Top Centered") + TOP_RIGHT: str = SettingsField("", title="Top Right") + BOTTOM_LEFT: str = SettingsField("", title="Bottom Left") + BOTTOM_CENTERED: str = SettingsField("", title="Bottom Centered") + BOTTOM_RIGHT: str = SettingsField("", title="Bottom Right") filter: ExtractBurninDefFilter = SettingsField( default_factory=ExtractBurninDefFilter, title="Additional filtering" From 725584a8dbb9b29e7dc1f675cf2c174efc268d9d Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:29:56 +0200 Subject: [PATCH 076/106] require addon name/version Co-authored-by: Roy Nieterau --- client/ayon_core/addon/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/addon/base.py b/client/ayon_core/addon/base.py index 494c0f3da7..7f0636ccca 100644 --- a/client/ayon_core/addon/base.py +++ b/client/ayon_core/addon/base.py @@ -106,8 +106,8 @@ class ProcessContext: """ def __init__( self, - addon_name: str = None, - addon_version: str = None, + addon_name: str, + addon_version: str, project_name: Optional[str] = None, headless: Optional[bool] = None, **kwargs, From 8dd1843be107919f01e9fdbd5baf1df297191854 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:52:40 +0200 Subject: [PATCH 077/106] implemented helper line edit with options --- client/ayon_core/style/style.css | 25 ++++++ client/ayon_core/tools/utils/widgets.py | 115 ++++++++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/client/ayon_core/style/style.css b/client/ayon_core/style/style.css index 607fd1fa31..2c826f16a4 100644 --- a/client/ayon_core/style/style.css +++ b/client/ayon_core/style/style.css @@ -739,6 +739,31 @@ OverlayMessageWidget QWidget { background: transparent; } +/* Hinted Line Edit */ +#HintedLineEditInput { + border-radius: 0.2em; + border-top-right-radius: 0px; + border-bottom-right-radius: 0px; + border: 1px solid {color:border}; +} +#HintedLineEditInput:hover { + border-color: {color:border-hover}; +} +#HintedLineEditInput:focus{ + border-color: {color:border-focus}; +} +#HintedLineEditInput:disabled { + background: {color:bg-inputs-disabled}; +} +#HintedLineEditButton { + border: none; + border-radius: 0.2em; + border-bottom-left-radius: 0px; + border-top-left-radius: 0px; + padding: 0px; + qproperty-iconSize: 11px 11px; +} + /* Password dialog*/ #PasswordBtn { border: none; diff --git a/client/ayon_core/tools/utils/widgets.py b/client/ayon_core/tools/utils/widgets.py index 28331fbc35..2065246190 100644 --- a/client/ayon_core/tools/utils/widgets.py +++ b/client/ayon_core/tools/utils/widgets.py @@ -1,4 +1,5 @@ import logging +from typing import Optional, List from qtpy import QtWidgets, QtCore, QtGui import qargparse @@ -104,6 +105,120 @@ def __init__(self, *args, **kwargs): self.setPalette(filter_palette) +def get_down_arrow_icon() -> QtGui.QIcon: + normal_pixmap = QtGui.QPixmap( + get_style_image_path("down_arrow") + ) + on_pixmap = QtGui.QPixmap( + get_style_image_path("down_arrow_on") + ) + disabled_pixmap = QtGui.QPixmap( + get_style_image_path("down_arrow_disabled") + ) + icon = QtGui.QIcon(normal_pixmap) + icon.addPixmap(on_pixmap, QtGui.QIcon.Active) + icon.addPixmap(disabled_pixmap, QtGui.QIcon.Disabled) + return icon + + +class HintedLineEdit(QtWidgets.QWidget): + returnPressed = QtCore.Signal() + textChanged = QtCore.Signal(str) + textEdited = QtCore.Signal(str) + + def __init__( + self, + options: Optional[List[str]] = None, + parent: Optional[QtWidgets.QWidget] = None + ): + super().__init__(parent) + + text_input = PlaceholderLineEdit(self) + options_button = QtWidgets.QPushButton(self) + + text_input.setObjectName("HintedLineEditInput") + options_button.setObjectName("HintedLineEditButton") + options_button.setIcon(get_down_arrow_icon()) + + main_layout = QtWidgets.QHBoxLayout(self) + main_layout.setContentsMargins(0, 0, 0, 0) + main_layout.setSpacing(0) + main_layout.addWidget(text_input, 1) + main_layout.addWidget(options_button, 0) + + # Expand line edit and button vertically so they have same height + for widget in (text_input, options_button): + w_size_policy = widget.sizePolicy() + w_size_policy.setVerticalPolicy( + QtWidgets.QSizePolicy.MinimumExpanding) + widget.setSizePolicy(w_size_policy) + + # Set size hint of this frame to fixed so size hint height is + # used as fixed height + size_policy = self.sizePolicy() + size_policy.setVerticalPolicy(QtWidgets.QSizePolicy.Fixed) + self.setSizePolicy(size_policy) + + text_input.returnPressed.connect(self.returnPressed) + text_input.textChanged.connect(self.textChanged) + text_input.textEdited.connect(self.textEdited) + options_button.clicked.connect(self._on_options_button_clicked) + + self._text_input = text_input + self._options_button = options_button + self._options = None + + # Set default state + self.set_options(options) + + def text(self) -> str: + return self._text_input.text() + + def setText(self, text: str): + self._text_input.setText(text) + + def setPlaceholderText(self, text: str): + self._text_input.setPlaceholderText(text) + + def placeholderText(self) -> str: + return self._text_input.placeholderText() + + def setReadOnly(self, state: bool): + self._text_input.setReadOnly(state) + + def setIcon(self, icon: QtGui.QIcon): + self._options_button.setIcon(icon) + + def set_options(self, options: Optional[List[str]] = None): + self._options = options + self._options_button.setEnabled(bool(options)) + + def sizeHint(self) -> QtCore.QSize: + hint = super().sizeHint() + tsz = self._text_input.sizeHint() + bsz = self._options_button.sizeHint() + hint.setHeight(max(tsz.height(), bsz.height())) + return hint + + def _on_options_button_clicked(self): + if not self._options: + return + + menu = QtWidgets.QMenu(self) + for option in self._options: + action = menu.addAction(option) + action.triggered.connect(self._on_option_action) + + rect = self._options_button.rect() + pos = self._options_button.mapToGlobal(rect.bottomLeft()) + menu.exec_(pos) + + def _on_option_action(self): + action = self.sender() + if action: + self.setText(action.text()) + + class ExpandingTextEdit(QtWidgets.QTextEdit): """QTextEdit which does not have sroll area but expands height.""" From 7e12163c7a78dfd0dd7157d1760232ab0808a7c2 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:25:54 +0200 Subject: [PATCH 078/106] added options to pass separator --- client/ayon_core/tools/utils/widgets.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/tools/utils/widgets.py b/client/ayon_core/tools/utils/widgets.py index 2065246190..e3ff42a102 100644 --- a/client/ayon_core/tools/utils/widgets.py +++ b/client/ayon_core/tools/utils/widgets.py @@ -1,5 +1,5 @@ import logging -from typing import Optional, List +from typing import Optional, List, Set from qtpy import QtWidgets, QtCore, QtGui import qargparse @@ -122,6 +122,7 @@ def get_down_arrow_icon() -> QtGui.QIcon: class HintedLineEdit(QtWidgets.QWidget): + SEPARATORS: Set[str] = {"---", "---separator---"} returnPressed = QtCore.Signal() textChanged = QtCore.Signal(str) textEdited = QtCore.Signal(str) @@ -206,6 +207,9 @@ def _on_options_button_clicked(self): menu = QtWidgets.QMenu(self) for option in self._options: + if option in self.SEPARATORS: + menu.addSeparator() + continue action = menu.addAction(option) action.triggered.connect(self._on_option_action) From 54665ba72b5732da893712586359f95ee3298ac1 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:26:01 +0200 Subject: [PATCH 079/106] handle tooltips --- client/ayon_core/tools/utils/widgets.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/ayon_core/tools/utils/widgets.py b/client/ayon_core/tools/utils/widgets.py index e3ff42a102..8109130c27 100644 --- a/client/ayon_core/tools/utils/widgets.py +++ b/client/ayon_core/tools/utils/widgets.py @@ -190,6 +190,12 @@ def setReadOnly(self, state: bool): def setIcon(self, icon: QtGui.QIcon): self._options_button.setIcon(icon) + def setToolTip(self, text: str): + self._text_input.setToolTip(text) + + def set_button_tool_tip(self, text: str): + self._options_button.setToolTip(text) + def set_options(self, options: Optional[List[str]] = None): self._options = options self._options_button.setEnabled(bool(options)) From bf48d9e804f0b66b29ddaa417f28cf0bbb253c50 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:26:16 +0200 Subject: [PATCH 080/106] added 'HintedLineEdit' to utils init file --- client/ayon_core/tools/utils/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/ayon_core/tools/utils/__init__.py b/client/ayon_core/tools/utils/__init__.py index 4b5fbeaf67..059ac28b7b 100644 --- a/client/ayon_core/tools/utils/__init__.py +++ b/client/ayon_core/tools/utils/__init__.py @@ -5,6 +5,7 @@ ComboBox, CustomTextComboBox, PlaceholderLineEdit, + HintedLineEdit, ExpandingTextEdit, BaseClickableFrame, ClickableFrame, @@ -88,6 +89,7 @@ "ComboBox", "CustomTextComboBox", "PlaceholderLineEdit", + "HintedLineEdit", "ExpandingTextEdit", "BaseClickableFrame", "ClickableFrame", From 8a9d815278746f5b49cf09b4cb50e8b5647b4a7e Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 11:29:44 +0200 Subject: [PATCH 081/106] use class name over object name for formatting --- client/ayon_core/style/style.css | 10 +++++----- client/ayon_core/tools/utils/widgets.py | 15 ++++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/client/ayon_core/style/style.css b/client/ayon_core/style/style.css index 2c826f16a4..1af355ac7b 100644 --- a/client/ayon_core/style/style.css +++ b/client/ayon_core/style/style.css @@ -740,22 +740,22 @@ OverlayMessageWidget QWidget { } /* Hinted Line Edit */ -#HintedLineEditInput { +HintedLineEditInput { border-radius: 0.2em; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border: 1px solid {color:border}; } -#HintedLineEditInput:hover { +HintedLineEditInput:hover { border-color: {color:border-hover}; } -#HintedLineEditInput:focus{ +HintedLineEditInput:focus{ border-color: {color:border-focus}; } -#HintedLineEditInput:disabled { +HintedLineEditInput:disabled { background: {color:bg-inputs-disabled}; } -#HintedLineEditButton { +HintedLineEditButton { border: none; border-radius: 0.2em; border-bottom-left-radius: 0px; diff --git a/client/ayon_core/tools/utils/widgets.py b/client/ayon_core/tools/utils/widgets.py index 8109130c27..008f48c502 100644 --- a/client/ayon_core/tools/utils/widgets.py +++ b/client/ayon_core/tools/utils/widgets.py @@ -121,6 +121,14 @@ def get_down_arrow_icon() -> QtGui.QIcon: return icon +class HintedLineEditInput(PlaceholderLineEdit): + pass + + +class HintedLineEditButton(QtWidgets.QPushButton): + pass + + class HintedLineEdit(QtWidgets.QWidget): SEPARATORS: Set[str] = {"---", "---separator---"} returnPressed = QtCore.Signal() @@ -134,11 +142,8 @@ def __init__( ): super().__init__(parent) - text_input = PlaceholderLineEdit(self) - options_button = QtWidgets.QPushButton(self) - - text_input.setObjectName("HintedLineEditInput") - options_button.setObjectName("HintedLineEditButton") + text_input = HintedLineEditInput(self) + options_button = HintedLineEditButton(self) options_button.setIcon(get_down_arrow_icon()) main_layout = QtWidgets.QHBoxLayout(self) From c8880a87d63fcdd5af69ed1f95ba9910d2970527 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 12:11:58 +0200 Subject: [PATCH 082/106] added option to change style of the widget --- client/ayon_core/tools/utils/widgets.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/tools/utils/widgets.py b/client/ayon_core/tools/utils/widgets.py index 008f48c502..184465ee1b 100644 --- a/client/ayon_core/tools/utils/widgets.py +++ b/client/ayon_core/tools/utils/widgets.py @@ -1,5 +1,5 @@ import logging -from typing import Optional, List, Set +from typing import Optional, List, Set, Any from qtpy import QtWidgets, QtCore, QtGui import qargparse @@ -12,7 +12,7 @@ ) from ayon_core.lib.attribute_definitions import AbstractAttrDef -from .lib import get_qta_icon_by_name_and_color +from .lib import get_qta_icon_by_name_and_color, set_style_property log = logging.getLogger(__name__) @@ -121,6 +121,7 @@ def get_down_arrow_icon() -> QtGui.QIcon: return icon +# These are placeholders for adding style class HintedLineEditInput(PlaceholderLineEdit): pass @@ -212,6 +213,21 @@ def sizeHint(self) -> QtCore.QSize: hint.setHeight(max(tsz.height(), bsz.height())) return hint + # Adds ability to change style of the widgets + # - because style change of the 'HintedLineEdit' may not propagate + # correctly 'HintedLineEditInput' and 'HintedLineEditButton' + def set_text_widget_object_name(self, name: str): + self._text_input.setObjectName(name) + + def set_text_widget_property(self, name: str, value: Any): + set_style_property(self._text_input, name, value) + + def set_button_widget_object_name(self, name: str): + self._text_input.setObjectName(name) + + def set_button_widget_property(self, name: str, value: Any): + set_style_property(self._options_button, name, value) + def _on_options_button_clicked(self): if not self._options: return From 9524aadeb2db0aa9c8cb37cea68f87521e2cb507 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 12:13:49 +0200 Subject: [PATCH 083/106] use 'HintedLineEdit' in publisher --- client/ayon_core/style/style.css | 11 --- .../tools/publisher/widgets/create_widget.py | 98 +++++-------------- 2 files changed, 22 insertions(+), 87 deletions(-) diff --git a/client/ayon_core/style/style.css b/client/ayon_core/style/style.css index 1af355ac7b..0857bc80c6 100644 --- a/client/ayon_core/style/style.css +++ b/client/ayon_core/style/style.css @@ -994,17 +994,6 @@ PixmapButton:disabled { #PublishLogConsole { font-family: "Noto Sans Mono"; } -#VariantInputsWidget QLineEdit { - border-bottom-right-radius: 0px; - border-top-right-radius: 0px; -} -#VariantInputsWidget QToolButton { - border-bottom-left-radius: 0px; - border-top-left-radius: 0px; - padding-top: 0.5em; - padding-bottom: 0.5em; - width: 0.5em; -} #VariantInput[state="new"], #VariantInput[state="new"]:focus, #VariantInput[state="new"]:hover { border-color: {color:publisher:success}; } diff --git a/client/ayon_core/tools/publisher/widgets/create_widget.py b/client/ayon_core/tools/publisher/widgets/create_widget.py index 479a63ebc9..4c94c5c9b9 100644 --- a/client/ayon_core/tools/publisher/widgets/create_widget.py +++ b/client/ayon_core/tools/publisher/widgets/create_widget.py @@ -19,6 +19,7 @@ INPUTS_LAYOUT_HSPACING, INPUTS_LAYOUT_VSPACING, ) +from ayon_core.tools.utils import HintedLineEdit from .thumbnail_widget import ThumbnailWidget from .widgets import ( @@ -28,8 +29,6 @@ from .create_context_widgets import CreateContextWidget from .precreate_widget import PreCreateWidget -SEPARATORS = ("---separator---", "---") - class ResizeControlWidget(QtWidgets.QWidget): resized = QtCore.Signal() @@ -168,25 +167,9 @@ def __init__(self, controller, parent=None): product_variant_widget = QtWidgets.QWidget(creator_basics_widget) # Variant and product input - variant_widget = ResizeControlWidget(product_variant_widget) - variant_widget.setObjectName("VariantInputsWidget") - - variant_input = QtWidgets.QLineEdit(variant_widget) - variant_input.setObjectName("VariantInput") - variant_input.setToolTip(VARIANT_TOOLTIP) - - variant_hints_btn = QtWidgets.QToolButton(variant_widget) - variant_hints_btn.setArrowType(QtCore.Qt.DownArrow) - variant_hints_btn.setIconSize(QtCore.QSize(12, 12)) - - variant_hints_menu = QtWidgets.QMenu(variant_widget) - variant_hints_group = QtWidgets.QActionGroup(variant_hints_menu) - - variant_layout = QtWidgets.QHBoxLayout(variant_widget) - variant_layout.setContentsMargins(0, 0, 0, 0) - variant_layout.setSpacing(0) - variant_layout.addWidget(variant_input, 1) - variant_layout.addWidget(variant_hints_btn, 0, QtCore.Qt.AlignVCenter) + variant_widget = HintedLineEdit(parent=product_variant_widget) + variant_widget.set_text_widget_object_name("VariantInput") + variant_widget.setToolTip(VARIANT_TOOLTIP) product_name_input = QtWidgets.QLineEdit(product_variant_widget) product_name_input.setEnabled(False) @@ -262,15 +245,12 @@ def __init__(self, controller, parent=None): prereq_timer.timeout.connect(self._invalidate_prereq) create_btn.clicked.connect(self._on_create) - variant_widget.resized.connect(self._on_variant_widget_resize) creator_basics_widget.resized.connect(self._on_creator_basics_resize) - variant_input.returnPressed.connect(self._on_create) - variant_input.textChanged.connect(self._on_variant_change) + variant_widget.returnPressed.connect(self._on_create) + variant_widget.textChanged.connect(self._on_variant_change) creators_view.selectionModel().currentChanged.connect( self._on_creator_item_change ) - variant_hints_btn.clicked.connect(self._on_variant_btn_click) - variant_hints_menu.triggered.connect(self._on_variant_action) context_widget.folder_changed.connect(self._on_folder_change) context_widget.task_changed.connect(self._on_task_change) thumbnail_widget.thumbnail_created.connect(self._on_thumbnail_create) @@ -291,10 +271,7 @@ def __init__(self, controller, parent=None): self.product_name_input = product_name_input - self.variant_input = variant_input - self.variant_hints_btn = variant_hints_btn - self.variant_hints_menu = variant_hints_menu - self.variant_hints_group = variant_hints_group + self._variant_widget = variant_widget self._creators_model = creators_model self._creators_sort_model = creators_sort_model @@ -314,6 +291,7 @@ def __init__(self, controller, parent=None): self._last_current_context_folder_path = None self._last_current_context_task = None self._use_current_context = True + self._current_creator_variant_hints = [] def get_current_folder_path(self): return self._controller.get_current_folder_path() @@ -438,8 +416,7 @@ def _invalidate_prereq(self): self._create_btn.setEnabled(prereq_available) - self.variant_input.setEnabled(prereq_available) - self.variant_hints_btn.setEnabled(prereq_available) + self._variant_widget.setEnabled(prereq_available) tooltip = "" if creator_btn_tooltips: @@ -611,35 +588,15 @@ def _set_creator(self, creator_item): if not default_variant: default_variant = default_variants[0] - for action in tuple(self.variant_hints_menu.actions()): - self.variant_hints_menu.removeAction(action) - action.deleteLater() - - for variant in default_variants: - if variant in SEPARATORS: - self.variant_hints_menu.addSeparator() - elif variant: - self.variant_hints_menu.addAction(variant) + self._current_creator_variant_hints = list(default_variants) + self._variant_widget.set_options(default_variants) variant_text = default_variant or DEFAULT_VARIANT_VALUE # Make sure product name is updated to new plugin - if variant_text == self.variant_input.text(): + if variant_text == self._variant_widget.text(): self._on_variant_change() else: - self.variant_input.setText(variant_text) - - def _on_variant_widget_resize(self): - self.variant_hints_btn.setFixedHeight(self.variant_input.height()) - - def _on_variant_btn_click(self): - pos = self.variant_hints_btn.rect().bottomLeft() - point = self.variant_hints_btn.mapToGlobal(pos) - self.variant_hints_menu.popup(point) - - def _on_variant_action(self, action): - value = action.text() - if self.variant_input.text() != value: - self.variant_input.setText(value) + self._variant_widget.setText(variant_text) def _on_variant_change(self, variant_value=None): if not self._prereq_available: @@ -652,7 +609,7 @@ def _on_variant_change(self, variant_value=None): return if variant_value is None: - variant_value = self.variant_input.text() + variant_value = self._variant_widget.text() if not self._compiled_name_pattern.match(variant_value): self._create_btn.setEnabled(False) @@ -707,20 +664,12 @@ def _validate_product_name(self, product_name, variant_value): if _result: variant_hints |= set(_result.groups()) - # Remove previous hints from menu - for action in tuple(self.variant_hints_group.actions()): - self.variant_hints_group.removeAction(action) - self.variant_hints_menu.removeAction(action) - action.deleteLater() - - # Add separator if there are hints and menu already has actions - if variant_hints and self.variant_hints_menu.actions(): - self.variant_hints_menu.addSeparator() - + options = list(self._current_creator_variant_hints) + if options: + options.append("---") + options.extend(variant_hints) # Add hints to actions - for variant_hint in variant_hints: - action = self.variant_hints_menu.addAction(variant_hint) - self.variant_hints_group.addAction(action) + self._variant_widget.set_options(options) # Indicate product existence if not variant_value: @@ -741,10 +690,7 @@ def _validate_product_name(self, product_name, variant_value): self._create_btn.setEnabled(variant_is_valid) def _set_variant_state_property(self, state): - current_value = self.variant_input.property("state") - if current_value != state: - self.variant_input.setProperty("state", state) - self.variant_input.style().polish(self.variant_input) + self._variant_widget.set_text_widget_property("state", state) def _on_first_show(self): width = self.width() @@ -776,7 +722,7 @@ def _on_create(self): index = indexes[0] creator_identifier = index.data(CREATOR_IDENTIFIER_ROLE) product_type = index.data(PRODUCT_TYPE_ROLE) - variant = self.variant_input.text() + variant = self._variant_widget.text() # Care about product name only if context change is enabled product_name = None folder_path = None @@ -810,7 +756,7 @@ def _on_create(self): if success: self._set_creator(self._selected_creator) - self.variant_input.setText(variant) + self._variant_widget.setText(variant) self._controller.emit_card_message("Creation finished...") self._last_thumbnail_path = None self._thumbnail_widget.set_current_thumbnails() From e54e639b9dd7473d590488fc9506ce3de2f21e45 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:39:23 +0200 Subject: [PATCH 084/106] don't show spent time if did not run yet --- .../tools/publisher/publish_report_viewer/widgets.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index 029ce300a8..8227008ff3 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -442,9 +442,14 @@ def __init__(self, plugin_item, parent): plugin_families_widget.setText(str(plugin_item.families or "N/A")) plugin_path_widget.setText(plugin_item.filepath or "N/A") plugin_path_widget.setToolTip(plugin_item.filepath or None) - plugin_time_widget.setText( - get_pretty_milliseconds(plugin_item.process_time) - ) + if plugin_item.passed: + time_label = get_pretty_milliseconds(plugin_item.process_time) + elif plugin_item.skipped: + time_label = "Skipped plugin" + else: + time_label = "Not started" + + plugin_time_widget.setText(time_label) content_layout = QtWidgets.QGridLayout(content_widget) content_layout.setContentsMargins(8, 8, 8, 8) From fd6c6eade49636dbb4604d25c02f235b3711512c Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:42:01 +0200 Subject: [PATCH 085/106] details widget is acknowledged about being active --- .../tools/publisher/publish_report_viewer/widgets.py | 8 ++++++++ client/ayon_core/tools/publisher/window.py | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index 8227008ff3..af1a7e5281 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -817,6 +817,14 @@ def _on_plugin_view_clicked(self, index): else: self._plugins_view.expand(index) + def set_active(self, active): + for idx in range(self._details_tab_widget.count()): + widget = self._details_tab_widget.widget(idx) + widget.set_active(active and idx == self._current_tab_idx) + + if not active: + self.close_details_popup() + def set_report_data(self, report_data): report = PublishReport(report_data) self.set_report(report) diff --git a/client/ayon_core/tools/publisher/window.py b/client/ayon_core/tools/publisher/window.py index 1218221420..0c6087b41d 100644 --- a/client/ayon_core/tools/publisher/window.py +++ b/client/ayon_core/tools/publisher/window.py @@ -687,13 +687,14 @@ def _on_create_overlay_button_click(self): def _on_tab_change(self, old_tab, new_tab): if old_tab == "details": - self._publish_details_widget.close_details_popup() + self._publish_details_widget.set_active(False) if new_tab == "details": self._content_stacked_layout.setCurrentWidget( self._publish_details_widget ) self._update_publish_details_widget() + self._publish_details_widget.set_active(True) elif new_tab == "report": self._content_stacked_layout.setCurrentWidget( From cf6cf0bf14eba836e575428e476baf99dda38dd1 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:54:55 +0200 Subject: [PATCH 086/106] move time label calculation above value changes --- .../publisher/publish_report_viewer/widgets.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index af1a7e5281..b8ddb0ef54 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -435,6 +435,12 @@ def __init__(self, plugin_item, parent): plugin_label += " ({})".format( plugin_item.plugin_type.capitalize() ) + + time_label = "Not started" + if plugin_item.passed: + time_label = get_pretty_milliseconds(plugin_item.process_time) + elif plugin_item.skipped: + time_label = "Skipped plugin" plugin_label_widget.setText(plugin_label) plugin_doc_widget.setText(plugin_item.docstring or "N/A") plugin_class_widget.setText(plugin_item.name or "N/A") @@ -442,13 +448,6 @@ def __init__(self, plugin_item, parent): plugin_families_widget.setText(str(plugin_item.families or "N/A")) plugin_path_widget.setText(plugin_item.filepath or "N/A") plugin_path_widget.setToolTip(plugin_item.filepath or None) - if plugin_item.passed: - time_label = get_pretty_milliseconds(plugin_item.process_time) - elif plugin_item.skipped: - time_label = "Skipped plugin" - else: - time_label = "Not started" - plugin_time_widget.setText(time_label) content_layout = QtWidgets.QGridLayout(content_widget) From f2232f0af15dd6b87323a9d1f5c45fa78f5c7c0c Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:55:46 +0200 Subject: [PATCH 087/106] '0' order is not resolved as N/A --- .../tools/publisher/publish_report_viewer/widgets.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index b8ddb0ef54..5e854ae945 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -441,10 +441,14 @@ def __init__(self, plugin_item, parent): time_label = get_pretty_milliseconds(plugin_item.process_time) elif plugin_item.skipped: time_label = "Skipped plugin" + order = plugin_item.order + if order is None: + order = "N/A" + plugin_label_widget.setText(plugin_label) plugin_doc_widget.setText(plugin_item.docstring or "N/A") plugin_class_widget.setText(plugin_item.name or "N/A") - plugin_order_widget.setText(str(plugin_item.order or "N/A")) + plugin_order_widget.setText(order) plugin_families_widget.setText(str(plugin_item.families or "N/A")) plugin_path_widget.setText(plugin_item.filepath or "N/A") plugin_path_widget.setToolTip(plugin_item.filepath or None) From 9fce774a7e545641ab0282e2f71e3e7512d3765d Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:56:08 +0200 Subject: [PATCH 088/106] families are joined with comma --- .../tools/publisher/publish_report_viewer/widgets.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index 5e854ae945..925547bc1a 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -441,6 +441,11 @@ def __init__(self, plugin_item, parent): time_label = get_pretty_milliseconds(plugin_item.process_time) elif plugin_item.skipped: time_label = "Skipped plugin" + + families = "N/A" + if plugin_item.families: + families = ", ".join(plugin_item.families) + order = plugin_item.order if order is None: order = "N/A" @@ -449,7 +454,7 @@ def __init__(self, plugin_item, parent): plugin_doc_widget.setText(plugin_item.docstring or "N/A") plugin_class_widget.setText(plugin_item.name or "N/A") plugin_order_widget.setText(order) - plugin_families_widget.setText(str(plugin_item.families or "N/A")) + plugin_families_widget.setText(families) plugin_path_widget.setText(plugin_item.filepath or "N/A") plugin_path_widget.setToolTip(plugin_item.filepath or None) plugin_time_widget.setText(time_label) From 4eef7ecadd22185585e4cdb1e7107a69329c455a Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:57:18 +0200 Subject: [PATCH 089/106] hide content widget before adding widgets to it's layout --- .../tools/publisher/publish_report_viewer/widgets.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index 925547bc1a..6441667264 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -578,6 +578,11 @@ def _update_widgets(self): self._need_refresh = False + # Hide content widget before updating + # - add widgets to layout can happen without recalculating + # the layout and widget size hints + self._content_widget.setVisible(False) + for plugin_id in self._get_plugin_ids(): widget = self._widgets_by_plugin_id.get(plugin_id) if widget is None: @@ -591,6 +596,7 @@ def _update_widgets(self): or plugin_id in self._plugin_filter ) + self._content_widget.setVisible(True) class DeselectableTreeView(QtWidgets.QTreeView): """A tree view that deselects on clicking on an empty area in the view""" From a819797f21a6a1f287fd7dde789eab457a7b7f05 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:58:25 +0200 Subject: [PATCH 090/106] don't show all details if nothing is selected --- .../tools/publisher/publish_report_viewer/widgets.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index 6441667264..df6cd4b168 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -591,10 +591,7 @@ def _update_widgets(self): self._widgets_by_plugin_id[plugin_id] = widget self._content_layout.addWidget(widget, 0) - widget.setVisible( - not self._plugin_filter - or plugin_id in self._plugin_filter - ) + widget.setVisible(plugin_id in self._plugin_filter) self._content_widget.setVisible(True) From 1e7be786eb69f2c0b265b4e7833aa2e5c097a72e Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 14:58:47 +0200 Subject: [PATCH 091/106] added label shown if nothing is selected --- .../publish_report_viewer/widgets.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index df6cd4b168..fa4127fe8b 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -505,6 +505,12 @@ def __init__(self, parent): scroll_area.setWidget(scroll_content_widget) + empty_label = QtWidgets.QLabel( + "

Select plugins to view more information...", + scroll_content_widget + ) + empty_label.setAlignment(QtCore.Qt.AlignCenter) + content_widget = QtWidgets.QWidget(scroll_content_widget) content_layout = QtWidgets.QVBoxLayout(content_widget) @@ -513,6 +519,7 @@ def __init__(self, parent): scroll_content_layout = QtWidgets.QVBoxLayout(scroll_content_widget) scroll_content_layout.setContentsMargins(0, 0, 0, 0) + scroll_content_layout.addWidget(empty_label, 0) scroll_content_layout.addWidget(content_widget, 0) scroll_content_layout.addStretch(1) @@ -520,7 +527,10 @@ def __init__(self, parent): main_layout.setContentsMargins(0, 0, 0, 0) main_layout.addWidget(scroll_area, 1) + content_widget.setVisible(False) + self._scroll_area = scroll_area + self._empty_label = empty_label self._content_layout = content_layout self._content_widget = content_widget @@ -583,6 +593,7 @@ def _update_widgets(self): # the layout and widget size hints self._content_widget.setVisible(False) + any_visible = False for plugin_id in self._get_plugin_ids(): widget = self._widgets_by_plugin_id.get(plugin_id) if widget is None: @@ -591,9 +602,14 @@ def _update_widgets(self): self._widgets_by_plugin_id[plugin_id] = widget self._content_layout.addWidget(widget, 0) - widget.setVisible(plugin_id in self._plugin_filter) + is_visible = plugin_id in self._plugin_filter + widget.setVisible(is_visible) + if is_visible: + any_visible = True + + self._content_widget.setVisible(any_visible) + self._empty_label.setVisible(not any_visible) - self._content_widget.setVisible(True) class DeselectableTreeView(QtWidgets.QTreeView): """A tree view that deselects on clicking on an empty area in the view""" From 7e4da0761d558bd42c9f0dcadbdb679d605f1699 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:00:07 +0200 Subject: [PATCH 092/106] order is converted to string --- .../tools/publisher/publish_report_viewer/widgets.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py index fa4127fe8b..5fa1c04dc0 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/widgets.py @@ -446,9 +446,9 @@ def __init__(self, plugin_item, parent): if plugin_item.families: families = ", ".join(plugin_item.families) - order = plugin_item.order - if order is None: - order = "N/A" + order = "N/A" + if plugin_item.order is not None: + order = str(plugin_item.order) plugin_label_widget.setText(plugin_label) plugin_doc_widget.setText(plugin_item.docstring or "N/A") From d8ca5e797cdfaa658c8251e89efbc8270c0d8e98 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:59:25 +0200 Subject: [PATCH 093/106] simplify menu handling --- client/ayon_core/tools/utils/widgets.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/client/ayon_core/tools/utils/widgets.py b/client/ayon_core/tools/utils/widgets.py index 184465ee1b..982b2fd6a6 100644 --- a/client/ayon_core/tools/utils/widgets.py +++ b/client/ayon_core/tools/utils/widgets.py @@ -233,21 +233,19 @@ def _on_options_button_clicked(self): return menu = QtWidgets.QMenu(self) + menu.triggered.connect(self._on_option_action) for option in self._options: if option in self.SEPARATORS: menu.addSeparator() - continue - action = menu.addAction(option) - action.triggered.connect(self._on_option_action) + else: + menu.addAction(option) rect = self._options_button.rect() pos = self._options_button.mapToGlobal(rect.bottomLeft()) menu.exec_(pos) - def _on_option_action(self): - action = self.sender() - if action: - self.setText(action.text()) + def _on_option_action(self, action): + self.setText(action.text()) class ExpandingTextEdit(QtWidgets.QTextEdit): From 767ce61208f549a9fb38d1acad9191f092638c52 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:19:09 +0200 Subject: [PATCH 094/106] cache paths --- client/ayon_core/tools/utils/widgets.py | 29 +++++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/client/ayon_core/tools/utils/widgets.py b/client/ayon_core/tools/utils/widgets.py index 982b2fd6a6..5e4cd75cfe 100644 --- a/client/ayon_core/tools/utils/widgets.py +++ b/client/ayon_core/tools/utils/widgets.py @@ -105,7 +105,14 @@ def __init__(self, *args, **kwargs): self.setPalette(filter_palette) +class _LocalCache: + down_arrow_icon = None + + def get_down_arrow_icon() -> QtGui.QIcon: + if _LocalCache.down_arrow_icon is not None: + return _LocalCache.down_arrow_icon + normal_pixmap = QtGui.QPixmap( get_style_image_path("down_arrow") ) @@ -118,6 +125,7 @@ def get_down_arrow_icon() -> QtGui.QIcon: icon = QtGui.QIcon(normal_pixmap) icon.addPixmap(on_pixmap, QtGui.QIcon.Active) icon.addPixmap(disabled_pixmap, QtGui.QIcon.Disabled) + _LocalCache.down_arrow_icon = icon return icon @@ -350,6 +358,8 @@ class ExpandBtnLabel(QtWidgets.QLabel): """Label showing expand icon meant for ExpandBtn.""" state_changed = QtCore.Signal() + branch_closed_path = get_style_image_path("branch_closed") + branch_open_path = get_style_image_path("branch_open") def __init__(self, parent): super(ExpandBtnLabel, self).__init__(parent) @@ -360,14 +370,10 @@ def __init__(self, parent): self._collapsed = True def _create_collapsed_pixmap(self): - return QtGui.QPixmap( - get_style_image_path("branch_closed") - ) + return QtGui.QPixmap(self.branch_closed_path) def _create_expanded_pixmap(self): - return QtGui.QPixmap( - get_style_image_path("branch_open") - ) + return QtGui.QPixmap(self.branch_open_path) @property def collapsed(self): @@ -435,15 +441,14 @@ def set_collapsed(self, collapsed=None): class ClassicExpandBtnLabel(ExpandBtnLabel): + right_arrow_path = get_style_image_path("right_arrow") + down_arrow_path = get_style_image_path("down_arrow") + def _create_collapsed_pixmap(self): - return QtGui.QPixmap( - get_style_image_path("right_arrow") - ) + return QtGui.QPixmap(self.right_arrow_path) def _create_expanded_pixmap(self): - return QtGui.QPixmap( - get_style_image_path("down_arrow") - ) + return QtGui.QPixmap(self.down_arrow_path) class ClassicExpandBtn(ExpandBtn): From 41694772c12739a8ac1e230997816d2596820e08 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 23 Aug 2024 17:58:51 +0200 Subject: [PATCH 095/106] Use proper aac argument for ExtractReview acc doesnt work for audio --- server/settings/publish_plugins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/settings/publish_plugins.py b/server/settings/publish_plugins.py index 8ca96432f4..9745a07fcb 100644 --- a/server/settings/publish_plugins.py +++ b/server/settings/publish_plugins.py @@ -1066,7 +1066,7 @@ class PublishPuginsModel(BaseSettingsModel): "output": [ "-pix_fmt yuv420p", "-crf 18", - "-c:a acc", + "-c:a aac", "-b:a 192k", "-g 1", "-movflags faststart" From 4344b032306d412d7e777574e1aaffb328e71d8e Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Sun, 25 Aug 2024 11:25:19 +0200 Subject: [PATCH 096/106] fix validation stop check --- client/ayon_core/tools/publisher/models/publish.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/tools/publisher/models/publish.py b/client/ayon_core/tools/publisher/models/publish.py index a73997c302..a60ef69fac 100644 --- a/client/ayon_core/tools/publisher/models/publish.py +++ b/client/ayon_core/tools/publisher/models/publish.py @@ -1129,10 +1129,16 @@ def _publish_iterator(self) -> Iterable[partial]: self._publish_progress = idx # Check if plugin is over validation order - if not self._publish_has_validated: - self._set_has_validated( - plugin.order >= self._validation_order - ) + if ( + not self._publish_has_validated + and plugin.order >= self._validation_order + ): + self._set_has_validated(True) + if ( + self._publish_up_validation + or self._publish_has_validation_errors + ): + yield partial(self.stop_publish) # Add plugin to publish report self._publish_report.add_plugin_iter( From 4632d22275099045d2c1da0d757b92e7aacc37ec Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Sun, 25 Aug 2024 11:30:51 +0200 Subject: [PATCH 097/106] make sure only one loop is running Make sure loop of '_next_publish_item_process' is in processor only once --- client/ayon_core/tools/publisher/control_qt.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/tools/publisher/control_qt.py b/client/ayon_core/tools/publisher/control_qt.py index f769fab91e..e87d546333 100644 --- a/client/ayon_core/tools/publisher/control_qt.py +++ b/client/ayon_core/tools/publisher/control_qt.py @@ -76,21 +76,27 @@ def __init__(self, *args, **kwargs): self.register_event_callback( "publish.process.stopped", self._qt_on_publish_stop ) + self._item_process_in_loop = False def reset(self): self._main_thread_processor.clear() + self._item_process_in_loop = False super().reset() def _start_publish(self, up_validation): self._publish_model.set_publish_up_validation(up_validation) self._publish_model.start_publish(wait=False) - self._process_main_thread_item( - MainThreadItem(self._next_publish_item_process) - ) + if not self._item_process_in_loop: + self._process_main_thread_item( + MainThreadItem(self._next_publish_item_process) + ) def _next_publish_item_process(self): if not self._publish_model.is_running(): + self._item_process_in_loop = False return + + self._item_process_in_loop = True func = self._publish_model.get_next_process_func() self._process_main_thread_item(MainThreadItem(func)) self._process_main_thread_item( @@ -104,4 +110,6 @@ def _qt_on_publish_start(self): self._main_thread_processor.start() def _qt_on_publish_stop(self): - self._main_thread_processor.stop() + self._process_main_thread_item( + MainThreadItem(self._main_thread_processor.stop) + ) From 714f58fbd692dd31f5446c8f4b1270dcd0cb0b32 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:10:54 +0200 Subject: [PATCH 098/106] excape parenthesis for shell --- client/ayon_core/plugins/publish/extract_review.py | 7 +++++++ client/ayon_core/plugins/publish/extract_review_slate.py | 7 +++++++ client/ayon_core/plugins/publish/extract_thumbnail.py | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/client/ayon_core/plugins/publish/extract_review.py b/client/ayon_core/plugins/publish/extract_review.py index c2793f98a2..b2531ebae9 100644 --- a/client/ayon_core/plugins/publish/extract_review.py +++ b/client/ayon_core/plugins/publish/extract_review.py @@ -454,6 +454,13 @@ def _render_output_definitions( raise NotImplementedError subprcs_cmd = " ".join(ffmpeg_args) + if os.getenv("SHELL") in ("/bin/bash", "/bin/sh"): + # Escape parentheses for bash + subprcs_cmd = ( + subprcs_cmd + .replace("(", "\\(") + .replace(")", "\\)") + ) # run subprocess self.log.debug("Executing: {}".format(subprcs_cmd)) diff --git a/client/ayon_core/plugins/publish/extract_review_slate.py b/client/ayon_core/plugins/publish/extract_review_slate.py index 35f55e275c..01a65e89ae 100644 --- a/client/ayon_core/plugins/publish/extract_review_slate.py +++ b/client/ayon_core/plugins/publish/extract_review_slate.py @@ -269,6 +269,13 @@ def process(self, instance): " ".join(output_args) ] slate_subprocess_cmd = " ".join(slate_args) + if os.getenv("SHELL") in ("/bin/bash", "/bin/sh"): + # Escape parentheses for bash + slate_subprocess_cmd = ( + slate_subprocess_cmd + .replace("(", "\\(") + .replace(")", "\\)") + ) # run slate generation subprocess self.log.debug( diff --git a/client/ayon_core/plugins/publish/extract_thumbnail.py b/client/ayon_core/plugins/publish/extract_thumbnail.py index d1b6e4e0cc..328cb308b9 100644 --- a/client/ayon_core/plugins/publish/extract_thumbnail.py +++ b/client/ayon_core/plugins/publish/extract_thumbnail.py @@ -455,6 +455,14 @@ def _create_thumbnail_ffmpeg(self, src_path, dst_path): # output file jpeg_items.append(path_to_subprocess_arg(dst_path)) subprocess_command = " ".join(jpeg_items) + if os.getenv("SHELL") in ("/bin/bash", "/bin/sh"): + # Escape parentheses for bash + subprocess_command = ( + subprocess_command + .replace("(", "\\(") + .replace(")", "\\)") + ) + try: run_subprocess( subprocess_command, shell=True, logger=self.log From 570b0c8b7038db3dac39e8dd0f61b85f273ae898 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:45:01 +0200 Subject: [PATCH 099/106] added some comments --- client/ayon_core/tools/publisher/control_qt.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/ayon_core/tools/publisher/control_qt.py b/client/ayon_core/tools/publisher/control_qt.py index e87d546333..7d1c661603 100644 --- a/client/ayon_core/tools/publisher/control_qt.py +++ b/client/ayon_core/tools/publisher/control_qt.py @@ -76,6 +76,8 @@ def __init__(self, *args, **kwargs): self.register_event_callback( "publish.process.stopped", self._qt_on_publish_stop ) + # Capture if '_next_publish_item_process' is in + # '_main_thread_processor' loop self._item_process_in_loop = False def reset(self): @@ -86,6 +88,8 @@ def reset(self): def _start_publish(self, up_validation): self._publish_model.set_publish_up_validation(up_validation) self._publish_model.start_publish(wait=False) + # Make sure '_next_publish_item_process' is only once in + # the '_main_thread_processor' loop if not self._item_process_in_loop: self._process_main_thread_item( MainThreadItem(self._next_publish_item_process) @@ -93,6 +97,7 @@ def _start_publish(self, up_validation): def _next_publish_item_process(self): if not self._publish_model.is_running(): + # This removes '_next_publish_item_process' from loop self._item_process_in_loop = False return From 911ef45a458a51a90d5e5caee2058748cfc68b67 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:33:48 +0200 Subject: [PATCH 100/106] handle escape in 'run_subprocess' --- client/ayon_core/lib/execute.py | 14 ++++++++++++++ client/ayon_core/plugins/publish/extract_review.py | 7 ------- .../plugins/publish/extract_review_slate.py | 7 ------- .../ayon_core/plugins/publish/extract_thumbnail.py | 7 ------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/client/ayon_core/lib/execute.py b/client/ayon_core/lib/execute.py index bc55c27bd8..4e6cb415e7 100644 --- a/client/ayon_core/lib/execute.py +++ b/client/ayon_core/lib/execute.py @@ -108,6 +108,20 @@ def run_subprocess(*args, **kwargs): | getattr(subprocess, "CREATE_NO_WINDOW", 0) ) + # Escape parentheses for bash + if ( + kwargs.get("shell") is True + and len(args) == 1 + and isinstance(args[0], str) + and os.getenv("SHELL") in ("/bin/bash", "/bin/sh") + ): + new_arg = ( + args[0] + .replace("(", "\\(") + .replace(")", "\\)") + ) + args = (new_arg, ) + # Get environents from kwarg or use current process environments if were # not passed. env = kwargs.get("env") or os.environ diff --git a/client/ayon_core/plugins/publish/extract_review.py b/client/ayon_core/plugins/publish/extract_review.py index b2531ebae9..c2793f98a2 100644 --- a/client/ayon_core/plugins/publish/extract_review.py +++ b/client/ayon_core/plugins/publish/extract_review.py @@ -454,13 +454,6 @@ def _render_output_definitions( raise NotImplementedError subprcs_cmd = " ".join(ffmpeg_args) - if os.getenv("SHELL") in ("/bin/bash", "/bin/sh"): - # Escape parentheses for bash - subprcs_cmd = ( - subprcs_cmd - .replace("(", "\\(") - .replace(")", "\\)") - ) # run subprocess self.log.debug("Executing: {}".format(subprcs_cmd)) diff --git a/client/ayon_core/plugins/publish/extract_review_slate.py b/client/ayon_core/plugins/publish/extract_review_slate.py index 01a65e89ae..35f55e275c 100644 --- a/client/ayon_core/plugins/publish/extract_review_slate.py +++ b/client/ayon_core/plugins/publish/extract_review_slate.py @@ -269,13 +269,6 @@ def process(self, instance): " ".join(output_args) ] slate_subprocess_cmd = " ".join(slate_args) - if os.getenv("SHELL") in ("/bin/bash", "/bin/sh"): - # Escape parentheses for bash - slate_subprocess_cmd = ( - slate_subprocess_cmd - .replace("(", "\\(") - .replace(")", "\\)") - ) # run slate generation subprocess self.log.debug( diff --git a/client/ayon_core/plugins/publish/extract_thumbnail.py b/client/ayon_core/plugins/publish/extract_thumbnail.py index 328cb308b9..4ffabf6028 100644 --- a/client/ayon_core/plugins/publish/extract_thumbnail.py +++ b/client/ayon_core/plugins/publish/extract_thumbnail.py @@ -455,13 +455,6 @@ def _create_thumbnail_ffmpeg(self, src_path, dst_path): # output file jpeg_items.append(path_to_subprocess_arg(dst_path)) subprocess_command = " ".join(jpeg_items) - if os.getenv("SHELL") in ("/bin/bash", "/bin/sh"): - # Escape parentheses for bash - subprocess_command = ( - subprocess_command - .replace("(", "\\(") - .replace(")", "\\)") - ) try: run_subprocess( From 102ec52dd0c88d466e33adc947f3df1ffff33ee0 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:30:18 +0200 Subject: [PATCH 101/106] add exceptions moved to different file --- client/ayon_core/pipeline/create/context.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index b3a46bb778..69103159c6 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -39,6 +39,13 @@ discover_convertor_plugins, ) +# Import of exceptions that were moved to different file +from .exceptions import ( + ImmutableKeyError, + CreatorsOperationFailed, + ConvertorsOperationFailed, +) # noqa: F401 + # Changes of instances and context are send as tuple of 2 information UpdateData = collections.namedtuple("UpdateData", ["instance", "changes"]) _NOT_SET = object() From f414d73f7dcd5d4359795154028c3ab355cd5dd3 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:58:34 +0200 Subject: [PATCH 102/106] use shorter import --- client/ayon_core/tools/publisher/abstract.py | 2 +- client/ayon_core/tools/publisher/models/create.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/tools/publisher/abstract.py b/client/ayon_core/tools/publisher/abstract.py index 768f4b052f..ce9c6ac1ed 100644 --- a/client/ayon_core/tools/publisher/abstract.py +++ b/client/ayon_core/tools/publisher/abstract.py @@ -14,7 +14,7 @@ from ayon_core.lib import AbstractAttrDef from ayon_core.host import HostBase from ayon_core.pipeline.create import CreateContext, CreatedInstance -from ayon_core.pipeline.create.context import ConvertorItem +from ayon_core.pipeline.create import ConvertorItem from ayon_core.tools.common_models import ( FolderItem, TaskItem, diff --git a/client/ayon_core/tools/publisher/models/create.py b/client/ayon_core/tools/publisher/models/create.py index ab2bf07614..9fe114f4bd 100644 --- a/client/ayon_core/tools/publisher/models/create.py +++ b/client/ayon_core/tools/publisher/models/create.py @@ -18,7 +18,7 @@ CreateContext, CreatedInstance, ) -from ayon_core.pipeline.create.context import ( +from ayon_core.pipeline.create import ( CreatorsOperationFailed, ConvertorsOperationFailed, ConvertorItem, From a4ed32e3e114480e0fe54624b664b04c90d21e92 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:12:56 +0200 Subject: [PATCH 103/106] added strucctures to init file --- client/ayon_core/pipeline/create/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/create/__init__.py b/client/ayon_core/pipeline/create/__init__.py index fa8d639c6f..ced43528eb 100644 --- a/client/ayon_core/pipeline/create/__init__.py +++ b/client/ayon_core/pipeline/create/__init__.py @@ -20,7 +20,14 @@ TaskNotSetError, TemplateFillError, ) -from .structures import CreatedInstance +from .structures import ( + CreatedInstance, + ConvertorItem, + AttributeValues, + CreatorAttributeValues, + PublishAttributeValues, + PublishAttributes, +) from .utils import ( get_last_versions_for_instances, get_next_versions_for_instances, @@ -79,6 +86,11 @@ "TemplateFillError", "CreatedInstance", + "ConvertorItem", + "AttributeValues", + "CreatorAttributeValues", + "PublishAttributeValues", + "PublishAttributes", "get_last_versions_for_instances", "get_next_versions_for_instances", From e33f8670fd9cc3f1c3c99cfad8d989b5c0cd6cf6 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:13:06 +0200 Subject: [PATCH 104/106] fake import classes from structures too --- client/ayon_core/pipeline/create/context.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index 69103159c6..71ba3b7799 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -39,12 +39,18 @@ discover_convertor_plugins, ) -# Import of exceptions that were moved to different file +# Import of functions and classes that were moved to different file +# TODO Should be removed in future release - Added 24/08/28, 0.4.3-dev.1 from .exceptions import ( ImmutableKeyError, CreatorsOperationFailed, ConvertorsOperationFailed, ) # noqa: F401 +from .structures import ( + AttributeValues, + CreatorAttributeValues, + PublishAttributeValues, +) # noqa: F401 # Changes of instances and context are send as tuple of 2 information UpdateData = collections.namedtuple("UpdateData", ["instance", "changes"]) From 0ce2bf6633bdfc1ac7ef6b6ec9fbcf2c8cd64066 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:25:40 +0200 Subject: [PATCH 105/106] changed noqa location --- client/ayon_core/pipeline/create/context.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index 71ba3b7799..3f067427fa 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -42,15 +42,15 @@ # Import of functions and classes that were moved to different file # TODO Should be removed in future release - Added 24/08/28, 0.4.3-dev.1 from .exceptions import ( - ImmutableKeyError, - CreatorsOperationFailed, - ConvertorsOperationFailed, -) # noqa: F401 + ImmutableKeyError, # noqa: F401 + CreatorsOperationFailed, # noqa: F401 + ConvertorsOperationFailed, # noqa: F401 +) from .structures import ( - AttributeValues, - CreatorAttributeValues, - PublishAttributeValues, -) # noqa: F401 + AttributeValues, # noqa: F401 + CreatorAttributeValues, # noqa: F401 + PublishAttributeValues, # noqa: F401 +) # Changes of instances and context are send as tuple of 2 information UpdateData = collections.namedtuple("UpdateData", ["instance", "changes"]) From 237e17b658d2cf016614e8c8ac30a69a2e0208e0 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:34:20 +0200 Subject: [PATCH 106/106] merge import --- client/ayon_core/tools/publisher/abstract.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/tools/publisher/abstract.py b/client/ayon_core/tools/publisher/abstract.py index ce9c6ac1ed..362fa38882 100644 --- a/client/ayon_core/tools/publisher/abstract.py +++ b/client/ayon_core/tools/publisher/abstract.py @@ -13,8 +13,11 @@ from ayon_core.lib import AbstractAttrDef from ayon_core.host import HostBase -from ayon_core.pipeline.create import CreateContext, CreatedInstance -from ayon_core.pipeline.create import ConvertorItem +from ayon_core.pipeline.create import ( + CreateContext, + CreatedInstance, + ConvertorItem, +) from ayon_core.tools.common_models import ( FolderItem, TaskItem,