Closed tws0002 closed 5 years ago
The publish system is a group of Python callable that runs when called the anima.publish.run_publishers()
function.
The anima.publish
module provides a Python Decorator called publisher
that registers the decorated function as a publisher.
You can simply register a Python function as a publisher as follows (in my_publishers.py
):
from anima.publish import publisher
@publisher
def this_is_a_generic_publish_function1():
"""this function is a generic publisher
"""
# do something meaningful here
# that is important for you at publish time
print("this publisher has run!")
Later on you can call all the publishers by calling the run_publishers
helper function (in my_env.py
).
from anima.publish import run_publishers
run_publishers()
This will simply output this publisher has run!
to the console.
Also you can define types for publishers:
from anima.publish import publisher
@publisher("model")
def model_publisher1():
"""this publisher is in model type
"""
print("model publisher 1 has run!)
With this last code, we now have two publishers. If we call run_publishers()
only the first publisher will run (publishers with no types or empty types are called Generic Publisher):
run_publishers()
Outputs:
this publisher has run!
But if we call run_publishers("model")
both Generic Publishers and publishers whose types are set to model
will run:
run_publishers("model")
Outputs:
this publisher has run!
model publisher 1 has run!
This is a very powerful system, that let one to automate quality control routines to run for, let say, published versions (in my_env.py
):
def save_as(version):
"""my custom save routine for my application
"""
if version.is_published:
from anima.publish import run_publishers
type_name = ''
if version.task.type:
type_name = version.task.type.name
run_publishers(type_name)
Also if you would like to be able to reach to the published Version
, you can do so by using the staging
module variable, which is a dictionary that holds temporary data.
Let's say that you would like to use the Version
instance in your publisher, do something like this (in my_publishers.py
:
from anima.publish import publisher, staging
@publisher
def my_publisher():
"""this publisher can use the Version instance which is
about to be published.
"""
v = staging.get("version")
if v:
# do something related with the Version instance
print("the version.number is: %s" % v.version_number)
So the modified save_as
routine should fill the Version
instance before calling the run_publishers
(in my_env.py
):
def save_as(version):
"""my custom save routine for my application
"""
if version.is_published:
from anima.publish import run_publishers, staging
# add the current Version instance to staging
# so the publishers which need it can reach it
staging["version"] = version
type_name = ''
if version.task.type:
type_name = version.task.type.name
run_publishers(type_name)
This will output (for example):
The version.number is: 001
So the publisher can reach the Version
that is about to be published.
Also for any errors that needs to be raised by the publisher functions, the PublishError
should be used:
from anima.publish import publisher, version
from anima.exc import PublishError
@publisher
def my_publisher1():
"""This publisher raises PublishError for anything
it doesn't like
"""
# check for something
if version.version_number == 1:
# and raise PublishError
# if you don't like it
raise PublishError("You can not publish the first version!")
So that's about it. It is a very powerful way of creating automated quality control scripts to your pipeline without making your save_as
routines bloated.
The anima.env.mayaEnv.publish
module has a lot of publishers that you can use a an example. Also check the anima.env.mayaEnv.Maya.save_as()
for how I call the run_publishers()
.
Also I have implemented a publisher UI ( anima.ui.dialog.publish_checker
) that is shown when the publishers run, it simply informs the user about the publisher progress and about the errors if any. You can also check that out.
hi,
can you explain more about publish workflow in anima pipeline?
Thanks, Desmond