From 50a30a253fb3ee82da9a2a74ca927fa6fb2c37a7 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 31 Dec 2019 04:52:48 +0100 Subject: [PATCH 01/11] Refactor find_host_config to lib.find_module_in_config - Add `uninstall()` function to `avalon.fusion` as that was missing. - Match Houdini and Fusion metadata collecting to Maya implementation, which had an optimization. --- avalon/fusion/pipeline.py | 50 +++++++++++++++++++++++++------------- avalon/houdini/pipeline.py | 40 ++++++++++++------------------ avalon/lib.py | 20 +++++++++++++++ avalon/maya/pipeline.py | 33 +++++++++---------------- avalon/nuke/pipeline.py | 26 ++++++-------------- 5 files changed, 88 insertions(+), 81 deletions(-) diff --git a/avalon/fusion/pipeline.py b/avalon/fusion/pipeline.py index 1dd9da084..d759b9e6c 100644 --- a/avalon/fusion/pipeline.py +++ b/avalon/fusion/pipeline.py @@ -6,6 +6,7 @@ from avalon import api as avalon from ..pipeline import AVALON_CONTAINER_ID +from ..lib import find_module_in_config class CompLogHandler(logging.Handler): @@ -23,32 +24,30 @@ def ls(): assets on disk, it lists assets already loaded in Fusion; once loaded they are called 'containers' + Yields: + dict: container + """ comp = get_current_comp() tools = comp.GetToolList(False, "Loader").values() + + has_metadata_collector = False + config_host = find_module_in_config(api.registered_config(), "fusion") + if hasattr(config_host, "collect_container_metadata"): + has_metadata_collector = True + for tool in tools: container = parse_container(tool) if container: - # Collect custom data if attribute is present - config = find_host_config(avalon.registered_config()) - if hasattr(config, "collect_container_metadata"): - metadata = config.collect_container_metadata(container) + + if has_metadata_collector: + metadata = config_host.collect_container_metadata(container) container.update(metadata) yield container -def find_host_config(config): - config_name = config.__name__ - try: - config = importlib.import_module(config_name + ".fusion") - except ImportError: - pass - - return config - - def install(config): """Install Fusion-specific functionality of avalon-core. @@ -76,9 +75,26 @@ def install(config): logger.setLevel(logging.DEBUG) # Trigger install on the config's "fusion" package - config = find_host_config(config) - if hasattr(config, "install"): - config.install() + config_host = find_module_in_config(config, "fusion") + if hasattr(config_host, "install"): + config_host.install() + + +def uninstall(config): + """Uninstall Fusion-specific functionality of avalon-core. + + This function is called automatically on calling `api.uninstall()`. + + Args: + config: configuration module + + """ + + config_host = find_module_in_config(config, "fusion") + if hasattr(config_host, "uninstall"): + config_host.uninstall() + + pyblish.api.deregister_host("fusion") def imprint_container(tool, diff --git a/avalon/houdini/pipeline.py b/avalon/houdini/pipeline.py index a94df88a4..d8c547a3f 100644 --- a/avalon/houdini/pipeline.py +++ b/avalon/houdini/pipeline.py @@ -10,7 +10,7 @@ # Local libraries from . import lib -from ..lib import logger +from ..lib import logger, find_module_in_config from avalon import api, schema from ..pipeline import AVALON_CONTAINER_ID @@ -39,10 +39,10 @@ def install(config): self._has_been_setup = True - config = find_host_config(config) - if hasattr(config, "install"): - config.install() - + config_host = find_module_in_config(config, "houdini") + if hasattr(config_host, "install"): + config_host.install() + def uninstall(config): """Uninstall Houdini-specific functionality of avalon-core. @@ -54,27 +54,15 @@ def uninstall(config): """ - config = find_host_config(config) - if hasattr(config, "uninstall"): - config.uninstall() + config_host = find_module_in_config(config, "houdini") + if hasattr(config_host, "uninstall"): + config_host.uninstall() pyblish.api.deregister_host("hython") pyblish.api.deregister_host("hpython") pyblish.api.deregister_host("houdini") -def find_host_config(config): - config_name = config.__name__ - try: - config = importlib.import_module(config_name + ".houdini") - except ImportError as exc: - if str(exc) != "No module name {}".format(config_name + ".houdini"): - raise - config = None - - return config - - def get_main_window(): """Acquire Houdini's main window""" if self._parent is None: @@ -236,13 +224,17 @@ def ls(): "pyblish.mindbender.container"): containers += lib.lsattr("id", identifier) - for container in sorted(containers): + has_metadata_collector = False + config_host = find_module_in_config(api.registered_config(), "houdini") + if hasattr(config_host, "collect_container_metadata"): + has_metadata_collector = True + + for container in sorted(container_names): data = parse_container(container) # Collect custom data if attribute is present - config = find_host_config(api.registered_config()) - if hasattr(config, "collect_container_metadata"): - metadata = config.collect_container_metadata(container) + if has_metadata_collector: + metadata = config_host.collect_container_metadata(container) data.update(metadata) yield data diff --git a/avalon/lib.py b/avalon/lib.py index 11c9dff4a..3bbd2d2e1 100644 --- a/avalon/lib.py +++ b/avalon/lib.py @@ -281,3 +281,23 @@ def modules_from_path(path): modules.append(module) return modules + + +def find_module_in_config(config, module): + """Find and return submodule of the config. + + Args: + config (types.ModuleType): The config to search in. + module (str): The config's submodule to search. + + Returns: + types.ModuleType or None: The module, if found. + + """ + config_name = config.__name__ + module_name = "%s.%s" % (config_name, module) + try: + return importlib.import_module(module_name) + except ImportError as exc: + if str(exc) != "No module name {}".format(module_name): + log.warning("Config has no '%s' module." % module_name) diff --git a/avalon/maya/pipeline.py b/avalon/maya/pipeline.py index 55c4bb490..16739aa6c 100644 --- a/avalon/maya/pipeline.py +++ b/avalon/maya/pipeline.py @@ -10,7 +10,7 @@ from pyblish import api as pyblish from . import lib, compat -from ..lib import logger +from ..lib import logger, find_module_in_config from .. import api, schema from ..tools import workfiles from ..vendor.Qt import QtCore, QtWidgets @@ -57,10 +57,10 @@ def install(config): pyblish.register_host("mayabatch") pyblish.register_host("mayapy") pyblish.register_host("maya") - - config = find_host_config(config) - if hasattr(config, "install"): - config.install() + + config_host = find_module_in_config(config, "maya") + if hasattr(config_host, "install"): + config_host.install() def _set_project(): @@ -84,17 +84,6 @@ def _set_project(): cmds.workspace(workdir, openWorkspace=True) -def find_host_config(config): - try: - config = importlib.import_module(config.__name__ + ".maya") - except ImportError as exc: - if str(exc) != "No module name {}".format(config.__name__ + ".maya"): - raise - config = None - - return config - - def get_main_window(): """Acquire Maya's main window""" if self._parent is None: @@ -111,9 +100,9 @@ def uninstall(config): This function is called automatically on calling `api.uninstall()`. """ - config = find_host_config(config) - if hasattr(config, "uninstall"): - config.uninstall() + config_host = find_module_in_config(config, "maya") + if hasattr(config_host, "uninstall"): + config_host.uninstall() _uninstall_menu() @@ -517,8 +506,8 @@ def ls(): container_names = _ls() has_metadata_collector = False - config = find_host_config(api.registered_config()) - if hasattr(config, "collect_container_metadata"): + config_host = find_module_in_config(api.registered_config(), "maya") + if hasattr(config_host, "collect_container_metadata"): has_metadata_collector = True for container in sorted(container_names): @@ -526,7 +515,7 @@ def ls(): # Collect custom data if attribute is present if has_metadata_collector: - metadata = config.collect_container_metadata(container) + metadata = config_host.collect_container_metadata(container) data.update(metadata) yield data diff --git a/avalon/nuke/pipeline.py b/avalon/nuke/pipeline.py index 31ac2295e..1ccc70f7b 100644 --- a/avalon/nuke/pipeline.py +++ b/avalon/nuke/pipeline.py @@ -10,6 +10,7 @@ from . import lib, command from .. import api +from ..lib import find_module_in_config from ..vendor.Qt import QtWidgets from ..pipeline import AVALON_CONTAINER_ID @@ -227,26 +228,15 @@ def install(config): _register_events() pyblish.register_host("nuke") + # Trigger install on the config's "nuke" package - config = find_host_config(config) - - if hasattr(config, "install"): - config.install() + config_host = find_module_in_config(config, "nuke") + if hasattr(config_host, "install"): + config_host.install() log.info("config.nuke installed") -def find_host_config(config): - try: - config = importlib.import_module(config.__name__ + ".nuke") - except ImportError as exc: - if str(exc) != "No module name {}".format(config.__name__ + ".nuke"): - raise - config = None - - return config - - def get_main_window(): """Acquire Nuke's main window""" if self._parent is None: @@ -270,9 +260,9 @@ def uninstall(config): modifying the menu or registered families. """ - config = find_host_config(config) - if hasattr(config, "uninstall"): - config.uninstall() + config_host = find_module_in_config(config, "nuke") + if hasattr(config_host, "uninstall"): + config_host.uninstall() _uninstall_menu() From 249952bfbd7390c2c0f3def52aac571241d2c452 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 31 Dec 2019 05:06:00 +0100 Subject: [PATCH 02/11] Fix log variable name --- avalon/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avalon/lib.py b/avalon/lib.py index 3bbd2d2e1..dfb24118d 100644 --- a/avalon/lib.py +++ b/avalon/lib.py @@ -300,4 +300,4 @@ def find_module_in_config(config, module): return importlib.import_module(module_name) except ImportError as exc: if str(exc) != "No module name {}".format(module_name): - log.warning("Config has no '%s' module." % module_name) + log_.warning("Config has no '%s' module." % module_name) From 3f1aa64bc8e53cde982f09f67a213a13c2e03408 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 31 Dec 2019 10:00:56 +0100 Subject: [PATCH 03/11] Move config.host.install/uninstall call to global api install/uninstall --- avalon/fusion/pipeline.py | 9 --------- avalon/houdini/pipeline.py | 8 -------- avalon/maya/pipeline.py | 7 ------- avalon/nuke/pipeline.py | 9 --------- avalon/pipeline.py | 15 +++++++++++++-- 5 files changed, 13 insertions(+), 35 deletions(-) diff --git a/avalon/fusion/pipeline.py b/avalon/fusion/pipeline.py index d759b9e6c..9e6570100 100644 --- a/avalon/fusion/pipeline.py +++ b/avalon/fusion/pipeline.py @@ -73,11 +73,6 @@ def install(config): handler.setFormatter(formatter) logger.addHandler(handler) logger.setLevel(logging.DEBUG) - - # Trigger install on the config's "fusion" package - config_host = find_module_in_config(config, "fusion") - if hasattr(config_host, "install"): - config_host.install() def uninstall(config): @@ -90,10 +85,6 @@ def uninstall(config): """ - config_host = find_module_in_config(config, "fusion") - if hasattr(config_host, "uninstall"): - config_host.uninstall() - pyblish.api.deregister_host("fusion") diff --git a/avalon/houdini/pipeline.py b/avalon/houdini/pipeline.py index d8c547a3f..0653b45ed 100644 --- a/avalon/houdini/pipeline.py +++ b/avalon/houdini/pipeline.py @@ -38,10 +38,6 @@ def install(config): pyblish.api.register_host("hpython") self._has_been_setup = True - - config_host = find_module_in_config(config, "houdini") - if hasattr(config_host, "install"): - config_host.install() def uninstall(config): @@ -54,10 +50,6 @@ def uninstall(config): """ - config_host = find_module_in_config(config, "houdini") - if hasattr(config_host, "uninstall"): - config_host.uninstall() - pyblish.api.deregister_host("hython") pyblish.api.deregister_host("hpython") pyblish.api.deregister_host("houdini") diff --git a/avalon/maya/pipeline.py b/avalon/maya/pipeline.py index 16739aa6c..111c1295d 100644 --- a/avalon/maya/pipeline.py +++ b/avalon/maya/pipeline.py @@ -57,10 +57,6 @@ def install(config): pyblish.register_host("mayabatch") pyblish.register_host("mayapy") pyblish.register_host("maya") - - config_host = find_module_in_config(config, "maya") - if hasattr(config_host, "install"): - config_host.install() def _set_project(): @@ -100,9 +96,6 @@ def uninstall(config): This function is called automatically on calling `api.uninstall()`. """ - config_host = find_module_in_config(config, "maya") - if hasattr(config_host, "uninstall"): - config_host.uninstall() _uninstall_menu() diff --git a/avalon/nuke/pipeline.py b/avalon/nuke/pipeline.py index 1ccc70f7b..6cadb1385 100644 --- a/avalon/nuke/pipeline.py +++ b/avalon/nuke/pipeline.py @@ -10,7 +10,6 @@ from . import lib, command from .. import api -from ..lib import find_module_in_config from ..vendor.Qt import QtWidgets from ..pipeline import AVALON_CONTAINER_ID @@ -228,11 +227,6 @@ def install(config): _register_events() pyblish.register_host("nuke") - - # Trigger install on the config's "nuke" package - config_host = find_module_in_config(config, "nuke") - if hasattr(config_host, "install"): - config_host.install() log.info("config.nuke installed") @@ -260,9 +254,6 @@ def uninstall(config): modifying the menu or registered families. """ - config_host = find_module_in_config(config, "nuke") - if hasattr(config_host, "uninstall"): - config_host.uninstall() _uninstall_menu() diff --git a/avalon/pipeline.py b/avalon/pipeline.py index a310908ec..12a5fbcce 100644 --- a/avalon/pipeline.py +++ b/avalon/pipeline.py @@ -77,6 +77,11 @@ def install(host): # Optional host install function if hasattr(host, "install"): host.install(config) + + # Optional config.host.install() + config_host = lib.find_module_in_config(config, host.__name__) + if hasattr(config_host, "install"): + config_host.install() register_host(host) register_config(config) @@ -104,9 +109,15 @@ def find_config(): def uninstall(): """Undo all of what `install()` did""" config = registered_config() - + host = registered_host() + + # Optional config.host.uninstall() + config_host = lib.find_module_in_config(config, host.__name__) + if hasattr(config_host, "uninstall"): + config_host.uninstall() + try: - registered_host().uninstall(config) + host.uninstall(config) except AttributeError: pass From fcbb79f1ac36cbaf7fc90437dc3b8ead782f0d10 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 31 Dec 2019 10:35:33 +0100 Subject: [PATCH 04/11] Correctly get only host name from host module --- avalon/pipeline.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/avalon/pipeline.py b/avalon/pipeline.py index 12a5fbcce..5d0946b4f 100644 --- a/avalon/pipeline.py +++ b/avalon/pipeline.py @@ -79,7 +79,8 @@ def install(host): host.install(config) # Optional config.host.install() - config_host = lib.find_module_in_config(config, host.__name__) + host_name = host.__name__.rsplit(".", 1)[-1] + config_host = lib.find_module_in_config(config, host_name) if hasattr(config_host, "install"): config_host.install() @@ -112,7 +113,8 @@ def uninstall(): host = registered_host() # Optional config.host.uninstall() - config_host = lib.find_module_in_config(config, host.__name__) + host_name = host.__name__.rsplit(".", 1)[-1] + config_host = lib.find_module_in_config(config, host_name) if hasattr(config_host, "uninstall"): config_host.uninstall() From f0e4429f3cb8e1dbeeadf726e670f39f387d5358 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 2 Jan 2020 11:23:49 +0100 Subject: [PATCH 05/11] Fix imports, clean up imports and refactor to find_submodule --- avalon/fusion/pipeline.py | 4 ++-- avalon/houdini/pipeline.py | 10 ++++------ avalon/lib.py | 29 +++++++++++++++-------------- avalon/maya/pipeline.py | 12 +++++------- avalon/nuke/pipeline.py | 2 -- avalon/pipeline.py | 10 +++++----- 6 files changed, 31 insertions(+), 36 deletions(-) diff --git a/avalon/fusion/pipeline.py b/avalon/fusion/pipeline.py index 9e6570100..db17faa6e 100644 --- a/avalon/fusion/pipeline.py +++ b/avalon/fusion/pipeline.py @@ -6,7 +6,7 @@ from avalon import api as avalon from ..pipeline import AVALON_CONTAINER_ID -from ..lib import find_module_in_config +from ..lib import find_submodule class CompLogHandler(logging.Handler): @@ -33,7 +33,7 @@ def ls(): tools = comp.GetToolList(False, "Loader").values() has_metadata_collector = False - config_host = find_module_in_config(api.registered_config(), "fusion") + config_host = find_submodule(api.registered_config(), "fusion") if hasattr(config_host, "collect_container_metadata"): has_metadata_collector = True diff --git a/avalon/houdini/pipeline.py b/avalon/houdini/pipeline.py index 0653b45ed..b60922685 100644 --- a/avalon/houdini/pipeline.py +++ b/avalon/houdini/pipeline.py @@ -10,8 +10,8 @@ # Local libraries from . import lib -from ..lib import logger, find_module_in_config -from avalon import api, schema +from ..lib import logger, find_submodule +from avalon import api from ..pipeline import AVALON_CONTAINER_ID @@ -38,7 +38,7 @@ def install(config): pyblish.api.register_host("hpython") self._has_been_setup = True - + def uninstall(config): """Uninstall Houdini-specific functionality of avalon-core. @@ -69,8 +69,6 @@ def reload_pipeline(*args): """ - import importlib - api.uninstall() for module in ("avalon.io", @@ -217,7 +215,7 @@ def ls(): containers += lib.lsattr("id", identifier) has_metadata_collector = False - config_host = find_module_in_config(api.registered_config(), "houdini") + config_host = find_submodule(api.registered_config(), "houdini") if hasattr(config_host, "collect_container_metadata"): has_metadata_collector = True diff --git a/avalon/lib.py b/avalon/lib.py index dfb24118d..8bd26727f 100644 --- a/avalon/lib.py +++ b/avalon/lib.py @@ -5,6 +5,7 @@ import json import logging import datetime +import importlib import subprocess import types @@ -281,23 +282,23 @@ def modules_from_path(path): modules.append(module) return modules - - -def find_module_in_config(config, module): - """Find and return submodule of the config. - + + +def find_submodule(module, submodule): + """Find and return submodule of the module. + Args: - config (types.ModuleType): The config to search in. - module (str): The config's submodule to search. - + module (types.ModuleType): The module to search in. + submodule (str): The submodule name to find. + Returns: types.ModuleType or None: The module, if found. - + """ - config_name = config.__name__ - module_name = "%s.%s" % (config_name, module) + name = "%s.%s" % (module.__name__, submodule) try: - return importlib.import_module(module_name) + return importlib.import_module(name) except ImportError as exc: - if str(exc) != "No module name {}".format(module_name): - log_.warning("Config has no '%s' module." % module_name) + if str(exc) != "No module name {}".format(name): + log_.warning("Could not find '%s' in module: %s" % (submodule, + module)) diff --git a/avalon/maya/pipeline.py b/avalon/maya/pipeline.py index 111c1295d..c04baf862 100644 --- a/avalon/maya/pipeline.py +++ b/avalon/maya/pipeline.py @@ -10,8 +10,8 @@ from pyblish import api as pyblish from . import lib, compat -from ..lib import logger, find_module_in_config -from .. import api, schema +from ..lib import logger, find_submodule +from .. import api from ..tools import workfiles from ..vendor.Qt import QtCore, QtWidgets @@ -212,8 +212,6 @@ def reload_pipeline(*args): """ - import importlib - api.uninstall() for module in ("avalon.io", @@ -254,13 +252,13 @@ def reload_pipeline(*args): def _uninstall_menu(): - + # In Maya 2020+ don't use the QApplication.instance() # during startup (userSetup.py) as it will return a # QtCore.QCoreApplication instance which does not have # the allWidgets method. As such, we call the staticmethod. all_widgets = QtWidgets.QApplication.allWidgets() - + widgets = dict((w.objectName(), w) for w in all_widgets) menu = widgets.get(self._menu) @@ -499,7 +497,7 @@ def ls(): container_names = _ls() has_metadata_collector = False - config_host = find_module_in_config(api.registered_config(), "maya") + config_host = find_submodule(api.registered_config(), "maya") if hasattr(config_host, "collect_container_metadata"): has_metadata_collector = True diff --git a/avalon/nuke/pipeline.py b/avalon/nuke/pipeline.py index 6cadb1385..2b7738a02 100644 --- a/avalon/nuke/pipeline.py +++ b/avalon/nuke/pipeline.py @@ -28,8 +28,6 @@ def reload_pipeline(): """ - import importlib - api.uninstall() _uninstall_menu() diff --git a/avalon/pipeline.py b/avalon/pipeline.py index 5d0946b4f..51cbb35b0 100644 --- a/avalon/pipeline.py +++ b/avalon/pipeline.py @@ -77,10 +77,10 @@ def install(host): # Optional host install function if hasattr(host, "install"): host.install(config) - + # Optional config.host.install() host_name = host.__name__.rsplit(".", 1)[-1] - config_host = lib.find_module_in_config(config, host_name) + config_host = lib.find_submodule(config, host_name) if hasattr(config_host, "install"): config_host.install() @@ -111,13 +111,13 @@ def uninstall(): """Undo all of what `install()` did""" config = registered_config() host = registered_host() - + # Optional config.host.uninstall() host_name = host.__name__.rsplit(".", 1)[-1] - config_host = lib.find_module_in_config(config, host_name) + config_host = lib.find_submodule(config, host_name) if hasattr(config_host, "uninstall"): config_host.uninstall() - + try: host.uninstall(config) except AttributeError: From 0c1e443200652ed95cdbbe55b7ab539da326df8d Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 2 Jan 2020 11:30:02 +0100 Subject: [PATCH 06/11] Fix invalidly refactored variable name --- avalon/houdini/pipeline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avalon/houdini/pipeline.py b/avalon/houdini/pipeline.py index b60922685..ce4888e41 100644 --- a/avalon/houdini/pipeline.py +++ b/avalon/houdini/pipeline.py @@ -219,7 +219,7 @@ def ls(): if hasattr(config_host, "collect_container_metadata"): has_metadata_collector = True - for container in sorted(container_names): + for container in sorted(containers): data = parse_container(container) # Collect custom data if attribute is present From f03d0f6e06b0c540e59f9d59f0798d7287efcbce Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 2 Jan 2020 11:30:20 +0100 Subject: [PATCH 07/11] Fix imports and shush the hound --- avalon/fusion/pipeline.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/avalon/fusion/pipeline.py b/avalon/fusion/pipeline.py index db17faa6e..c8c3c4ebe 100644 --- a/avalon/fusion/pipeline.py +++ b/avalon/fusion/pipeline.py @@ -2,9 +2,10 @@ import contextlib import importlib import logging -from pyblish import api as pyblish -from avalon import api as avalon +import pyblish.api + +from .. import api from ..pipeline import AVALON_CONTAINER_ID from ..lib import find_submodule @@ -31,16 +32,16 @@ def ls(): comp = get_current_comp() tools = comp.GetToolList(False, "Loader").values() - + has_metadata_collector = False config_host = find_submodule(api.registered_config(), "fusion") if hasattr(config_host, "collect_container_metadata"): has_metadata_collector = True - + for tool in tools: container = parse_container(tool) if container: - + if has_metadata_collector: metadata = config_host.collect_container_metadata(container) container.update(metadata) @@ -59,7 +60,7 @@ def install(config): # TODO: Set project # TODO: Install Fusion menu (this is done with config .fu script actually) - pyblish.register_host("fusion") + pyblish.api.register_host("fusion") # Remove all handlers associated with the root logger object, because # that one sometimes logs as "warnings" incorrectly. @@ -73,7 +74,7 @@ def install(config): handler.setFormatter(formatter) logger.addHandler(handler) logger.setLevel(logging.DEBUG) - + def uninstall(config): """Uninstall Fusion-specific functionality of avalon-core. From 986157351ac5bd6ea8dd5d22cb1ec4ac892952c3 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 2 Jan 2020 12:29:34 +0100 Subject: [PATCH 08/11] Refactor to relative import --- avalon/houdini/pipeline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avalon/houdini/pipeline.py b/avalon/houdini/pipeline.py index ce4888e41..f2657f978 100644 --- a/avalon/houdini/pipeline.py +++ b/avalon/houdini/pipeline.py @@ -11,7 +11,7 @@ # Local libraries from . import lib from ..lib import logger, find_submodule -from avalon import api +from .. import api from ..pipeline import AVALON_CONTAINER_ID From 6d894d13133e7726d9e76bf64fec1c11985732a9 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 2 Jan 2020 12:30:53 +0100 Subject: [PATCH 09/11] Refactor string formatting to logger string formatting --- avalon/lib.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/avalon/lib.py b/avalon/lib.py index 8bd26727f..b77c3d5fc 100644 --- a/avalon/lib.py +++ b/avalon/lib.py @@ -300,5 +300,6 @@ def find_submodule(module, submodule): return importlib.import_module(name) except ImportError as exc: if str(exc) != "No module name {}".format(name): - log_.warning("Could not find '%s' in module: %s" % (submodule, - module)) + log_.warning("Could not find '%s' in module: %s", + submodule, + module) From 5aea369f9d3818d89c81297a1e32764d34180c5f Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 2 Jan 2020 12:34:15 +0100 Subject: [PATCH 10/11] Use new style string formatting for consistency --- avalon/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avalon/lib.py b/avalon/lib.py index b77c3d5fc..b19b2844c 100644 --- a/avalon/lib.py +++ b/avalon/lib.py @@ -295,7 +295,7 @@ def find_submodule(module, submodule): types.ModuleType or None: The module, if found. """ - name = "%s.%s" % (module.__name__, submodule) + name = "{0}.{1}".format(module.__name__, submodule) try: return importlib.import_module(name) except ImportError as exc: From 241e05d83e53ad128dbb3038dab493122cb3fea9 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 2 Jan 2020 12:42:10 +0100 Subject: [PATCH 11/11] Fix printed exception and fix typo in docstring + clarify docstring --- avalon/lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avalon/lib.py b/avalon/lib.py index b19b2844c..139fce223 100644 --- a/avalon/lib.py +++ b/avalon/lib.py @@ -237,7 +237,7 @@ def modules_from_path(path): """Get python scripts as modules from a path. Arguments: - path (str): Path to python scrips. + path (str): Path to folder containing python scripts. Returns: List of modules. @@ -276,7 +276,7 @@ def modules_from_path(path): sys.modules[mod_name] = module except Exception as err: - print("Skipped: \"%s\" (%s)", mod_name, err) + print("Skipped: \"{0}\" ({1})".format(mod_name, err)) continue modules.append(module)