abstractfactory/pyblish — pull request #69 by mottosso (2014-09-06 07:43:52+00:00)
Title: Improved plugin interface

A much simplified interface for plugins with methods separated for Instance and Context arguments.
https://groups.google.com/forum/#!topic/pyblish/tcY3SBK-NHQ

Plugins that implement `process()` will still work as-is, the method has simply gotten a base class implementation that triggers `process_instance()` and `process_context()`.

```python
# Psuedo-code
def process(self, context):
self.process_context(context)
for instance in context:
self.process_instance(instance)
```

In a nutshell, plugins that modify the context only need to override `process_context()` and plugins that modify the instance override `process_instance()`. Some plugins modify both, and that is okay.

`process_instance()` comes with the added benefit of getting only compatible instances as argument.

```python
class ValidateModelFamily(Validator):
families = ['model']
def process_instance(self, instance):
# instance is of family "model"
```

# Data

Additionally, collected data is now fully part of the Selection process, which works really well! What this means is that, rather than validators or extractors gathering information from the scene or system, selectors gather this information and stores it within each instance or context. The information includes:

- System time and date
- Currently logged on user
- Current working directory
- Current working file
- Optional workspace

The data may then be used by plugins and they are guaranteed to get the same data, which may vary with e.g. collecting `date` if one plugin executes a few seconds after the first.

It also means we can start making more defined assumptions and requirements from and in our plugins. For example, a conform plugin that takes data from a temporary location as provided by an extractor will need to know where to find this information. This allows us to set up rules for how plugins communicate with each other. Extractor plugins can now communicate with Conform plugins via members of data.

```python
# Extractor
instance.set_data('temporary_location', value='c:\temp\data_here.mb')

# Conform
shutil.copytree(instance.data('temporary_location'), '\\server\final_destination')
```

To get started, I included a few data selectors.
https://github.com/mottosso/pyblish/tree/master/pyblish/backend/plugins

Best,
Marcus