From 51eb904d3658ee5719cfc73aca5c920c79ec236e Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Tue, 9 Jun 2015 10:18:29 +0100 Subject: [PATCH 1/8] Fixed #192 --- pyblish/plugin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyblish/plugin.py b/pyblish/plugin.py index eaff3646..851b380b 100644 --- a/pyblish/plugin.py +++ b/pyblish/plugin.py @@ -874,7 +874,9 @@ def discover(type=None, regex=None, paths=None): if not os.path.isfile(abspath): continue - mod_name, _ = os.path.splitext(fname) + mod_name, mod_ext = os.path.splitext(fname) + if not mod_ext == ".py": + continue try: # Discard traces of previously From 75eb0040321f4ed1c4a89b56bef1c0d12965842d Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Tue, 9 Jun 2015 10:41:18 +0100 Subject: [PATCH 2/8] Minimising output from CLI, stil available via the --verbose flag. --- pyblish/cli.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pyblish/cli.py b/pyblish/cli.py index 2c7baf96..500eb574 100644 --- a/pyblish/cli.py +++ b/pyblish/cli.py @@ -397,17 +397,16 @@ def publish(ctx, context.set_data("current_file", path) # Begin processing - click.echo() # newline - plugins = pyblish.api.discover(paths=ctx.obj["plugin_paths"]) pyblish.util.publish(context=context, plugins=plugins) _end = time.time() - click.echo() - click.echo("-" * 80) - click.echo(_format_time(_start, _end)) + if ctx.obj["verbose"]: + click.echo() + click.echo("-" * 80) + click.echo(_format_time(_start, _end)) @click.command() From 92c9c8dba390207d1d5166069b625f870fd273d4 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Tue, 9 Jun 2015 10:43:32 +0100 Subject: [PATCH 3/8] Lowering logging level for skipped plug-ins --- pyblish/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyblish/plugin.py b/pyblish/plugin.py index 851b380b..1d5e856f 100644 --- a/pyblish/plugin.py +++ b/pyblish/plugin.py @@ -890,7 +890,7 @@ def discover(type=None, regex=None, paths=None): module = pyblish.lib.import_module(mod_name) reload(module) except Exception as err: - log.warning("Skipped: \"%s\" (%s)", mod_name, err) + log.debug("Skipped: \"%s\" (%s)", mod_name, err) continue finally: From c2419d1bf8e36466b6cfc0bc50ef5fb41ed2815b Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Tue, 9 Jun 2015 10:49:17 +0100 Subject: [PATCH 4/8] Removing newline from CLI verbose output --- pyblish/cli.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyblish/cli.py b/pyblish/cli.py index 500eb574..74d07d12 100644 --- a/pyblish/cli.py +++ b/pyblish/cli.py @@ -284,7 +284,6 @@ def main(ctx, available_plugins = pyblish.api.discover(paths=plugin_paths) if plugins: - click.echo() # newline click.echo(_format_plugins(available_plugins)) if verbose: From 77911dd78b9a083b8f5ac8153ac7168457f9a48d Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Tue, 9 Jun 2015 15:00:52 +0100 Subject: [PATCH 5/8] Repairing CLI test --- pyblish/cli.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/pyblish/cli.py b/pyblish/cli.py index 74d07d12..0c07765e 100644 --- a/pyblish/cli.py +++ b/pyblish/cli.py @@ -20,7 +20,6 @@ """ import os -import sys import time import logging @@ -36,7 +35,12 @@ # Current Click context _ctx = None -log = logging.getLogger() +def _setup_log(root="pyblish"): + log = logging.getLogger(root) + log.setLevel(logging.INFO) + return log + +log = _setup_log() main_log = pyblish.lib.setup_log(level=logging.ERROR) # Constants @@ -68,11 +72,6 @@ {plugins}""" -def _setup_log(root="pyblish"): - log = logging.getLogger(root) - log.setLevel(logging.INFO) - return log - def _format_paths(paths): """Return paths at one new each""" @@ -245,10 +244,8 @@ def main(ctx, global _ctx _ctx = ctx - _setup_log() - level = LOG_LEVEL[logging_level] - logging.getLogger().setLevel(level) + log.setLevel(level) # Process top-level arguments if version: @@ -397,8 +394,14 @@ def publish(ctx, # Begin processing plugins = pyblish.api.discover(paths=ctx.obj["plugin_paths"]) - pyblish.util.publish(context=context, - plugins=plugins) + context = pyblish.util.publish(context=context, plugins=plugins) + + if any(result["error"] for result in context.data("results")): + click.echo("There were errors.") + + for result in context.data("results"): + if result["error"] is not None: + click.echo(result["error"]) _end = time.time() From 743c99914ba98f55ba06ce73a61bc8c1ba0d2522 Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Tue, 9 Jun 2015 15:36:54 +0100 Subject: [PATCH 6/8] Implementing #194 --- pyblish/plugin.py | 14 +++-------- tests/test_plugin.py | 60 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/pyblish/plugin.py b/pyblish/plugin.py index 1d5e856f..2ae4dcd9 100644 --- a/pyblish/plugin.py +++ b/pyblish/plugin.py @@ -606,36 +606,30 @@ def current_host(): >> # Running within Sidefx Houdini >> current_host() "houdini" + >> # Running from an unknown software + >> current_host() + "unknown" """ executable = os.path.basename(sys.executable).lower() if "python" in executable: - # Running from standalone Python return "python" if "maya" in executable: - # Maya is distinguished by looking at the currently running - # executable of the Python interpreter. It will be something - # like: "maya.exe" or "mayapy.exe"; without suffix for - # posix platforms. return "maya" if "nuke" in executable: - # Nuke typically includes a version number, e.g. Nuke8.0.exe - # and mixed-case letters. return "nuke" - # ..note:: The following are guesses, feel free to correct - if "modo" in executable: return "modo" if "houdini" in executable: return "houdini" - raise ValueError("Could not determine host from \"%s\"" % executable) + return "unknown" def register_plugin(plugin): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 31da519f..79615ff2 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1,10 +1,15 @@ import os +import sys import shutil import tempfile import contextlib import pyblish.plugin -from pyblish.vendor.nose.tools import * +from pyblish.vendor.nose.tools import ( + with_setup, + assert_true, + assert_equals, +) import lib @@ -118,3 +123,56 @@ class MyOtherSelector(pyblish.api.Selector): assert "MyOtherSelector" in plugins, plugins assert "MySelector" not in plugins, plugins + + +@with_setup(lib.setup_empty, lib.teardown) +def test_unsupported_host(): + """Publishing from within an unsupported host is ok""" + + class Always(pyblish.api.Plugin): + """This plug-in is always discoverable""" + + class OnlyInUnknown(pyblish.api.Plugin): + """This plug-in is only discoverable from unknown hosts""" + hosts = ["unknown"] + + class OnlyInMaya(pyblish.api.Plugin): + """This plug-in is only discoverable from maya""" + hosts = ["maya"] + + + pyblish.api.register_plugin(Always) + pyblish.api.register_plugin(OnlyInUnknown) + pyblish.api.register_plugin(OnlyInMaya) + + discovered = pyblish.api.discover() + + assert Always in discovered + assert OnlyInUnknown not in discovered # It's known to be python + assert OnlyInMaya not in discovered # Host is not maya + + def _current_host(): + return "maya" + + try: + old = sys.executable + sys.executable = "/root/some_executable" + + discovered = pyblish.api.discover() + assert OnlyInUnknown in discovered + assert OnlyInMaya not in discovered + + finally: + sys.executable = old + + try: + old = sys.executable + sys.executable = "/root/maya" + + discovered = pyblish.api.discover() + assert OnlyInUnknown not in discovered + assert OnlyInMaya in discovered + + finally: + sys.executable = old + From 2bf26e64894476c428902edb34966532f93beb1e Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Tue, 9 Jun 2015 16:21:09 +0100 Subject: [PATCH 7/8] Version bump --- CHANGES | 8 ++++++++ pyblish/version.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 0724ca6b..caddb9ec 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,14 @@ pyblish Changelog This contains all major version changes between pyblish releases. +Version 1.1.1 +------------- + +- Enhancement: Hosts limit, not allow (see #194) +- Enhancement: CLI outputs less, more concise information +- Enhancement: Lowering logging level for plug-ins skipped during discovery to DEBUG +- Bugfix: Discover ignores non-Python files (see #192) + Version 1.1.0 ------------- diff --git a/pyblish/version.py b/pyblish/version.py index 2205df60..e6504523 100644 --- a/pyblish/version.py +++ b/pyblish/version.py @@ -1,7 +1,7 @@ VERSION_MAJOR = 1 VERSION_MINOR = 1 -VERSION_PATCH = 0 +VERSION_PATCH = 1 version_info = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH) version = '%i.%i.%i' % version_info From b9895017c87d4d9c7f74d200c8d3a2f29c5e012a Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Tue, 9 Jun 2015 16:51:39 +0100 Subject: [PATCH 8/8] Implemented in #196 --- pyblish/plugin.py | 3 +++ tests/test_plugin.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/pyblish/plugin.py b/pyblish/plugin.py index ae739302..a22ee24f 100644 --- a/pyblish/plugin.py +++ b/pyblish/plugin.py @@ -866,6 +866,9 @@ def discover(type=None, regex=None, paths=None): continue for fname in os.listdir(path): + if fname.startswith("_"): + continue + abspath = os.path.join(path, fname) if not os.path.isfile(abspath): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 79615ff2..3b4bcf6f 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -176,3 +176,35 @@ def _current_host(): finally: sys.executable = old + +@with_setup(lib.setup_empty, lib.teardown) +def test_temporarily_disabled_plugins(): + """Plug-ins as files starting with an underscore are hidden""" + + discoverable = """ +import pyblish.api + +class Discoverable(pyblish.api.Plugin): + pass +""" + + notdiscoverable = """ +import pyblish.api + +class NotDiscoverable(pyblish.api.Plugin): + pass +""" + + with tempdir() as d: + pyblish.api.register_plugin_path(d) + + with open(os.path.join(d, "discoverable.py"), "w") as f: + f.write(discoverable) + + with open(os.path.join(d, "_undiscoverable.py"), "w") as f: + f.write(notdiscoverable) + + + plugins = [p.__name__ for p in pyblish.api.discover()] + assert "Discoverable" in plugins + assert "NotDiscoverable" not in plugins