Skip to content

Commit

Permalink
Merge pull request #114 from chadmv/iterator_reset
Browse files Browse the repository at this point in the history
Fix #59, fix #113
  • Loading branch information
mottosso authored Nov 13, 2020
2 parents 5f8eacf + ab2f46f commit ca89c50
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
40 changes: 32 additions & 8 deletions pyblish_lite/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,18 @@ def reset(self):
on_finished=self.was_reset.emit)

def validate(self):
# The iterator doesn't sync with the GUI check states so
# reset the iterator to ensure we grab the updated instances
self._reset_iterator(start_from=pyblish.api.ValidatorOrder)
self._run(until=pyblish.api.ValidatorOrder,
on_finished=self.on_validated)

def publish(self):
plugin = self.current_pair[0]
if plugin:
# The iterator doesn't sync with the GUI check states so
# reset the iterator to ensure we grab the updated instances
self._reset_iterator(start_from=plugin.order)
self._run(on_finished=self.on_published)

def on_validated(self):
Expand Down Expand Up @@ -171,18 +179,22 @@ def on_next():
if order > (until + 0.5):
return util.defer(100, on_finished_)

self.about_to_process.emit(*self.current_pair)
# The instance may have been disabled, check because the iterator will
# have already provided it
if self._current_pair_is_active():
self.about_to_process.emit(*self.current_pair)

util.defer(10, on_process)

def on_process():
try:
result = self._process(*self.current_pair)
if self._current_pair_is_active():
result = self._process(*self.current_pair)

if result["error"] is not None:
self.current_error = result["error"]
if result["error"] is not None:
self.current_error = result["error"]

self.was_processed.emit(result)
self.was_processed.emit(result)

except Exception as e:
stack = traceback.format_exc()
Expand Down Expand Up @@ -223,19 +235,31 @@ def on_finished_():
self.is_running = True
util.defer(10, on_next)

def _iterator(self, plugins, context):
def _current_pair_is_active(self):
return self.current_pair[1] is None or self.current_pair[1].data.get("publish", True)

def _reset_iterator(self, start_from=-float("inf")):
self.is_running = True
self.pair_generator = self._iterator(self.plugins,
self.context,
start_from)
self.current_pair = next(self.pair_generator, (None, None))
self.is_running = False

def _iterator(self, plugins, context, start_from=-float("inf")):
"""Yield next plug-in and instance to process.
Arguments:
plugins (list): Plug-ins to process
context (pyblish.api.Context): Context to process
"""

test = pyblish.logic.registered_test()

for plug, instance in pyblish.logic.Iterator(plugins, context):
if not plug.active:
order = plug.order

if order < start_from or not plug.active:
continue

if instance is not None and instance.data.get("publish") is False:
Expand Down
8 changes: 4 additions & 4 deletions pyblish_lite/version.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

VERSION_MAJOR = 0
VERSION_MINOR = 8
VERSION_PATCH = 7
VERSION_PATCH = 8
VERSION_BETA = "b1"


version_info = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)
version = '%i.%i.%i' % version_info
version_info = (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_BETA)
version = '%i.%i.%i%s' % version_info
__version__ = version

__all__ = ['version', 'version_info', '__version__']

0 comments on commit ca89c50

Please sign in to comment.