Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maya: Workfile testing #5

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions client/ayon_maya/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
MayaHost,
)
from .plugin import (
Creator,
Loader
)

Expand Down Expand Up @@ -44,6 +45,7 @@
"containerise",
"MayaHost",

"Creator",
"Loader",

# Workfiles API
Expand Down
11 changes: 1 addition & 10 deletions client/ayon_maya/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ def is_valid_reference_node(reference_node):
Reference node 'reference_node' is not associated with a reference file.

Note that this does *not* check whether the reference node points to an
existing file. Instead, it only returns whether maya considers it valid
existing file. Instead it only returns whether maya considers it valid
and thus is not an unassociated reference node

Arguments:
Expand All @@ -1746,18 +1746,9 @@ def is_valid_reference_node(reference_node):
bool: Whether reference node is a valid reference

"""
# maya 2022 is missing `isValidReference` so the check needs to be
# done in different way.
if int(cmds.about(version=True)) < 2023:
try:
cmds.referenceQuery(reference_node, filename=True)
return True
except RuntimeError:
return False
sel = OpenMaya.MSelectionList()
sel.add(reference_node)
depend_node = sel.getDependNode(0)

return OpenMaya.MFnReference(depend_node).isValidReference()


Expand Down
13 changes: 12 additions & 1 deletion client/ayon_maya/api/lib_rendersettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,20 @@ def _set_arnold_settings(self, width, height):
current_aovs = AOVInterface().getAOVs()
remove_aovs = render_settings["remove_aovs"]
if remove_aovs:
# Remove fetched AOVs
# Remove fetched AOVs
AOVInterface().removeAOVs(current_aovs)

# Need to reset the cameras renderable state after
# "unifiedRenderGlobalsRevertToDefault".
renderable_by_camera = {}
for camera in cmds.ls(type="camera"):
renderable_by_camera[camera] = cmds.getAttr(camera + ".renderable")

mel.eval("unifiedRenderGlobalsRevertToDefault")

for camera, value in renderable_by_camera.items():
cmds.setAttr(camera + ".renderable", value)

img_ext = arnold_render_presets["image_format"]
img_prefix = arnold_render_presets["image_prefix"]
aovs = arnold_render_presets["aov_list"]
Expand Down
88 changes: 76 additions & 12 deletions client/ayon_maya/api/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
from ayon_core.pipeline.workfile import BuildWorkfile
from ayon_core.tools.utils import host_tools
from ayon_maya.api import lib, lib_rendersettings
from ayon_core.settings import get_project_settings
from ayon_core.pipeline import get_current_project_name

from .lib import get_main_window, IS_HEADLESS
from ..tools import show_look_assigner

from .workfile_template_builder import (
create_placeholder,
update_placeholder,
Expand All @@ -28,6 +30,16 @@
from ayon_core.pipeline.context_tools import version_up_current_workfile
from ayon_core.tools.workfile_template_build import open_template_ui
from .workfile_template_builder import MayaTemplateBuilder
from .testing import (
run_tests_on_repository_workfile,
test_create_on_repository_workfile,
test_publish_on_repository_workfile,
test_load_on_repository_workfile,
run_tests,
test_create,
test_publish,
test_load
)

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -56,6 +68,10 @@ def install(project_settings):
return

def add_menu():
project_settings = get_project_settings(
get_current_project_name()
)

pyblish_icon = host_tools.get_pyblish_icon()
parent_widget = get_main_window()
cmds.menu(
Expand All @@ -75,17 +91,13 @@ def add_menu():

cmds.setParent("..", menu=True)

try:
if project_settings["core"]["tools"]["ayon_menu"].get(
"version_up_current_workfile"):
cmds.menuItem(divider=True)
cmds.menuItem(
"Version Up Workfile",
command=lambda *args: version_up_current_workfile()
)
except KeyError:
print("Version Up Workfile setting not found in "
"Core Settings. Please update Core Addon")
if project_settings["core"]["tools"]["ayon_menu"].get(
"version_up_current_workfile"):
cmds.menuItem(divider=True)
cmds.menuItem(
"Version Up Workfile",
command=lambda *args: version_up_current_workfile()
)

cmds.menuItem(divider=True)

Expand Down Expand Up @@ -216,6 +228,58 @@ def add_menu():
command=update_placeholder
)

if not project_settings["maya"].get("workfile_testing", False):
cmds.setParent(MENU_NAME, menu=True)
return

testing_menu = cmds.menuItem(
"Testing",
subMenu=True,
tearOff=True,
parent=MENU_NAME
)
cmds.menuItem(
"Run Tests On Repository Workfile",
parent=testing_menu,
command=lambda *args: run_tests_on_repository_workfile()
)
cmds.menuItem(
"Test Create On Repository Workfile",
parent=testing_menu,
command=lambda *args: test_create_on_repository_workfile()
)
cmds.menuItem(
"Test Publish On Repository Workfile",
parent=testing_menu,
command=lambda *args: test_publish_on_repository_workfile()
)
cmds.menuItem(
"Test Load On Repository Workfile",
parent=testing_menu,
command=lambda *args: test_load_on_repository_workfile()
)
cmds.menuItem(divider=True)
cmds.menuItem(
"Run Tests On Current Workfile",
parent=testing_menu,
command=lambda *args: run_tests()
)
cmds.menuItem(
"Test Create On Current Workfile",
parent=testing_menu,
command=lambda *args: test_create()
)
cmds.menuItem(
"Test Publish On Current Workfile",
parent=testing_menu,
command=lambda *args: test_publish()
)
cmds.menuItem(
"Test Load On Current Workfile",
parent=testing_menu,
command=lambda *args: test_load()
)

cmds.setParent(MENU_NAME, menu=True)

def add_scripts_menu(project_settings):
Expand Down
29 changes: 25 additions & 4 deletions client/ayon_maya/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
Anatomy,
AutoCreator,
CreatedInstance,
Creator,
Creator as NewCreator,
CreatorError,
HiddenCreator,
LegacyCreator,
LoaderPlugin,
get_current_project_name,
get_representation_path,
Expand Down Expand Up @@ -69,6 +70,22 @@ def get_reference_node_parents(*args, **kwargs):
return lib.get_reference_node_parents(*args, **kwargs)


class Creator(LegacyCreator):
defaults = ['Main']

def process(self):
nodes = list()

with lib.undo_chunk():
if (self.options or {}).get("useSelection"):
nodes = cmds.ls(selection=True)

instance = cmds.sets(nodes, name=self.name)
lib.imprint(instance, self.data)

return instance


@six.add_metaclass(ABCMeta)
class MayaCreatorBase(object):

Expand Down Expand Up @@ -257,7 +274,7 @@ def _default_remove_instances(self, instances):


@six.add_metaclass(ABCMeta)
class MayaCreator(Creator, MayaCreatorBase):
class MayaCreator(NewCreator, MayaCreatorBase):

settings_category = "maya"

Expand Down Expand Up @@ -364,7 +381,7 @@ def ensure_namespace(namespace):
return cmds.namespace(add=namespace)


class RenderlayerCreator(Creator, MayaCreatorBase):
class RenderlayerCreator(NewCreator, MayaCreatorBase):
"""Creator which creates an instance per renderlayer in the workfile.

