ayon-core
ayon-core copied to clipboard
Publisher: Support dynamic/cached attribute definitions
Is your feature request related to a problem? Please describe.
I'd like to expose the primaryPool
and secondaryPool
to the user in the New Publisher.
I thought of adding this to Collect Deadline Pools:
@classmethod
def get_attribute_defs(cls):
manager = ModulesManager()
deadline_module = manager.modules_by_name["deadline"]
pools = deadline_module.get_deadline_pools(deadline_url)
pools_enum = {key: key for key in pools}
from openpype.lib import EnumDef
return [
EnumDef("primaryPool",
label="Primary Pool",
default=cls.primary_pool,
items=pools_enum),
EnumDef("secondaryPool",
label="Secondary Pool",
default=cls.secondary_pool,
items=pools_enum),
]
However the studio and user could customize the Deadline Webservice URL and the deadline pools would be a dynamic result.
For example this logic is used in maya:
try:
default_servers = deadline_settings["deadline_urls"]
project_servers = (
self._project_settings["deadline"]["deadline_servers"]
)
self.deadline_servers = {
k: default_servers[k]
for k in project_servers
if k in default_servers
}
if not self.deadline_servers:
self.deadline_servers = default_servers
except AttributeError:
# Handle situation were we had only one url for deadline.
# get default deadline webservice url from deadline module
self.deadline_servers = self.deadline_module.deadline_urls
Describe the solution you'd like
- Be able to delay the query of e.g.
deadline_module.get_deadline_pools(deadline_url)
to when it'd be needed - e.g. so that it updates the Pools list when clicking on the Enum for the first time. - Be able to "update" the available pool list e.g. another attribute definition would be changed, like the Deadline URL
Here's some pseudocode:
@classmethod
def get_attribute_defs(cls):
from openpype.lib import EnumDef
from functools import partial
url_def = EnumDef("url",
label="Webservice URL",
items=project_deadline_urls)
def get_pools(_url_def):
"""Return pool list based on value of url EnumDef"""
url = _url_def.value
manager = ModulesManager()
deadline_module = manager.modules_by_name["deadline"]
pools = deadline_module.get_deadline_pools(url)
return {key: key for key in pools}
fn_get_pools = partial(get_pools, url_def)
primary_pool_def = EnumDef("primaryPool",
label="Primary Pool",
default=cls.primary_pool,
itemgetter=fn_get_pools)
secondary_pool_def = EnumDef("secondaryPool",
label="Secondary Pool",
default=cls.secondary_pool,
itemgetter=fn_get_pools)
url_def.valueChanged.connect(primary_pool_def.updateItems)
url_def.valueChanged.connect(secondary_pool_def.updateItems)
return [
url_def,
primary_pool_def,
secondary_pool_def
]
Describe alternatives you've considered
Not sure what other approaches there are for the new publisher to expose this.
Additional context
[cuID:OP-4827]