From 2e052ee139807d0fd4bf99ee30d5ac3d1ed17891 Mon Sep 17 00:00:00 2001 From: Ben Souchet Date: Wed, 11 Sep 2024 14:40:42 +0200 Subject: [PATCH] Deadline Plugins: Improve how settings are applied to plugins, always apply OP settings first --- openpype/hosts/equalizer/api/plugin.py | 15 -------- .../deadline/plugins/publish/collect_pools.py | 7 ---- .../plugins/publish/submit_max_deadline.py | 11 ------ .../plugins/publish/submit_maya_deadline.py | 19 ---------- openpype/pipeline/publish/__init__.py | 8 ++-- openpype/pipeline/publish/lib.py | 37 ++++++++++--------- 6 files changed, 24 insertions(+), 73 deletions(-) diff --git a/openpype/hosts/equalizer/api/plugin.py b/openpype/hosts/equalizer/api/plugin.py index deebc4f423a..48916e8b576 100644 --- a/openpype/hosts/equalizer/api/plugin.py +++ b/openpype/hosts/equalizer/api/plugin.py @@ -113,21 +113,6 @@ class ExtractScriptBase(OptionalPyblishPluginMixin): overscan_percent_height = 100 units = "mm" - @classmethod - def apply_settings(cls, project_settings, system_settings): - settings = project_settings["equalizer"]["publish"][ - "ExtractMatchmoveScriptMaya"] # noqa - - cls.hide_reference_frame = settings.get( - "hide_reference_frame", cls.hide_reference_frame) - cls.export_uv_textures = settings.get( - "export_uv_textures", cls.export_uv_textures) - cls.overscan_percent_width = settings.get( - "overscan_percent_width", cls.overscan_percent_width) - cls.overscan_percent_height = settings.get( - "overscan_percent_height", cls.overscan_percent_height) - cls.units = settings.get("units", cls.units) - @classmethod def get_attribute_defs(cls): defs = super(ExtractScriptBase, cls).get_attribute_defs() diff --git a/openpype/modules/deadline/plugins/publish/collect_pools.py b/openpype/modules/deadline/plugins/publish/collect_pools.py index e3fc0b35edb..f0e8ec7ca19 100644 --- a/openpype/modules/deadline/plugins/publish/collect_pools.py +++ b/openpype/modules/deadline/plugins/publish/collect_pools.py @@ -51,13 +51,6 @@ class CollectDeadlinePools(pyblish.api.InstancePlugin, primary_pool = None secondary_pool = None - @classmethod - def apply_settings(cls, project_settings, system_settings): - # deadline.publish.CollectDeadlinePools - settings = project_settings["deadline"]["publish"]["CollectDeadlinePools"] # noqa - cls.primary_pool = settings.get("primary_pool", None) - cls.secondary_pool = settings.get("secondary_pool", None) - def process(self, instance): attr_values = self.get_attr_values_from_data(instance.data) if not instance.data.get("primaryPool"): diff --git a/openpype/modules/deadline/plugins/publish/submit_max_deadline.py b/openpype/modules/deadline/plugins/publish/submit_max_deadline.py index 07bbb1cacbb..2143e7df056 100644 --- a/openpype/modules/deadline/plugins/publish/submit_max_deadline.py +++ b/openpype/modules/deadline/plugins/publish/submit_max_deadline.py @@ -44,17 +44,6 @@ class MaxSubmitDeadline(abstract_submit_deadline.AbstractSubmitDeadline, pluginInfo = {} group = None - @classmethod - def apply_settings(cls, project_settings, system_settings): - settings = project_settings["deadline"]["publish"]["MaxSubmitDeadline"] # noqa - - # Take some defaults from settings - cls.use_published = settings.get("use_published", - cls.use_published) - cls.priority = settings.get("priority", - cls.priority) - cls.chuck_size = settings.get("chunk_size", cls.chunk_size) - cls.group = settings.get("group", cls.group) # TODO: multiple camera instance, separate job infos def get_job_info(self): job_info = DeadlineJobInfo(Plugin="3dsmax") diff --git a/openpype/modules/deadline/plugins/publish/submit_maya_deadline.py b/openpype/modules/deadline/plugins/publish/submit_maya_deadline.py index 4cd417b83b2..ee5cb8ffbf8 100644 --- a/openpype/modules/deadline/plugins/publish/submit_maya_deadline.py +++ b/openpype/modules/deadline/plugins/publish/submit_maya_deadline.py @@ -116,25 +116,6 @@ class MayaSubmitDeadline(abstract_submit_deadline.AbstractSubmitDeadline, group = "none" strict_error_checking = True - @classmethod - def apply_settings(cls, project_settings, system_settings): - settings = project_settings["deadline"]["publish"]["MayaSubmitDeadline"] # noqa - - # Take some defaults from settings - cls.asset_dependencies = settings.get("asset_dependencies", - cls.asset_dependencies) - cls.import_reference = settings.get("import_reference", - cls.import_reference) - cls.use_published = settings.get("use_published", cls.use_published) - cls.priority = settings.get("priority", cls.priority) - cls.tile_priority = settings.get("tile_priority", cls.tile_priority) - cls.limit = settings.get("limit", cls.limit) - cls.group = settings.get("group", cls.group) - cls.strict_error_checking = settings.get("strict_error_checking", - cls.strict_error_checking) - cls.jobInfo = settings.get("jobInfo", cls.jobInfo) - cls.pluginInfo = settings.get("pluginInfo", cls.pluginInfo) - def get_job_info(self): job_info = DeadlineJobInfo(Plugin="MayaBatch") diff --git a/openpype/pipeline/publish/__init__.py b/openpype/pipeline/publish/__init__.py index 3a82d6f5650..a65a6cefc0b 100644 --- a/openpype/pipeline/publish/__init__.py +++ b/openpype/pipeline/publish/__init__.py @@ -37,8 +37,8 @@ get_instance_staging_dir, get_publish_repre_path, - apply_plugin_settings_automatically, - get_plugin_settings, + apply_plugin_settings, + get_publish_plugin_settings, get_publish_instance_label, get_publish_instance_families, ) @@ -85,8 +85,8 @@ "get_instance_staging_dir", "get_publish_repre_path", - "apply_plugin_settings_automatically", - "get_plugin_settings", + "apply_plugin_settings", + "get_publish_plugin_settings", "get_publish_instance_label", "get_publish_instance_families", diff --git a/openpype/pipeline/publish/lib.py b/openpype/pipeline/publish/lib.py index 40cb94e2bfe..e19c31cb9de 100644 --- a/openpype/pipeline/publish/lib.py +++ b/openpype/pipeline/publish/lib.py @@ -315,7 +315,7 @@ def publish_plugins_discover(paths=None): return result -def get_plugin_settings(plugin, project_settings, log, category=None): +def get_publish_plugin_settings(plugin, project_settings, category=None, logger=None): """Get plugin settings based on host name and plugin name. Note: @@ -325,13 +325,15 @@ def get_plugin_settings(plugin, project_settings, log, category=None): Args: plugin (pyblish.Plugin): Plugin where settings are applied. project_settings (dict[str, Any]): Project settings. - log (logging.Logger): Logger to log messages. category (Optional[str]): Settings category key where to look for plugin settings. + logger (Optional[logging.Logger]): Logger to log messages. Returns: dict[str, Any]: Plugin settings {'attribute': 'value'}. """ + if not logger: + logger = Logger.get_logger("get_publish_plugin_settings") # Plugin can define settings category by class attribute # - it's impossible to set `settings_category` via settings because @@ -347,7 +349,7 @@ def get_plugin_settings(plugin, project_settings, log, category=None): [plugin.__name__] ) except KeyError: - log.warning(( + logger.warning(( "Couldn't find plugin '{}' settings" " under settings category '{}'" ).format(plugin.__name__, settings_category)) @@ -366,13 +368,13 @@ def get_plugin_settings(plugin, project_settings, log, category=None): pass # Settings category determined from path - # - usually path is './/plugins/publish/' + # - usually the path is './/plugins/publish/' # - category can be host name of addon name ('maya', 'deadline', ...) filepath = os.path.normpath(inspect.getsourcefile(plugin)) split_path = filepath.rsplit(os.path.sep, 5) if len(split_path) < 4: - log.debug(( + logger.debug(( "Plugin path is too short to automatically" " extract settings category. {}" ).format(filepath)) @@ -397,7 +399,7 @@ def get_plugin_settings(plugin, project_settings, log, category=None): return {} -def apply_plugin_settings_automatically(plugin, settings, logger=None): +def apply_plugin_settings(plugin, settings, logger=None): """Automatically apply plugin settings to a plugin object. Note: @@ -431,10 +433,10 @@ class method 'def apply_settings(cls, project_settings, system_settings)' are applied settings. """ - log = Logger.get_logger("filter_pyblish_plugins") + logger = Logger.get_logger("filter_pyblish_plugins") # TODO: Don't use host from 'pyblish.api' but from defined host by us. - # - kept becau on farm is probably used host 'shell' which propably + # - kept because on farm is probably used host 'shell' which probably # affect how settings are applied there host_name = pyblish.api.current_host() project_name = os.environ.get("AVALON_PROJECT") @@ -444,7 +446,14 @@ class method 'def apply_settings(cls, project_settings, system_settings)' # iterate over plugins for plugin in plugins[:]: - # Apply settings to plugins + # Apply settings to plugin + + # First settings from OP settings + plugin_settings = get_publish_plugin_settings( + plugin, project_settings, host_name, logger) + apply_plugin_settings(plugin, plugin_settings, logger) + + # Then (if defined) calling the class method apply_settings_func = getattr(plugin, "apply_settings", None) if apply_settings_func is not None: @@ -466,19 +475,13 @@ class method 'def apply_settings(cls, project_settings, system_settings)' else: plugin.apply_settings(project_settings, system_settings) - except Exception: - log.warning( + except Exception: # noqa + logger.warning( ( "Failed to apply settings on plugin {}" ).format(plugin.__name__), exc_info=True ) - else: - # Automated - plugin_settins = get_plugin_settings( - plugin, project_settings, log, host_name - ) - apply_plugin_settings_automatically(plugin, plugin_settins, log) # Remove disabled plugins if getattr(plugin, "enabled", True) is False: