Skip to content

host

HostBase

Bases: ABC

Base of host implementation class.

Host is pipeline implementation of DCC application. This class should help to identify what must/should/can be implemented for specific functionality.

Compared to 'avalon' concept: What was before considered as functions in host implementation folder. The host implementation should primarily care about adding ability of creation (mark products to be published) and optionally about referencing published representations as containers.

Host may need extend some functionality like working with workfiles or loading. Not all host implementations may allow that for those purposes can be logic extended with implementing functions for the purpose. There are prepared interfaces to be able identify what must be implemented to be able use that functionality. - current statement is that it is not required to inherit from interfaces but all of the methods are validated (only their existence!)

Installation of host before (avalon concept):

from ayon_core.pipeline import install_host
import ayon_core.hosts.maya.api as host

install_host(host)

Installation of host now:

from ayon_core.pipeline import install_host
from ayon_core.hosts.maya.api import MayaHost

host = MayaHost()
install_host(host)
Todo
  • move content of 'install_host' as method of this class
    • register host object
    • install global plugin paths
  • store registered plugin paths to this object
  • handle current context (project, asset, task)
    • this must be done in many separated steps
  • have it's object of host tools instead of using globals

This implementation will probably change over time when more functionality and responsibility will be added.

Source code in client/ayon_core/host/host.py
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 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
134
135
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
class HostBase(ABC):
    """Base of host implementation class.

    Host is pipeline implementation of DCC application. This class should help
    to identify what must/should/can be implemented for specific functionality.

    Compared to 'avalon' concept:
    What was before considered as functions in host implementation folder. The
    host implementation should primarily care about adding ability of creation
    (mark products to be published) and optionally about referencing published
    representations as containers.

    Host may need extend some functionality like working with workfiles
    or loading. Not all host implementations may allow that for those purposes
    can be logic extended with implementing functions for the purpose. There
    are prepared interfaces to be able identify what must be implemented to
    be able use that functionality.
    - current statement is that it is not required to inherit from interfaces
        but all of the methods are validated (only their existence!)

    # Installation of host before (avalon concept):
    ```python
    from ayon_core.pipeline import install_host
    import ayon_core.hosts.maya.api as host

    install_host(host)
    ```

    # Installation of host now:
    ```python
    from ayon_core.pipeline import install_host
    from ayon_core.hosts.maya.api import MayaHost

    host = MayaHost()
    install_host(host)
    ```

    Todo:
        - move content of 'install_host' as method of this class
            - register host object
            - install global plugin paths
        - store registered plugin paths to this object
        - handle current context (project, asset, task)
            - this must be done in many separated steps
        - have it's object of host tools instead of using globals

    This implementation will probably change over time when more
        functionality and responsibility will be added.
    """

    _log = None

    def __init__(self):
        """Initialization of host.

        Register DCC callbacks, host specific plugin paths, targets etc.
        (Part of what 'install' did in 'avalon' concept.)

        Note:
            At this moment global "installation" must happen before host
            installation. Because of this current limitation it is recommended
            to implement 'install' method which is triggered after global
            'install'.
        """

        pass

    def install(self):
        """Install host specific functionality.

        This is where should be added menu with tools, registered callbacks
        and other host integration initialization.

        It is called automatically when 'ayon_core.pipeline.install_host' is
        triggered.
        """

        pass

    @property
    def log(self):
        if self._log is None:
            self._log = logging.getLogger(self.__class__.__name__)
        return self._log

    @abstractproperty
    def name(self):
        """Host name."""

        pass

    def get_current_project_name(self):
        """
        Returns:
            Union[str, None]: Current project name.
        """

        return os.environ.get("AYON_PROJECT_NAME")

    def get_current_folder_path(self):
        """
        Returns:
            Union[str, None]: Current asset name.
        """

        return os.environ.get("AYON_FOLDER_PATH")

    def get_current_task_name(self):
        """
        Returns:
            Union[str, None]: Current task name.
        """

        return os.environ.get("AYON_TASK_NAME")

    def get_current_context(self):
        """Get current context information.

        This method should be used to get current context of host. Usage of
        this method can be crucial for host implementations in DCCs where
        can be opened multiple workfiles at one moment and change of context
        can't be caught properly.

        Returns:
            Dict[str, Union[str, None]]: Context with 3 keys 'project_name',
                'folder_path' and 'task_name'. All of them can be 'None'.
        """

        return {
            "project_name": self.get_current_project_name(),
            "folder_path": self.get_current_folder_path(),
            "task_name": self.get_current_task_name()
        }

    def get_context_title(self):
        """Context title shown for UI purposes.

        Should return current context title if possible.

        Note:
            This method is used only for UI purposes so it is possible to
                return some logical title for contextless cases.
            Is not meant for "Context menu" label.

        Returns:
            str: Context title.
            None: Default title is used based on UI implementation.
        """

        # Use current context to fill the context title
        current_context = self.get_current_context()
        project_name = current_context["project_name"]
        folder_path = current_context["folder_path"]
        task_name = current_context["task_name"]
        items = []
        if project_name:
            items.append(project_name)
            if folder_path:
                items.append(folder_path.lstrip("/"))
                if task_name:
                    items.append(task_name)
        if items:
            return "/".join(items)
        return None

    @contextlib.contextmanager
    def maintained_selection(self):
        """Some functionlity will happen but selection should stay same.

        This is DCC specific. Some may not allow to implement this ability
        that is reason why default implementation is empty context manager.

        Yields:
            None: Yield when is ready to restore selected at the end.
        """

        try:
            yield
        finally:
            pass