Create and manages renderlayer product per renderLayer in workfile.
Expand Down Expand Up @@ -404,7 +421,7 @@ def create(self, product_name, instance_data, pre_create_data):
# By RenderLayerCreator.create we make it so that the renderlayer
# instances directly appear even though it just collects scene
# renderlayers. This doesn't actually 'create' any scene contents.
self.collect_instances()
return self.collect_instances()

def create_singleton_node(self):
if self._get_singleton_node():
Expand All @@ -428,6 +445,7 @@ def collect_instances(self):
host_name = self.create_context.host_name
rs = renderSetup.instance()
layers = rs.getRenderLayers()
instances = []
for layer in layers:
layer_instance_node = self.find_layer_instance_node(layer)
if layer_instance_node:
Expand Down Expand Up @@ -468,6 +486,9 @@ def collect_instances(self):

instance.transient_data["layer"] = layer
self._add_instance_to_context(instance)
instances.append(instance)

return instances

def find_layer_instance_node(self, layer):
connected_sets = cmds.listConnections(
Expand Down
24 changes: 24 additions & 0 deletions client/ayon_maya/api/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from .lib import (
run_tests,
run_tests_on_repository_workfile,
test_create_on_repository_workfile,
test_publish_on_repository_workfile,
test_load_on_repository_workfile
)

from .tests import (
test_create,
test_publish,
test_load,
)

__all__ = [
"run_tests",
"run_tests_on_repository_workfile",
"test_create_on_repository_workfile",
"test_publish_on_repository_workfile",
"test_load_on_repository_workfile",
"test_create",
"test_publish",
"test_load",
]
Loading