Skip to content

publish_plugins

AYONPyblishPluginMixin

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
class AYONPyblishPluginMixin:
    # TODO
    # executable_in_thread = False
    #
    # state_message = None
    # state_percent = None
    # _state_change_callbacks = []
    #
    # def set_state(self, percent=None, message=None):
    #     """Inner callback of plugin that would help to show in UI state.
    #
    #     Plugin have registered callbacks on state change which could trigger
    #     update message and percent in UI and repaint the change.
    #
    #     This part must be optional and should not be used to display errors
    #     or for logging.
    #
    #     Message should be short without details.
    #
    #     Args:
    #         percent(int): Percent of processing in range <1-100>.
    #         message(str): Message which will be shown to user (if in UI).
    #     """
    #     if percent is not None:
    #         self.state_percent = percent
    #
    #     if message:
    #         self.state_message = message
    #
    #     for callback in self._state_change_callbacks:
    #         callback(self)

    @classmethod
    def register_create_context_callbacks(
        cls, create_context: "CreateContext"
    ):
        """Register callbacks for create context.

        It is possible to register callbacks listening to changes happened
        in create context.

        Methods available on create context:
        - add_instances_added_callback
        - add_instances_removed_callback
        - add_value_changed_callback
        - add_pre_create_attr_defs_change_callback
        - add_create_attr_defs_change_callback
        - add_publish_attr_defs_change_callback

        Args:
            create_context (CreateContext): Create context.

        """
        pass

    @classmethod
    def get_attribute_defs(cls):
        """Publish attribute definitions.

        Attributes available for all families in plugin's `families` attribute.

        Returns:
            list[AbstractAttrDef]: Attribute definitions for plugin.

        """
        return []

    @classmethod
    def get_attr_defs_for_context(cls, create_context: "CreateContext"):
        """Publish attribute definitions for context.

        Attributes available for all families in plugin's `families` attribute.

        Args:
            create_context (CreateContext): Create context.

        Returns:
            list[AbstractAttrDef]: Attribute definitions for plugin.

        """
        if cls.__instanceEnabled__:
            return []
        return cls.get_attribute_defs()

    @classmethod
    def instance_matches_plugin_families(
        cls, instance: Optional["CreatedInstance"]
    ):
        """Check if instance matches families.

        Args:
            instance (Optional[CreatedInstance]): Instance to check. Or None
                for context.

        Returns:
            bool: True if instance matches plugin families.

        """
        if instance is None:
            return not cls.__instanceEnabled__

        if not cls.__instanceEnabled__:
            return False

        families = [instance.product_base_type]
        families.extend(instance.families)
        for _ in pyblish.logic.plugins_by_families([cls], families):
            return True
        return False

    @classmethod
    def get_attr_defs_for_instance(
        cls, create_context: "CreateContext", instance: "CreatedInstance"
    ):
        """Publish attribute definitions for an instance.

        Attributes available for all families in plugin's `families` attribute.

        Args:
            create_context (CreateContext): Create context.
            instance (CreatedInstance): Instance for which attributes are
                collected.

        Returns:
            list[AbstractAttrDef]: Attribute definitions for plugin.

        """
        if not cls.instance_matches_plugin_families(instance):
            return []
        return cls.get_attribute_defs()

    @classmethod
    def convert_attribute_values(
        cls, create_context: "CreateContext", instance: "CreatedInstance"
    ):
        """Convert attribute values for instance.

        Args:
            create_context (CreateContext): Create context.
            instance (CreatedInstance): Instance for which attributes are
                converted.

        """
        return

    @staticmethod
    def get_attr_values_from_data_for_plugin(plugin, data):
        """Get attribute values for attribute definitions from data.

        Args:
            plugin (Union[publish.api.Plugin, Type[publish.api.Plugin]]): The
                plugin for which attributes are extracted.
            data(dict): Data from instance or context.
        """

        if not inspect.isclass(plugin):
            plugin = plugin.__class__

        return (
            data
            .get("publish_attributes", {})
            .get(plugin.__name__, {})
        )

    def get_attr_values_from_data(self, data):
        """Get attribute values for attribute definitions from data.

        Args:
            data(dict): Data from instance or context.
        """

        return self.get_attr_values_from_data_for_plugin(self.__class__, data)

convert_attribute_values(create_context, instance) classmethod

Convert attribute values for instance.

Parameters:

Name Type Description Default
create_context CreateContext

Create context.

required
instance CreatedInstance

Instance for which attributes are converted.

required
Source code in client/ayon_core/pipeline/publish/publish_plugins.py
267
268
269
270
271
272
273
274
275
276
277
278
279
@classmethod
def convert_attribute_values(
    cls, create_context: "CreateContext", instance: "CreatedInstance"
):
    """Convert attribute values for instance.

    Args:
        create_context (CreateContext): Create context.
        instance (CreatedInstance): Instance for which attributes are
            converted.

    """
    return

get_attr_defs_for_context(create_context) classmethod

Publish attribute definitions for context.

Attributes available for all families in plugin's families attribute.

Parameters:

Name Type Description Default
create_context CreateContext

Create context.

required

Returns:

Type Description

list[AbstractAttrDef]: Attribute definitions for plugin.

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
@classmethod
def get_attr_defs_for_context(cls, create_context: "CreateContext"):
    """Publish attribute definitions for context.

    Attributes available for all families in plugin's `families` attribute.

    Args:
        create_context (CreateContext): Create context.

    Returns:
        list[AbstractAttrDef]: Attribute definitions for plugin.

    """
    if cls.__instanceEnabled__:
        return []
    return cls.get_attribute_defs()

get_attr_defs_for_instance(create_context, instance) classmethod

Publish attribute definitions for an instance.

Attributes available for all families in plugin's families attribute.

Parameters:

Name Type Description Default
create_context CreateContext

Create context.

required
instance CreatedInstance

Instance for which attributes are collected.

required

Returns:

Type Description

list[AbstractAttrDef]: Attribute definitions for plugin.

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
@classmethod
def get_attr_defs_for_instance(
    cls, create_context: "CreateContext", instance: "CreatedInstance"
):
    """Publish attribute definitions for an instance.

    Attributes available for all families in plugin's `families` attribute.

    Args:
        create_context (CreateContext): Create context.
        instance (CreatedInstance): Instance for which attributes are
            collected.

    Returns:
        list[AbstractAttrDef]: Attribute definitions for plugin.

    """
    if not cls.instance_matches_plugin_families(instance):
        return []
    return cls.get_attribute_defs()

get_attr_values_from_data(data)

Get attribute values for attribute definitions from data.

Parameters:

Name Type Description Default
data dict

Data from instance or context.

required
Source code in client/ayon_core/pipeline/publish/publish_plugins.py
300
301
302
303
304
305
306
307
def get_attr_values_from_data(self, data):
    """Get attribute values for attribute definitions from data.

    Args:
        data(dict): Data from instance or context.
    """

    return self.get_attr_values_from_data_for_plugin(self.__class__, data)

get_attr_values_from_data_for_plugin(plugin, data) staticmethod

Get attribute values for attribute definitions from data.

Parameters:

Name Type Description Default
plugin Union[Plugin, Type[Plugin]]

The plugin for which attributes are extracted.

required
data dict

Data from instance or context.

required
Source code in client/ayon_core/pipeline/publish/publish_plugins.py
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
@staticmethod
def get_attr_values_from_data_for_plugin(plugin, data):
    """Get attribute values for attribute definitions from data.

    Args:
        plugin (Union[publish.api.Plugin, Type[publish.api.Plugin]]): The
            plugin for which attributes are extracted.
        data(dict): Data from instance or context.
    """

    if not inspect.isclass(plugin):
        plugin = plugin.__class__

    return (
        data
        .get("publish_attributes", {})
        .get(plugin.__name__, {})
    )

get_attribute_defs() classmethod

Publish attribute definitions.

Attributes available for all families in plugin's families attribute.

