Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Create Plugins: Better check of overriden '__init__' method #5571

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion openpype/pipeline/create/creator_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def __init__(
# Backwards compatibility for system settings
self.apply_settings(project_settings, system_settings)

init_overriden = self.__class__.__init__ is not BaseCreator.__init__
init_overriden = self._method_is_overriden("__init__")
iLLiCiTiT marked this conversation as resolved.
Show resolved Hide resolved
if init_overriden or expect_system_settings:
self.log.warning((
"WARNING: Source - Create plugin {}."
Expand All @@ -225,6 +225,19 @@ def __init__(
" need to keep system settings."
).format(self.__class__.__name__))

def _method_is_overriden(self, method_name):
"""Check if method is overriden on objects class.

Implemented for deprecation warning validation on init.

Returns:
bool: True if method is overriden on objects class.
"""

cls_method = getattr(BaseCreator, method_name)
obj_method = getattr(self.__class__, method_name)
return cls_method is not obj_method

def apply_settings(self, project_settings):
"""Method called on initialization of plugin to apply settings.

Expand Down Expand Up @@ -578,6 +591,11 @@ def __init__(self, *args, **kwargs):
)
super(Creator, self).__init__(*args, **kwargs)

def _method_is_overriden(self, method_name):
cls_method = getattr(Creator, method_name)
obj_method = getattr(self.__class__, method_name)
return cls_method is not obj_method

@property
def show_order(self):
"""Order in which is creator shown in UI.
Expand Down Expand Up @@ -720,6 +738,11 @@ class HiddenCreator(BaseCreator):
def create(self, instance_data, source_data):
pass

def _method_is_overriden(self, method_name):
cls_method = getattr(HiddenCreator, method_name)
obj_method = getattr(self.__class__, method_name)
return cls_method is not obj_method


class AutoCreator(BaseCreator):
"""Creator which is automatically triggered without user interaction.
Expand All @@ -731,6 +754,11 @@ def remove_instances(self, instances):
"""Skip removement."""
pass

def _method_is_overriden(self, method_name):
cls_method = getattr(AutoCreator, method_name)
obj_method = getattr(self.__class__, method_name)
return cls_method is not obj_method


def discover_creator_plugins(*args, **kwargs):
return discover(BaseCreator, *args, **kwargs)
Expand Down
Loading