__init__()

Initialization of host.

Register DCC callbacks, host specific plugin paths, targets etc. (Part of what 'install' did in 'avalon' concept.)

Note

At this moment global "installation" must happen before host installation. Because of this current limitation it is recommended to implement 'install' method which is triggered after global 'install'.

Source code in client/ayon_core/host/host.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def __init__(self):
    """Initialization of host.

    Register DCC callbacks, host specific plugin paths, targets etc.
    (Part of what 'install' did in 'avalon' concept.)

    Note:
        At this moment global "installation" must happen before host
        installation. Because of this current limitation it is recommended
        to implement 'install' method which is triggered after global
        'install'.
    """

    pass

get_context_title()

Context title shown for UI purposes.

Should return current context title if possible.

Note

This method is used only for UI purposes so it is possible to return some logical title for contextless cases. Is not meant for "Context menu" label.

Returns:

Name Type Description
str

Context title.

None

Default title is used based on UI implementation.

Source code in client/ayon_core/host/host.py
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
def get_context_title(self):
    """Context title shown for UI purposes.

    Should return current context title if possible.

    Note:
        This method is used only for UI purposes so it is possible to
            return some logical title for contextless cases.
        Is not meant for "Context menu" label.

    Returns:
        str: Context title.
        None: Default title is used based on UI implementation.
    """

    # Use current context to fill the context title
    current_context = self.get_current_context()
    project_name = current_context["project_name"]
    folder_path = current_context["folder_path"]
    task_name = current_context["task_name"]
    items = []
    if project_name:
        items.append(project_name)
        if folder_path:
            items.append(folder_path.lstrip("/"))
            if task_name:
                items.append(task_name)
    if items:
        return "/".join(items)
    return None

get_current_context()

Get current context information.

This method should be used to get current context of host. Usage of this method can be crucial for host implementations in DCCs where can be opened multiple workfiles at one moment and change of context can't be caught properly.

Returns:

Type Description

Dict[str, Union[str, None]]: Context with 3 keys 'project_name', 'folder_path' and 'task_name'. All of them can be 'None'.

Source code in client/ayon_core/host/host.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
def get_current_context(self):
    """Get current context information.

    This method should be used to get current context of host. Usage of
    this method can be crucial for host implementations in DCCs where
    can be opened multiple workfiles at one moment and change of context
    can't be caught properly.

    Returns:
        Dict[str, Union[str, None]]: Context with 3 keys 'project_name',
            'folder_path' and 'task_name'. All of them can be 'None'.
    """

    return {
        "project_name": self.get_current_project_name(),
        "folder_path": self.get_current_folder_path(),
        "task_name": self.get_current_task_name()
    }

get_current_folder_path()

Returns:

Type Description

Union[str, None]: Current asset name.

Source code in client/ayon_core/host/host.py
109
110
111
112
113
114
115
def get_current_folder_path(self):
    """
    Returns:
        Union[str, None]: Current asset name.
    """

    return os.environ.get("AYON_FOLDER_PATH")

get_current_project_name()

Returns:

Type Description

Union[str, None]: Current project name.

Source code in client/ayon_core/host/host.py
101
102
103
104
105
106
107
def get_current_project_name(self):
    """
    Returns:
        Union[str, None]: Current project name.
    """

    return os.environ.get("AYON_PROJECT_NAME")

get_current_task_name()

Returns:

Type Description

Union[str, None]: Current task name.

Source code in client/ayon_core/host/host.py
117
118
119
120
121
122
123
def get_current_task_name(self):
    """
    Returns:
        Union[str, None]: Current task name.
    """

    return os.environ.get("AYON_TASK_NAME")

install()

Install host specific functionality.

This is where should be added menu with tools, registered callbacks and other host integration initialization.

It is called automatically when 'ayon_core.pipeline.install_host' is triggered.

Source code in client/ayon_core/host/host.py
77
78
79
80
81
82
83
84
85
86
87
def install(self):
    """Install host specific functionality.

    This is where should be added menu with tools, registered callbacks
    and other host integration initialization.

    It is called automatically when 'ayon_core.pipeline.install_host' is
    triggered.
    """

    pass

maintained_selection()

Some functionlity will happen but selection should stay same.

This is DCC specific. Some may not allow to implement this ability that is reason why default implementation is empty context manager.

Yields:

Name Type Description
None

Yield when is ready to restore selected at the end.

Source code in client/ayon_core/host/host.py
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
@contextlib.contextmanager
def maintained_selection(self):
    """Some functionlity will happen but selection should stay same.

    This is DCC specific. Some may not allow to implement this ability
    that is reason why default implementation is empty context manager.

    Yields:
        None: Yield when is ready to restore selected at the end.
    """

    try:
        yield
    finally:
        pass

name()

Host name.

Source code in client/ayon_core/host/host.py
95
96
97
98
99
@abstractproperty
def name(self):
    """Host name."""

    pass