Returns:

Type Description

list[AbstractAttrDef]: Attribute definitions for plugin.

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
191
192
193
194
195
196
197
198
199
200
201
@classmethod
def get_attribute_defs(cls):
    """Publish attribute definitions.

    Attributes available for all families in plugin's `families` attribute.

    Returns:
        list[AbstractAttrDef]: Attribute definitions for plugin.

    """
    return []

instance_matches_plugin_families(instance) classmethod

Check if instance matches families.

Parameters:

Name Type Description Default
instance Optional[CreatedInstance]

Instance to check. Or None for context.

required

Returns:

Name Type Description
bool

True if instance matches plugin families.

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
@classmethod
def instance_matches_plugin_families(
    cls, instance: Optional["CreatedInstance"]
):
    """Check if instance matches families.

    Args:
        instance (Optional[CreatedInstance]): Instance to check. Or None
            for context.

    Returns:
        bool: True if instance matches plugin families.

    """
    if instance is None:
        return not cls.__instanceEnabled__

    if not cls.__instanceEnabled__:
        return False

    families = [instance.product_base_type]
    families.extend(instance.families)
    for _ in pyblish.logic.plugins_by_families([cls], families):
        return True
    return False

register_create_context_callbacks(create_context) classmethod

Register callbacks for create context.

It is possible to register callbacks listening to changes happened in create context.

Methods available on create context: - add_instances_added_callback - add_instances_removed_callback - add_value_changed_callback - add_pre_create_attr_defs_change_callback - add_create_attr_defs_change_callback - add_publish_attr_defs_change_callback

Parameters:

Name Type Description Default
create_context CreateContext

Create context.

required
Source code in client/ayon_core/pipeline/publish/publish_plugins.py
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
@classmethod
def register_create_context_callbacks(
    cls, create_context: "CreateContext"
):
    """Register callbacks for create context.

    It is possible to register callbacks listening to changes happened
    in create context.

    Methods available on create context:
    - add_instances_added_callback
    - add_instances_removed_callback
    - add_value_changed_callback
    - add_pre_create_attr_defs_change_callback
    - add_create_attr_defs_change_callback
    - add_publish_attr_defs_change_callback

    Args:
        create_context (CreateContext): Create context.

    """
    pass

ColormanagedPyblishPluginMixin

Bases: object

Mixin for colormanaged plugins.

This class is used to set colorspace data to a publishing representation. It contains a static method, get_colorspace_settings, which returns config and file rules data for the host context. It also contains a method, set_representation_colorspace, which sets colorspace data to the representation. The allowed file extensions are listed in the allowed_ext variable. The method first checks if the file extension is in the list of allowed extensions. If it is, it then gets the colorspace settings from the host context and gets a matching colorspace from rules. Finally, it infuses this data into the representation.

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
class ColormanagedPyblishPluginMixin(object):
    """Mixin for colormanaged plugins.

    This class is used to set colorspace data to a publishing
    representation. It contains a static method,
    get_colorspace_settings, which returns config and
    file rules data for the host context.
    It also contains a method, set_representation_colorspace,
    which sets colorspace data to the representation.
    The allowed file extensions are listed in the allowed_ext variable.
    The method first checks if the file extension is in
    the list of allowed extensions. If it is, it then gets the
    colorspace settings from the host context and gets a
    matching colorspace from rules. Finally, it infuses this
    data into the representation.
    """

    def get_colorspace_settings(self, context):
        """Returns solved settings for the host context.

        Args:
            context (publish.Context): publishing context

        Returns:
            tuple | bool: config, file rules or None
        """
        return get_colorspace_settings_from_publish_context(context.data)

    def set_representation_colorspace(
        self, representation, context,
        colorspace=None,
    ):
        """Sets colorspace data to representation.

        Args:
            representation (dict): publishing representation
            context (publish.Context): publishing context
            colorspace (str, optional): colorspace name. Defaults to None.

        Example:
            ```
            {
                # for other publish plugins and loaders
                "colorspace": "linear",
                "config": {
                    # for future references in case need
                    "path": "/abs/path/to/config.ocio",
                    # for other plugins within remote publish cases
                    "template": "{project[root]}/path/to/config.ocio"
                }
            }
            ```

        """

        # using cached settings if available
        set_colorspace_data_to_representation(
            representation, context.data,
            colorspace,
            log=self.log
        )

