Skip to content

Commit

Permalink
Merge pull request #279 from mottosso/master
Browse files Browse the repository at this point in the history
register_gui()
  • Loading branch information
mottosso authored Jun 24, 2016
2 parents 55cdd4b + 3cd8cd3 commit f54ab15
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 138 deletions.
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### Contributing to this project

To contribute, fork this project and submit a pull-request.

Your code will be reviewed and merged once it:

1. Does something useful
1. Is up to par with surrounding code

Development for this project takes place in individual forks. The parent project ever only contains a single branch, a branch containing the latest working version of the project.

Bugreports must include:

1. Description
2. Expected results
3. Short reproducible

Feature requests must include:

1. Goal (what the feature aims to solve)
2. Motivation (why *you* think this is necessary)
3. Suggested implementation (psuedocode)

Questions may also be submitted as issues.
57 changes: 51 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,63 @@
[![Coverage Status][cover-image]][cover-link]
[![PyPI version][pypi-image]][pypi-link]
[![Code Health][landscape-image]][landscape-repo]
[![Gitter][gitter-image]][chat]
[![Gitter][gitter-image]](https://gitter.im/pyblish/pyblish?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![image](https://cloud.githubusercontent.com/assets/2152766/12704326/b6ff015c-c850-11e5-91be-68d824526f13.png)](https://www.youtube.com/watch?v=j5uUTW702-U)

Test-driven content creation for collaborative, creative projects.

- [Wiki][wiki]
- [Learn by Example][example]
- [Wiki](../../wiki)
- [Learn by Example](http://learn.pyblish.com)

[example]: http://forums.pyblish.com/t/learning-pyblish-by-example/108
[wiki]: https://github.com/pyblish/pyblish-base/wiki
[chat]: https://gitter.im/pyblish/pyblish?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
<br>
<br>
<br>

### Introduction

Pyblish is a modular framework, consisting of many sub-projects. This project contains the primary API upon which all other projects build.

You may use this project as-is, or in conjunction with surrounding projects - such as [pyblish-maya][] for integration with Autodesk Maya, [pyblish-qml][] for a visual front-end and [pyblish-magenta][] for a starting point your publishing pipeline.

[pyblish-maya]: https://github.com/pyblish/pyblish-maya
[pyblish-qml]: https://github.com/pyblish/pyblish-qml
[pyblish-magenta]: https://github.com/pyblish/pyblish-magenta

- [Browse All Projects](https://github.com/pyblish)

<br>
<br>
<br>

### Installation

pyblish-base is avaialble on PyPI.

```bash
$ pip install pyblish-base
```

Like all other Pyblish projects, it may also be clone as-is via Git and added to your PYTHONPATH.

```bash
$ git clone https://github.com/pyblish/pyblish-base.git
$ # Windows
$ set PYTHONPATH=%cd%\pyblish-base
$ # Unix
$ export PYTHONPATH=$(pwd)/pyblish-base
```

<br>
<br>
<br>

### Usage

Refer to the [getting started guide](http://learn.pyblish.com) for a gentle introduction to the framework and [the forums](http://forums.pyblish.com) for tips and tricks.

- [Learn Pyblish By Example](http://learn.pyblish.com)
- [Forums](http://forums.pyblish.com)

[travis-image]: https://travis-ci.org/pyblish/pyblish-base.svg?branch=master
[travis-link]: https://travis-ci.org/pyblish/pyblish-base
Expand Down
2 changes: 2 additions & 0 deletions pyblish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
_registered_test = dict()
_registered_hosts = list()
_registered_targets = list()
_registered_gui = list()


__all__ = [
Expand All @@ -29,4 +30,5 @@
"_registered_test",
"_registered_hosts",
"_registered_targets",
"_registered_gui",
]
15 changes: 15 additions & 0 deletions pyblish/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
register_test,
deregister_test,
registered_test,

register_gui,
registered_guis,
deregister_gui,

default_test as __default_test,
)

Expand Down Expand Up @@ -205,11 +210,21 @@ def __init__():
"deregister_test",
"registered_test",

"register_gui",
"registered_guis",
"deregister_gui",

"plugins_by_family",
"plugins_by_host",
"plugins_by_instance",
"instances_by_plugin",

"current_target",
"register_target",
"registered_targets",
"deregister_target",
"deregister_all_targets",

"sort_plugins",
"format_filename",
"current_host",
Expand Down
129 changes: 126 additions & 3 deletions pyblish/compat.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Compatibility module"""

import os
import re
import inspect
import warnings
from . import plugin, lib
from .vendor import six
from . import plugin, lib, logic

# Aliases
Selector = plugin.Collector
Expand Down Expand Up @@ -129,6 +128,7 @@ def add(self, other):
plugin.Context.create_asset = create_asset
plugin.Context.add = add


@lib.deprecated
def format_filename(filename):
return filename
Expand All @@ -141,3 +141,126 @@ def format_filename2(filename):

lib.format_filename = format_filename
lib.format_filename2 = format_filename2


@lib.deprecated
def process(func, plugins, context, test=None):
r"""Primary processing logic
Takes callables and data as input, and performs
logical operations on them until the currently
registered test fails.
If `plugins` is a callable, it is called early, before
processing begins. If `context` is a callable, it will
be called once per plug-in.
Arguments:
func (callable): Callable taking three arguments;
plugin(Plugin), context(Context) and optional
instance(Instance). Each must provide a matching
interface to their corresponding objects.
plugins (list, callable): Plug-ins to process. If a
callable is provided, the return value is used
as plug-ins. It is called with no arguments.
context (Context, callable): Context whose instances
are to be processed. If a callable is provided,
the return value is used as context. It is called
with no arguments.
test (callable, optional): Provide custom test, defaults
to the currently registered test.
Yields:
A result per complete process. If test fails,
a TestFailed exception is returned, containing the
variables used in the test. Finally, any exception
thrown by `func` is yielded. Note that this is
considered a bug in *your* code as you are the one
supplying it.
"""

__plugins = plugins
__context = context

if test is None:
test = logic.registered_test()

if hasattr(__plugins, "__call__"):
plugins = __plugins()

def gen(plugin, instances):
if plugin.__instanceEnabled__ and len(instances) > 0:
for instance in instances:
yield instance
else:
yield None

vars = {
"nextOrder": None,
"ordersWithError": list()
}

# Clear introspection values
# TODO(marcus): Return *next* pair, this currently
# returns the current pair.
self = process
self.next_plugin = None
self.next_instance = None

for Plugin in plugins:
self.next_plugin = Plugin
vars["nextOrder"] = Plugin.order

if not test(**vars):
if hasattr(__context, "__call__"):
context = __context()

args = inspect.getargspec(Plugin.process).args

# Backwards compatibility with `asset`
if "asset" in args:
args.append("instance")

instances = logic.instances_by_plugin(context, Plugin)

# Limit processing to plug-ins with an available instance
if not instances and "*" not in Plugin.families:
continue

for instance in gen(Plugin, instances):
if instance is None and "instance" in args:
continue

# Provide introspection
self.next_instance = instance

try:
result = func(Plugin, context, instance)

except Exception as exc:
# Any exception occuring within the function
# you pass is yielded, you are expected to
# handle it.
yield exc

else:
# Make note of the order at which
# the potential error error occured.
if result["error"]:
if Plugin.order not in vars["ordersWithError"]:
vars["ordersWithError"].append(Plugin.order)
yield result

# Clear current
self.next_instance = None

else:
yield logic.TestFailed(test(**vars), vars)
break


process.next_plugin = None
process.next_instance = None

logic.process = process
10 changes: 6 additions & 4 deletions pyblish/lib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import re
import sys
import logging
import datetime
Expand Down Expand Up @@ -237,8 +236,10 @@ def emit(signal, **kwargs):
Example:
>>> import sys
>>> from .plugin import register_callback
>>> register_callback("mysignal", lambda data: sys.stdout.write(str(data)))
>>> from . import plugin
>>> plugin.register_callback(
... "mysignal", lambda data: sys.stdout.write(str(data)))
...
>>> emit("mysignal", data={"something": "cool"})
{'something': 'cool'}
Expand All @@ -252,14 +253,15 @@ def emit(signal, **kwargs):
traceback.print_exc(file=file)
sys.stderr.write(file.getvalue())
# Why the roundabout through StringIO?
#
#
# tests.lib.captured_stderr attempts to capture stderr
# but doing so with plain print_exc() results in a type
# error in Python 3. I'm not confident in Python 3 unicode
# handling so there is likely a better way to solve this.
#
# TODO(marcus): Make it prettier


def deprecated(func):
"""Deprecation decorator
Expand Down
Loading

0 comments on commit f54ab15

Please sign in to comment.