22import contextlib
33import importlib
44import logging
5- from pyblish import api as pyblish
6- from avalon import api as avalon
75
6+ import pyblish .api
7+
8+ from .. import api
89from ..pipeline import AVALON_CONTAINER_ID
10+ from ..lib import find_submodule
911
1012
1113class CompLogHandler (logging .Handler ):
@@ -23,32 +25,30 @@ def ls():
2325 assets on disk, it lists assets already loaded in Fusion; once loaded
2426 they are called 'containers'
2527
28+ Yields:
29+ dict: container
30+
2631 """
2732
2833 comp = get_current_comp ()
2934 tools = comp .GetToolList (False , "Loader" ).values ()
35+
36+ has_metadata_collector = False
37+ config_host = find_submodule (api .registered_config (), "fusion" )
38+ if hasattr (config_host , "collect_container_metadata" ):
39+ has_metadata_collector = True
40+
3041 for tool in tools :
3142 container = parse_container (tool )
3243 if container :
33- # Collect custom data if attribute is present
34- config = find_host_config (avalon .registered_config ())
35- if hasattr (config , "collect_container_metadata" ):
36- metadata = config .collect_container_metadata (container )
44+
45+ if has_metadata_collector :
46+ metadata = config_host .collect_container_metadata (container )
3747 container .update (metadata )
3848
3949 yield container
4050
4151
42- def find_host_config (config ):
43- config_name = config .__name__
44- try :
45- config = importlib .import_module (config_name + ".fusion" )
46- except ImportError :
47- pass
48-
49- return config
50-
51-
5252def install (config ):
5353 """Install Fusion-specific functionality of avalon-core.
5454
@@ -60,7 +60,7 @@ def install(config):
6060 # TODO: Set project
6161 # TODO: Install Fusion menu (this is done with config .fu script actually)
6262
63- pyblish .register_host ("fusion" )
63+ pyblish .api . register_host ("fusion" )
6464
6565 # Remove all handlers associated with the root logger object, because
6666 # that one sometimes logs as "warnings" incorrectly.
@@ -75,10 +75,18 @@ def install(config):
7575 logger .addHandler (handler )
7676 logger .setLevel (logging .DEBUG )
7777
78- # Trigger install on the config's "fusion" package
79- config = find_host_config (config )
80- if hasattr (config , "install" ):
81- config .install ()
78+
79+ def uninstall (config ):
80+ """Uninstall Fusion-specific functionality of avalon-core.
81+
82+ This function is called automatically on calling `api.uninstall()`.
83+
84+ Args:
85+ config: configuration module
86+
87+ """
88+
89+ pyblish .api .deregister_host ("fusion" )
8290
8391
8492def imprint_container (tool ,
0 commit comments