get_colorspace_settings(context)

Returns solved settings for the host context.

Parameters:

Name Type Description Default
context Context

publishing context

required

Returns:

Type Description

tuple | bool: config, file rules or None

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
458
459
460
461
462
463
464
465
466
467
def get_colorspace_settings(self, context):
    """Returns solved settings for the host context.

    Args:
        context (publish.Context): publishing context

    Returns:
        tuple | bool: config, file rules or None
    """
    return get_colorspace_settings_from_publish_context(context.data)

set_representation_colorspace(representation, context, colorspace=None)

Sets colorspace data to representation.

Parameters:

Name Type Description Default
representation dict

publishing representation

required
context Context

publishing context

required
colorspace str

colorspace name. Defaults to None.

None
Example
{
    # for other publish plugins and loaders
    "colorspace": "linear",
    "config": {
        # for future references in case need
        "path": "/abs/path/to/config.ocio",
        # for other plugins within remote publish cases
        "template": "{project[root]}/path/to/config.ocio"
    }
}
Source code in client/ayon_core/pipeline/publish/publish_plugins.py
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
def set_representation_colorspace(
    self, representation, context,
    colorspace=None,
):
    """Sets colorspace data to representation.

    Args:
        representation (dict): publishing representation
        context (publish.Context): publishing context
        colorspace (str, optional): colorspace name. Defaults to None.

    Example:
        ```
        {
            # for other publish plugins and loaders
            "colorspace": "linear",
            "config": {
                # for future references in case need
                "path": "/abs/path/to/config.ocio",
                # for other plugins within remote publish cases
                "template": "{project[root]}/path/to/config.ocio"
            }
        }
        ```

    """

    # using cached settings if available
    set_colorspace_data_to_representation(
        representation, context.data,
        colorspace,
        log=self.log
    )

Extractor

Bases: InstancePlugin

Extractor base class.

The extractor base class implements a "staging_dir" function used to generate a temporary directory for an instance to extract to.

This temporary directory is generated through tempfile.mkdtemp()

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
class Extractor(pyblish.api.InstancePlugin):
    """Extractor base class.

    The extractor base class implements a "staging_dir" function used to
    generate a temporary directory for an instance to extract to.

    This temporary directory is generated through `tempfile.mkdtemp()`

    """

    order = 2.0

    def staging_dir(self, instance):
        """Provide a temporary directory in which to store extracted files

        Upon calling this method the staging directory is stored inside
        the instance.data['stagingDir']
        """

        return get_instance_staging_dir(instance)

staging_dir(instance)

Provide a temporary directory in which to store extracted files

Upon calling this method the staging directory is stored inside the instance.data['stagingDir']

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
431
432
433
434
435
436
437
438
def staging_dir(self, instance):
    """Provide a temporary directory in which to store extracted files

    Upon calling this method the staging directory is stored inside
    the instance.data['stagingDir']
    """

    return get_instance_staging_dir(instance)

KnownPublishError

Bases: Exception

Publishing crashed because of known error.

Artist can't affect source of the error.

Deprecated

Please use PublishError instead. Marked as deprecated 24/09/02.

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
39
40
41
42
43
44
45
46
47
48
class KnownPublishError(Exception):
    """Publishing crashed because of known error.

    Artist can't affect source of the error.

    Deprecated:
        Please use `PublishError` instead. Marked as deprecated 24/09/02.

    """
    pass

OptionalPyblishPluginMixin

Bases: AYONPyblishPluginMixin

Prepare mixin for optional plugins.

Defined active attribute definition prepared for published and prepares method which will check if is active or not.

