Currently working on the integration of OpenCue with OpenPype, I face a problem I’ve had trouble to deal with since I’ve started working on OP core code: regarding the publish system, a lot of things rely on metadata dicts, and they are not documented anywhere. It is very tedious to guess which key is required and which one isn’t, where they belong (context.data
, instance.data
, representations
…) and what feature they are related to.
Creating documentation could be very helpful and a good start, but I’m afraid contributors won’t stick to it and as reviewers we easily forget this part.
My proposal is that we use classes and functions to build these metadata dicts. This way, we’ll be able to define which arguments are required and which one are optional (kwargs), and purpose of each argument will be documented in the docstring, where it is less likely to forget to add it (linter may be a great help as well).
For example, we could create an InstanceData
class which would look like:
class InstanceData(dict):
def __init__(self, family:str, subset:str, ..., comment="", ...):
"""blabla.
Args:
....
"""
self['family'] = family
self['subset'] = subset
self['comment'] = comment
def add_representations(representations: RepresentationData):
"""doc"""
if not isinstance(representations, Iterable):
representations = [representations]
self.setdefault('representations', []).extend(representations)
class RepresentationData(dict):
...