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

General: Static interfaces #2238

Merged
merged 7 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
72 changes: 12 additions & 60 deletions openpype/modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,9 @@ def __getattr__(self, attr_name):
if attr_name in ("__path__", "__file__"):
return None

# Fake Interface if is not missing
self.__attributes__[attr_name] = type(
attr_name,
(MissingInteface, ),
{}
)
raise ImportError((
"cannot import name '{}' from 'openpype_interfaces'"
).format(attr_name))

return self.__attributes__[attr_name]

Expand Down Expand Up @@ -212,54 +209,17 @@ def _load_interfaces():
_InterfacesClass(modules_key)
)

log = PypeLogger.get_logger("InterfacesLoader")

dirpaths = get_module_dirs()

interface_paths = []
interface_paths.append(
os.path.join(get_default_modules_dir(), "interfaces.py")
)
for dirpath in dirpaths:
if not os.path.exists(dirpath):
continue

for filename in os.listdir(dirpath):
if filename in ("__pycache__", ):
continue

full_path = os.path.join(dirpath, filename)
if not os.path.isdir(full_path):
continue

interfaces_path = os.path.join(full_path, "interfaces.py")
if os.path.exists(interfaces_path):
interface_paths.append(interfaces_path)
from . import interfaces

for full_path in interface_paths:
if not os.path.exists(full_path):
for attr_name in dir(interfaces):
attr = getattr(interfaces, attr_name)
if (
not inspect.isclass(attr)
or attr is OpenPypeInterface
or not issubclass(attr, OpenPypeInterface)
):
continue

try:
# Prepare module object where content of file will be parsed
module = import_filepath(full_path)

except Exception:
log.warning(
"Failed to load path: \"{0}\"".format(full_path),
exc_info=True
)
continue

for attr_name in dir(module):
attr = getattr(module, attr_name)
if (
not inspect.isclass(attr)
or attr is OpenPypeInterface
or not issubclass(attr, OpenPypeInterface)
):
continue
setattr(openpype_interfaces, attr_name, attr)
setattr(openpype_interfaces, attr_name, attr)


def load_modules(force=False):
Expand Down Expand Up @@ -369,14 +329,6 @@ class OpenPypeInterface:
pass


class MissingInteface(OpenPypeInterface):
"""Class representing missing interface class.

Used when interface is not available from currently registered paths.
"""
pass


@six.add_metaclass(ABCMeta)
class OpenPypeModule:
"""Base class of pype module.
Expand Down
30 changes: 0 additions & 30 deletions openpype/modules/default_modules/settings_module/interfaces.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import os
import platform
from openpype.modules import OpenPypeModule
from openpype_interfaces import (
ITimersManager,
ITrayService
)
from openpype_interfaces import ITrayService
from avalon.api import AvalonMongoDB


Expand Down
16 changes: 0 additions & 16 deletions openpype/modules/example_addons/example_addon/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
)
# Import interface defined by this addon to be able find other addons using it
from openpype_interfaces import (
IExampleInterface,
IPluginPaths,
ITrayAction
)
Expand Down Expand Up @@ -75,19 +74,6 @@ def tray_init(self):

self._create_dialog()

def connect_with_modules(self, enabled_modules):
"""Method where you should find connected modules.

It is triggered by OpenPype modules manager at the best possible time.
Some addons and modules may required to connect with other modules
before their main logic is executed so changes would require to restart
whole process.
"""
self._connected_modules = []
for module in enabled_modules:
if isinstance(module, IExampleInterface):
self._connected_modules.append(module)

def _create_dialog(self):
# Don't recreate dialog if already exists
if self._dialog is not None:
Expand All @@ -106,8 +92,6 @@ def show_dialog(self):
"""
# Make sure dialog is created
self._create_dialog()
# Change value of dialog by current state
self._dialog.set_connected_modules(self.get_connected_modules())
# Show dialog
self._dialog.open()

Expand Down
28 changes: 0 additions & 28 deletions openpype/modules/example_addons/example_addon/interfaces.py

This file was deleted.

12 changes: 2 additions & 10 deletions openpype/modules/example_addons/example_addon/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def __init__(self, parent=None):

self.setWindowTitle("Connected modules")

label_widget = QtWidgets.QLabel(self)
msg = "This is example dialog of example addon."
label_widget = QtWidgets.QLabel(msg, self)

ok_btn = QtWidgets.QPushButton("OK", self)
btns_layout = QtWidgets.QHBoxLayout()
Expand All @@ -28,12 +29,3 @@ def __init__(self, parent=None):

def _on_ok_clicked(self):
self.done(1)

def set_connected_modules(self, connected_modules):
if connected_modules:
message = "\n".join(connected_modules)
else:
message = (
"Other enabled modules/addons are not using my interface."
)
self._label_widget.setText(message)
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,31 @@ def set_service_idle_icon(self):
"""Change icon of an QAction to orange circle."""
if self.menu_action:
self.menu_action.setIcon(self.get_icon_idle())


class ISettingsChangeListener(OpenPypeInterface):
"""Module has plugin paths to return.

Expected result is dictionary with keys "publish", "create", "load" or
"actions" and values as list or string.
{
"publish": ["path/to/publish_plugins"]
}
"""
@abstractmethod
def on_system_settings_save(
self, old_value, new_value, changes, new_value_metadata
):
pass

@abstractmethod
def on_project_settings_save(
self, old_value, new_value, changes, project_name, new_value_metadata
):
pass

@abstractmethod
def on_project_anatomy_save(
self, old_value, new_value, changes, project_name, new_value_metadata
):
pass