Skip to content

Commit

Permalink
Merge pull request #195 from mottosso/master
Browse files Browse the repository at this point in the history
Maintenance update
  • Loading branch information
mottosso committed Jun 9, 2015
2 parents d45e4a3 + b989501 commit 1f10773
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 36 deletions.
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------

Expand Down
37 changes: 19 additions & 18 deletions pyblish/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""

import os
import sys
import time
import logging

Expand All @@ -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
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
31 changes: 15 additions & 16 deletions pyblish/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyblish/version.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
92 changes: 91 additions & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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

0 comments on commit 1f10773

Please sign in to comment.