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/cli.py b/pyblish/cli.py index 2c7baf96..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: @@ -284,7 +281,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: @@ -397,17 +393,22 @@ 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) + 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() - 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() diff --git a/pyblish/plugin.py b/pyblish/plugin.py index 574fdfa4..a22ee24f 100644 --- a/pyblish/plugin.py +++ b/pyblish/plugin.py @@ -606,39 +606,33 @@ 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 "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" - # incase you are not using the build in python version check and see if - # hou is imported. - if 'hou' in sys.modules or 'houdini' in executable: + if "houdini" in executable or "hou" in sys.modules: return 'houdini' - # if all else fails. + if "houdini" in executable: + return "houdini" + if "python" in executable: - # Running from standalone Python return "python" - raise ValueError("Could not determine host from \"%s\"" % executable) + return "unknown" def register_plugin(plugin): @@ -872,12 +866,17 @@ 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): 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 @@ -891,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: 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 diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 31da519f..3b4bcf6f 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,88 @@ 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 + + +@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