class ValidateScene(
    pyblish.api.InstancePlugin, OptionalPyblishPluginMixin
):
    def process(self, instance):
        # Skip the instance if is not active by data on the instance
        if not self.is_active(instance.data):
            return
Source code in client/ayon_core/pipeline/publish/publish_plugins.py
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
class OptionalPyblishPluginMixin(AYONPyblishPluginMixin):
    """Prepare mixin for optional plugins.

    Defined active attribute definition prepared for published and
    prepares method which will check if is active or not.

    ```
    class ValidateScene(
        pyblish.api.InstancePlugin, OptionalPyblishPluginMixin
    ):
        def process(self, instance):
            # Skip the instance if is not active by data on the instance
            if not self.is_active(instance.data):
                return
    ```
    """

    # Allow exposing tooltip from class with `optional_tooltip` attribute
    optional_tooltip: Optional[str] = None

    @classmethod
    def get_attribute_defs(cls):
        """Attribute definitions based on plugin's optional attribute."""

        # Empty list if plugin is not optional
        if not getattr(cls, "optional", None):
            return []

        # Get active value from class as default value
        active = getattr(cls, "active", True)
        # Return boolean stored under 'active' key with label of the class name
        label = cls.label or cls.__name__

        return [
            BoolDef(
                "active",
                default=active,
                label=label,
                tooltip=cls.optional_tooltip,
            )
        ]

    def is_active(self, data):
        """Check if plugins is active for instance/context based on their data.

        Args:
            data(dict): Data from instance or context.
        """
        # Skip if is not optional and return True
        if not getattr(self, "optional", None):
            return True
        attr_values = self.get_attr_values_from_data(data)
        active = attr_values.get("active")
        if active is None:
            active = getattr(self, "active", True)
        return active

get_attribute_defs() classmethod

Attribute definitions based on plugin's optional attribute.

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
@classmethod
def get_attribute_defs(cls):
    """Attribute definitions based on plugin's optional attribute."""

    # Empty list if plugin is not optional
    if not getattr(cls, "optional", None):
        return []

    # Get active value from class as default value
    active = getattr(cls, "active", True)
    # Return boolean stored under 'active' key with label of the class name
    label = cls.label or cls.__name__

    return [
        BoolDef(
            "active",
            default=active,
            label=label,
            tooltip=cls.optional_tooltip,
        )
    ]

is_active(data)

Check if plugins is active for instance/context based on their data.

Parameters:

Name Type Description Default
data dict

Data from instance or context.

required
Source code in client/ayon_core/pipeline/publish/publish_plugins.py
352
353
354
355
356
357
358
359
360
361
362
363
364
365
def is_active(self, data):
    """Check if plugins is active for instance/context based on their data.

    Args:
        data(dict): Data from instance or context.
    """
    # Skip if is not optional and return True
    if not getattr(self, "optional", None):
        return True
    attr_values = self.get_attr_values_from_data(data)
    active = attr_values.get("active")
    if active is None:
        active = getattr(self, "active", True)
    return active

PublishError

Bases: Exception

Publishing crashed because of known error.

Message will be shown in UI for artist.

Parameters:

Name Type Description Default
message str

Message of error. Short explanation an issue.

required
title Optional[str]

Title showed in UI.

None
description Optional[str]

Detailed description of an error. It is possible to use Markdown syntax.

None
Source code in client/ayon_core/pipeline/publish/publish_plugins.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class PublishError(Exception):
    """Publishing crashed because of known error.

    Message will be shown in UI for artist.

    Args:
        message (str): Message of error. Short explanation an issue.
        title (Optional[str]): Title showed in UI.
        description (Optional[str]): Detailed description of an error.
            It is possible to use Markdown syntax.

    """
    def __init__(self, message, title=None, description=None, detail=None):
        self.message = message
        self.title = title
        self.description = description or message
        self.detail = detail
        super().__init__(message)

PublishValidationError

Bases: PublishError

Validation error happened during publishing.

This exception should be used when validation publishing failed.

Publishing does not stop during validation order if this exception is raised.

