mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Merge pull request #3337 from pypeclub/feature/OP-3315_Host-implementation-defined-with-class
This commit is contained in:
commit
f277640da5
15 changed files with 810 additions and 196 deletions
|
|
@ -1,11 +1,9 @@
|
|||
"""Core pipeline functionality"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import types
|
||||
import logging
|
||||
import inspect
|
||||
import platform
|
||||
|
||||
import pyblish.api
|
||||
|
|
@ -232,73 +230,10 @@ def register_host(host):
|
|||
required, or browse the source code.
|
||||
|
||||
"""
|
||||
signatures = {
|
||||
"ls": []
|
||||
}
|
||||
|
||||
_validate_signature(host, signatures)
|
||||
_registered_host["_"] = host
|
||||
|
||||
|
||||
def _validate_signature(module, signatures):
|
||||
# Required signatures for each member
|
||||
|
||||
missing = list()
|
||||
invalid = list()
|
||||
success = True
|
||||
|
||||
for member in signatures:
|
||||
if not hasattr(module, member):
|
||||
missing.append(member)
|
||||
success = False
|
||||
|
||||
else:
|
||||
attr = getattr(module, member)
|
||||
if sys.version_info.major >= 3:
|
||||
signature = inspect.getfullargspec(attr)[0]
|
||||
else:
|
||||
signature = inspect.getargspec(attr)[0]
|
||||
required_signature = signatures[member]
|
||||
|
||||
assert isinstance(signature, list)
|
||||
assert isinstance(required_signature, list)
|
||||
|
||||
if not all(member in signature
|
||||
for member in required_signature):
|
||||
invalid.append({
|
||||
"member": member,
|
||||
"signature": ", ".join(signature),
|
||||
"required": ", ".join(required_signature)
|
||||
})
|
||||
success = False
|
||||
|
||||
if not success:
|
||||
report = list()
|
||||
|
||||
if missing:
|
||||
report.append(
|
||||
"Incomplete interface for module: '%s'\n"
|
||||
"Missing: %s" % (module, ", ".join(
|
||||
"'%s'" % member for member in missing))
|
||||
)
|
||||
|
||||
if invalid:
|
||||
report.append(
|
||||
"'%s': One or more members were found, but didn't "
|
||||
"have the right argument signature." % module.__name__
|
||||
)
|
||||
|
||||
for member in invalid:
|
||||
report.append(
|
||||
" Found: {member}({signature})".format(**member)
|
||||
)
|
||||
report.append(
|
||||
" Expected: {member}({required})".format(**member)
|
||||
)
|
||||
|
||||
raise ValueError("\n".join(report))
|
||||
|
||||
|
||||
def registered_host():
|
||||
"""Return currently registered host"""
|
||||
return _registered_host["_"]
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import inspect
|
|||
from uuid import uuid4
|
||||
from contextlib import contextmanager
|
||||
|
||||
from openpype.host import INewPublisher
|
||||
from openpype.pipeline import legacy_io
|
||||
from openpype.pipeline.mongodb import (
|
||||
AvalonMongoDB,
|
||||
|
|
@ -651,12 +652,6 @@ class CreateContext:
|
|||
discover_publish_plugins(bool): Discover publish plugins during reset
|
||||
phase.
|
||||
"""
|
||||
# Methods required in host implementaion to be able create instances
|
||||
# or change context data.
|
||||
required_methods = (
|
||||
"get_context_data",
|
||||
"update_context_data"
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self, host, dbcon=None, headless=False, reset=True,
|
||||
|
|
@ -738,10 +733,10 @@ class CreateContext:
|
|||
Args:
|
||||
host(ModuleType): Host implementaion.
|
||||
"""
|
||||
missing = set()
|
||||
for attr_name in cls.required_methods:
|
||||
if not hasattr(host, attr_name):
|
||||
missing.add(attr_name)
|
||||
|
||||
missing = set(
|
||||
INewPublisher.get_missing_publish_methods(host)
|
||||
)
|
||||
return missing
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -18,9 +18,13 @@ _database = database = None
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def is_installed():
|
||||
return module._is_installed
|
||||
|
||||
|
||||
def install():
|
||||
"""Establish a persistent connection to the database"""
|
||||
if module._is_installed:
|
||||
if is_installed():
|
||||
return
|
||||
|
||||
session = session_data_from_environment(context_keys=True)
|
||||
|
|
@ -55,7 +59,7 @@ def uninstall():
|
|||
def requires_install(func):
|
||||
@functools.wraps(func)
|
||||
def decorated(*args, **kwargs):
|
||||
if not module._is_installed:
|
||||
if not is_installed():
|
||||
install()
|
||||
return func(*args, **kwargs)
|
||||
return decorated
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue