replace avalon imports in pipeline

This commit is contained in:
Jakub Trllo 2022-04-14 12:36:53 +02:00
parent e75170d5c6
commit 3772e1d68c
5 changed files with 36 additions and 40 deletions

View file

@ -3,6 +3,10 @@ from .constants import (
HOST_WORKFILE_EXTENSIONS,
)
from .mongodb import (
AvalonMongoDB,
)
from .create import (
BaseCreator,
Creator,
@ -85,16 +89,13 @@ from .context_tools import (
install = install_host
uninstall = uninstall_host
from .mongodb import (
AvalonMongoDB,
)
__all__ = (
"AVALON_CONTAINER_ID",
"HOST_WORKFILE_EXTENSIONS",
"attribute_definitions",
# --- MongoDB ---
"AvalonMongoDB",
# --- Create ---
"BaseCreator",
@ -174,6 +175,4 @@ __all__ = (
# Backwards compatible function names
"install",
"uninstall",
"AvalonMongoDB",
)

View file

@ -11,8 +11,6 @@ import platform
import pyblish.api
from pyblish.lib import MessageHandler
from avalon import io, Session
import openpype
from openpype.modules import load_modules
from openpype.settings import get_project_settings
@ -24,6 +22,7 @@ from openpype.lib import (
)
from . import (
legacy_io,
register_loader_plugin_path,
register_inventory_action,
register_creator_plugin_path,
@ -57,7 +56,7 @@ def registered_root():
if root:
return root
root = Session.get("AVALON_PROJECTS")
root = legacy_io.Session.get("AVALON_PROJECTS")
if root:
return os.path.normpath(root)
return ""
@ -74,20 +73,20 @@ def install_host(host):
_is_installed = True
io.install()
legacy_io.install()
missing = list()
for key in ("AVALON_PROJECT", "AVALON_ASSET"):
if key not in Session:
if key not in legacy_io.Session:
missing.append(key)
assert not missing, (
"%s missing from environment, %s" % (
", ".join(missing),
json.dumps(Session, indent=4, sort_keys=True)
json.dumps(legacy_io.Session, indent=4, sort_keys=True)
))
project_name = Session["AVALON_PROJECT"]
project_name = legacy_io.Session["AVALON_PROJECT"]
log.info("Activating %s.." % project_name)
# Optional host install function
@ -170,7 +169,7 @@ def uninstall_host():
deregister_host()
io.uninstall()
legacy_io.uninstall()
log.info("Successfully uninstalled Avalon!")

View file

@ -6,13 +6,13 @@ import inspect
from uuid import uuid4
from contextlib import contextmanager
from openpype.pipeline import legacy_io
from openpype.pipeline.mongodb import (
AvalonMongoDB,
session_data_from_environment,
)
from .creator_plugins import (
BaseCreator,
Creator,
AutoCreator,
discover_creator_plugins,
@ -773,12 +773,11 @@ class CreateContext:
"""Give ability to reset avalon context.
Reset is based on optional host implementation of `get_current_context`
function or using `avalon.api.Session`.
function or using `legacy_io.Session`.
Some hosts have ability to change context file without using workfiles
tool but that change is not propagated to
"""
import avalon.api
project_name = asset_name = task_name = None
if hasattr(self.host, "get_current_context"):
@ -789,11 +788,11 @@ class CreateContext:
task_name = host_context.get("task_name")
if not project_name:
project_name = avalon.api.Session.get("AVALON_PROJECT")
project_name = legacy_io.Session.get("AVALON_PROJECT")
if not asset_name:
asset_name = avalon.api.Session.get("AVALON_ASSET")
asset_name = legacy_io.Session.get("AVALON_ASSET")
if not task_name:
task_name = avalon.api.Session.get("AVALON_TASK")
task_name = legacy_io.Session.get("AVALON_TASK")
if project_name:
self.dbcon.Session["AVALON_PROJECT"] = project_name
@ -808,7 +807,6 @@ class CreateContext:
Reloads creators from preregistered paths and can load publish plugins
if it's enabled on context.
"""
import avalon.api
import pyblish.logic
from openpype.pipeline import OpenPypePyblishPluginMixin

View file

@ -9,11 +9,11 @@ import numbers
import six
from bson.objectid import ObjectId
from avalon import io
from avalon.api import Session
from openpype.lib import Anatomy
from openpype.pipeline import schema
from openpype.pipeline import (
schema,
legacy_io,
)
log = logging.getLogger(__name__)
@ -60,7 +60,7 @@ def get_repres_contexts(representation_ids, dbcon=None):
"""
if not dbcon:
dbcon = io
dbcon = legacy_io
contexts = {}
if not representation_ids:
@ -167,7 +167,7 @@ def get_subset_contexts(subset_ids, dbcon=None):
dict: The full representation context by representation id.
"""
if not dbcon:
dbcon = io
dbcon = legacy_io
contexts = {}
if not subset_ids:
@ -230,10 +230,10 @@ def get_representation_context(representation):
assert representation is not None, "This is a bug"
if isinstance(representation, (six.string_types, ObjectId)):
representation = io.find_one(
representation = legacy_io.find_one(
{"_id": ObjectId(str(representation))})
version, subset, asset, project = io.parenthood(representation)
version, subset, asset, project = legacy_io.parenthood(representation)
assert all([representation, version, subset, asset, project]), (
"This is a bug"
@ -405,17 +405,17 @@ def update_container(container, version=-1):
"""Update a container"""
# Compute the different version from 'representation'
current_representation = io.find_one({
current_representation = legacy_io.find_one({
"_id": ObjectId(container["representation"])
})
assert current_representation is not None, "This is a bug"
current_version, subset, asset, project = io.parenthood(
current_version, subset, asset, project = legacy_io.parenthood(
current_representation)
if version == -1:
new_version = io.find_one({
new_version = legacy_io.find_one({
"type": "version",
"parent": subset["_id"]
}, sort=[("name", -1)])
@ -431,11 +431,11 @@ def update_container(container, version=-1):
"type": "version",
"name": version
}
new_version = io.find_one(version_query)
new_version = legacy_io.find_one(version_query)
assert new_version is not None, "This is a bug"
new_representation = io.find_one({
new_representation = legacy_io.find_one({
"type": "representation",
"parent": new_version["_id"],
"name": current_representation["name"]
@ -482,7 +482,7 @@ def switch_container(container, representation, loader_plugin=None):
))
# Get the new representation to switch to
new_representation = io.find_one({
new_representation = legacy_io.find_one({
"type": "representation",
"_id": representation["_id"],
})
@ -501,7 +501,7 @@ def get_representation_path_from_context(context):
representation = context['representation']
project_doc = context.get("project")
root = None
session_project = Session.get("AVALON_PROJECT")
session_project = legacy_io.Session.get("AVALON_PROJECT")
if project_doc and project_doc["name"] != session_project:
anatomy = Anatomy(project_doc["name"])
root = anatomy.roots
@ -530,7 +530,7 @@ def get_representation_path(representation, root=None, dbcon=None):
from openpype.lib import StringTemplate, TemplateUnsolved
if dbcon is None:
dbcon = io
dbcon = legacy_io
if root is None:
from openpype.pipeline import registered_root

View file

@ -2,6 +2,7 @@ import os
import copy
import logging
from . import legacy_io
from .plugin_discover import (
discover,
register_plugin,
@ -17,8 +18,7 @@ def get_thumbnail_binary(thumbnail_entity, thumbnail_type, dbcon=None):
resolvers = discover_thumbnail_resolvers()
resolvers = sorted(resolvers, key=lambda cls: cls.priority)
if dbcon is None:
from avalon import io
dbcon = io
dbcon = legacy_io
for Resolver in resolvers:
available_types = Resolver.thumbnail_types