Had some ideas on how to take this to the next level.
$ pyblish
Simply calling pyblish
launches the GUI. The GUI then uses the current directory as the current “workspace”, much like how publishing from Maya is using it’s internal state. All that you select, validate and so forth is based on this state.
Launching from the command-line in the same sense uses the current working directory.
Example
/root
my_scene.mb
Running pyblish
from /root
have access to it’s content, like running Pyblish from within Maya have access to all of the data currently in the scene.
A selector could look like this.
class SelectMayaScenes(...):
def process_context(self, context):
cwd = context.data("cwd")
for fname in os.listdir(cwd):
if fname.endswith(".mb") or fname.endswith(".ma"):
instance = context.create_instance(name=scene)
instance.set_data("family", "mayaScene")
abspath = os.path.join(cwd, fname)
instance.set_data("abspath", abspath)
instance.set_data("size", os.path.getsize(abspath))
A validator could look like this.
class ValidateMayaScene(...):
families = ["mayaScene"]
def process_instance(self, instance):
assert instance.data("size") < (2 * 1000**3), "File is larger than 2 gb"
A plug-in could also dive further into the file if needed.
import os
import inspect
import subprocess
def test():
"""Function to run in mayapy"""
import os
import maya.standalone
maya.standalone.initialize()
from maya import cmds
cmds.file(os.environ["ABSPATH"], open=True)
assert "MyCube" in cmds.ls()
class ValidateMayaScene(...):
families = ["mayaScene"]
def process_instance(self, instance):
# Pass data to Maya
os.environ["ABSPATH"] = instance.data("abspath")
os.environ["PATH"] += ";%s" % mayapy
script = inspect.getsource(test) + "test()"
assert subprocess.call(["mayapy", "-c", script]) == 0, "MyCube is missing"
Publishing Fixture
Here’s the part that got me fascinated with this approach.
/MyAsset
data.yaml # (Optional) Custom data passed to the context
config.yaml # (Optional) Custom configuration
my_scene.mb
Data is applied to the Context
from data.yaml
(if one exists) and can be used to persist various options that are to be used in plug-ins, whereas the configuration is applied the same way and can specify where to find plug-ins.
So, down the line, one could produce fixtures as an intermediate step between a development file, like a Maya or Houdini scene, and a final publish, to be triggered or modified at a later time, by calling Pyblish from the command-line.
/MyAsset
/rig
data.yaml
config.yaml
scene_v005.mb
/model
data.yaml
config.yaml
scene_v001.mb
Usage
$ cd /server/assets/MyAsset/rig
$ pyblish # Launch the GUI
$ pyblish publish # Or publish directly
Future
This would also lay the groundwork for future features.
Also, here’s the original issue about the CLI.