From dca53a183c5d70fdaa21048442c5dbebba46612d Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Fri, 6 Sep 2019 15:41:00 +0200 Subject: [PATCH] added support for presets on global plugins --- pype/lib.py | 22 +++++++++++++++++----- pype/tests/test_pyblish_filter.py | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pype/lib.py b/pype/lib.py index c097ad1f10..acd8756aa7 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -5,6 +5,7 @@ import importlib import itertools import contextlib import subprocess +import inspect from .vendor import pather from .vendor.pather.error import ParseError @@ -467,9 +468,7 @@ def filter_pyblish_plugins(plugins): host = api.current_host() - presets = config.get_presets().get('plugins', {}).get(host, {}).get( - "publish", {} - ) + presets = config.get_presets().get('plugins', {}) # iterate over plugins for plugin in plugins[:]: @@ -477,10 +476,23 @@ def filter_pyblish_plugins(plugins): if not presets: continue + file = os.path.normpath(inspect.getfile(plugin.__class__)) + file = os.path.normpath(file) + + # host determined from path + host_from_file = file.split(os.path.sep)[-3:-2][0] + plugin_kind = file.split(os.path.sep)[-2:-1][0] + + print(host_from_file) + print(plugin_kind) + try: - config_data = presets[plugin.__name__] # noqa: E501 + config_data = presets[host]["publish"][plugin.__name__] except KeyError: - continue + try: + config_data = presets[host_from_file][plugin_kind][plugin.__name__] # noqa: E501 + except KeyError: + continue for option, value in config_data.items(): if option == "enabled" and value is False: diff --git a/pype/tests/test_pyblish_filter.py b/pype/tests/test_pyblish_filter.py index 8d747e63df..cf3d5d6015 100644 --- a/pype/tests/test_pyblish_filter.py +++ b/pype/tests/test_pyblish_filter.py @@ -18,7 +18,7 @@ def test_pyblish_plugin_filter_modifier(printer, monkeypatch): assert len(plugins) == 0 paths = pyblish.api.registered_paths() printer("Test if we have no registered plugin paths") - print(paths) + assert len(paths) == 0 class MyTestPlugin(pyblish.api.InstancePlugin): my_test_property = 1