Has additional UI specific attributes that may be handy for artist.

Argument 'title' is used to group errors.

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
class PublishValidationError(PublishError):
    """Validation error happened during publishing.

    This exception should be used when validation publishing failed.

    Publishing does not stop during validation order if this
        exception is raised.

    Has additional UI specific attributes that may be handy for artist.

    Argument 'title' is used to group errors.

    """
    pass

PublishXmlValidationError

Bases: PublishValidationError

Raise an error from a dedicated xml file.

Can be useful to have one xml file with different possible messages that helps to avoid flood code with dedicated artist messages.

XML files should live relative to the plugin file location

'{plugin dir}/help/some_plugin.xml'.

Parameters:

Name Type Description Default
plugin Plugin

Plugin that raised an error. Is used to get path to xml file.

required
message str

Exception message, can be technical, is used for console output.

required
key Optional[str]

XML file can contain multiple error messages, key is used to get one of them. By default is used 'main'.

None
formatting_data Optional[dict[str, Any]

Error message can have variables to fill.

None
help_filename Optional[str]

Name of xml file with messages. By default, is used filename where plugin lives with .xml extension.

None
Source code in client/ayon_core/pipeline/publish/publish_plugins.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
class PublishXmlValidationError(PublishValidationError):
    """Raise an error from a dedicated xml file.

    Can be useful to have one xml file with different possible messages that
        helps to avoid flood code with dedicated artist messages.

    XML files should live relative to the plugin file location:
        '{plugin dir}/help/some_plugin.xml'.

    Args:
        plugin (pyblish.api.Plugin): Plugin that raised an error. Is used
            to get path to xml file.
        message (str): Exception message, can be technical, is used for
            console output.
        key (Optional[str]): XML file can contain multiple error messages, key
            is used to get one of them. By default is used 'main'.
        formatting_data (Optional[dict[str, Any]): Error message can have
            variables to fill.
        help_filename (Optional[str]): Name of xml file with messages. By
            default, is used filename where plugin lives with .xml extension.

    """
    def __init__(
        self,
        plugin: pyblish.api.Plugin,
        message: str,
        key: Optional[str] = None,
        formatting_data: Optional[dict[str, Any]] = None,
        help_filename: Optional[str] = None,
    ) -> None:
        if key is None:
            key = "main"

        if not formatting_data:
            formatting_data = {}
        result = load_help_content_from_plugin(plugin, help_filename)
        content_obj = result["errors"][key]
        description = content_obj.description.format_map(formatting_data)
        detail = content_obj.detail
        if detail:
            detail = detail.format_map(formatting_data)
        super().__init__(
            message,
            content_obj.title,
            description,
            detail
        )

RepairAction

Bases: Action

Repairs the action

To process the repairing this requires a static repair(instance) method is available on the plugin.

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
class RepairAction(pyblish.api.Action):
    """Repairs the action

    To process the repairing this requires a static `repair(instance)` method
    is available on the plugin.
    """

    label = "Repair"
    on = "failed"  # This action is only available on a failed plug-in
    icon = "wrench"  # Icon from Awesome Icon

    def process(self, context, plugin):
        if not hasattr(plugin, "repair"):
            raise RuntimeError("Plug-in does not have repair method.")

        # Get the errored instances
        self.log.debug("Finding failed instances..")
        errored_instances = get_errored_instances_from_context(context,
                                                               plugin=plugin)
        for instance in errored_instances:
            self.log.debug(
                "Attempting repair for instance: {} ...".format(instance)
            )
            plugin.repair(instance)

RepairContextAction

Bases: Action

Repairs the action

To process the repairing this requires a static repair(context) method is available on the plugin.

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
class RepairContextAction(pyblish.api.Action):
    """Repairs the action

    To process the repairing this requires a static `repair(context)` method
    is available on the plugin.
    """

    label = "Repair"
    on = "failed"  # This action is only available on a failed plug-in
    icon = "wrench"  # Icon from Awesome Icon

    def process(self, context, plugin):
        if not hasattr(plugin, "repair"):
            raise RuntimeError("Plug-in does not have repair method.")

        # Get the failed instances
        self.log.debug("Finding failed plug-ins..")
        failed_plugins = get_errored_plugins_from_context(context)

        # Apply pyblish.logic to get the instances for the plug-in
        if plugin in failed_plugins:
            self.log.debug("Attempting repair ...")
            plugin.repair(context)

refresh_instance_attributes(keys)

Helper for refreshing attribute definitions on key change.

This helper does handle only instance key changes and can update only instance attribute definitions.

This might be very inefficient if there are many instances that do change the keys frequently.

@refresh_instance_attributes("families")
class MyPlugin(pyblish.api.InstancePlugin, AYONPyblishPluginMixin):
    families = ["my_family"]

    @classmethod
    def get_attribute_defs(cls):
        return [TextDef("my_attr", label="My Attribute")]

Source code in client/ayon_core/pipeline/publish/publish_plugins.py
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
def refresh_instance_attributes(
    keys: str | set[str] | list[str],
) -> Callable:
    """Helper for refreshing attribute definitions on key change.

    This helper does handle only instance key changes and can update only
        instance attribute definitions.

    This might be very inefficient if there are many instances that do change
        the keys frequently.

    ```example
    @refresh_instance_attributes("families")
    class MyPlugin(pyblish.api.InstancePlugin, AYONPyblishPluginMixin):
        families = ["my_family"]

        @classmethod
        def get_attribute_defs(cls):
            return [TextDef("my_attr", label="My Attribute")]

    ```
    """
    if isinstance(keys, list):
        keys = set(keys)
    elif isinstance(keys, str):
        keys = {keys}
    elif not isinstance(keys, set):
        raise TypeError(
            "Expected str, set[str] or list[str] for 'keys'."
            f" Got {type(keys)}."
        )

    refresh_info = _RefreshInfo(keys=keys)

    def inner_func(
        plugin: type[AYONPyblishPluginMixin]
    ) -> type[AYONPyblishPluginMixin]:
        if not issubclass(plugin, AYONPyblishPluginMixin):
            raise TypeError(
                "Decorator 'refresh_attributes' can be used only on"
                " subclasses of AYONPyblishPluginMixin."
            )

        # Store refresh info on the plugin class to avoid unnecessary
        #   callbacks. Just use existing callback if already registered.
        _plugin_info: _RefreshInfo | None = getattr(
            plugin, "__refresh_instance_info__", None
        )
        if _plugin_info is not None:
            _plugin_info.keys.update(refresh_info.keys)
            return plugin

        setattr(plugin, "__refresh_instance_info__", refresh_info)

        plugin_name = plugin.__name__

        orig_register_create_context_callbacks = (
            plugin.register_create_context_callbacks
        )

        def on_values_changed(event):
            create_context: CreateContext = event["create_context"]
            for instance_change in event["changes"]:
                instance: CreatedInstance | None = instance_change["instance"]
                if instance is None:
                    continue

                value_changes = instance_change["changes"]
                if not any(
                    key in value_changes
                    for key in refresh_info.keys
                ):
                    continue

                attr_values = instance.publish_attributes.get(plugin_name)

                instance_attr_defs = plugin.get_attr_defs_for_instance(
                    create_context, instance
                )
                # Attribute values and attribute definitions are the same,
                #   no need to update.
                if not attr_values and not instance_attr_defs:
                    continue

                if (
                    attr_values is not None
                    and attr_values.attr_defs == instance_attr_defs
                ):
                    continue

                # Update attribute definitions for the instance
                instance.set_publish_plugin_attr_defs(
                    plugin_name, instance_attr_defs
                )

        def _custom_register_create_context_callbacks(
            cls, create_context
        ):
            orig_register_create_context_callbacks(create_context)
            create_context.add_value_changed_callback(on_values_changed)

        plugin.register_create_context_callbacks = classmethod(
            _custom_register_create_context_callbacks
        )
        return plugin

    return inner_func