Skip to content

Commit

Permalink
Merge pull request #3 from Shoobx/python3
Browse files Browse the repository at this point in the history
Python 3 support
  • Loading branch information
regebro committed Feb 6, 2018
2 parents 6848b2a + d60ab07 commit db942e0
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 175 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ language: python
sudo: false
python:
- 2.7
- 3.5
- 3.6
install:
- pip install tox-travis coveralls
script:
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CHANGES
4.0.5 (unreleased)
------------------

- Nothing changed yet.
- Python 3 support.


4.0.4 (2017-11-01)
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def read(*rnames):
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Natural Language :: English',
'Operating System :: OS Independent'],
Expand Down
70 changes: 36 additions & 34 deletions src/shoobx/wfmc/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ the workflow executing by registering a subscriber that logs workflow
events:

>>> def log_workflow(event):
... print event
... print (event)

>>> import zope.event
>>> zope.event.subscribers.append(log_workflow)
Expand Down Expand Up @@ -225,10 +225,10 @@ We'll start by defining a simple Participant class:
>>> import zope.interface
>>> from shoobx.wfmc import interfaces

>>> class Participant(object):
>>> @zope.interface.implementer(interfaces.IParticipant)
... class Participant(object):
... zope.component.adapts(interfaces.IActivity)
... zope.interface.implements(interfaces.IParticipant)
...
...
... def __init__(self, activity, process):
... self.activity = activity

Expand All @@ -246,17 +246,17 @@ Now we'll define our work-items. First we'll define some classes:

>>> work_list = []

>>> class ApplicationBase:
>>> @zope.interface.implementer(interfaces.IWorkItem)
... class ApplicationBase:
... zope.component.adapts(interfaces.IParticipant)
... zope.interface.implements(interfaces.IWorkItem)
...
...
... def __init__(self, participant, process, activity):
... self.participant = participant
... work_list.append(self)
...
...
... def start(self, args):
... pass
...
...
... def finish(self):
... self.participant.activity.workItemFinished(self)

Expand All @@ -267,12 +267,12 @@ Now we'll define our work-items. First we'll define some classes:

>>> class Publish(ApplicationBase):
... def start(self, args):
... print "Published"
... print ("Published")
... self.finish()

>>> class Reject(ApplicationBase):
... def start(self, args):
... print "Rejected"
... print ("Rejected")
... self.finish()

and then we'll hook them up with the integration object:
Expand Down Expand Up @@ -769,7 +769,7 @@ them. Finally, we'll create multiple authors and use the selected one:
... def __init__(self, activity, process):
... Participant.__init__(self, activity, process)
... author_name = activity.process.workflowRelevantData.author
... print "Author `%s` selected" % author_name
... print(("Author `%s` selected" % author_name))
... self.user = authors[author_name]

In this example, we need to define a separate attribute for each participant:
Expand Down Expand Up @@ -799,18 +799,18 @@ performers:

Now we'll create our applications. Let's start with our author:

>>> class ApplicationBase(object):
>>> @zope.interface.implementer(interfaces.IWorkItem)
... class ApplicationBase(object):
... zope.component.adapts(interfaces.IParticipant)
... zope.interface.implements(interfaces.IWorkItem)
...
...
... def __init__(self, participant, process, activity):
... self.participant = participant
... self.activity = participant.activity
... participant.user.work_list.append(self)
...
...
... def start(self, args):
... pass
...
...
... def finish(self):
... self.participant.activity.workItemFinished(self)

Expand All @@ -820,13 +820,13 @@ Now we'll create our applications. Let's start with our author:
... process = self.activity.process
... doc = getattr(process.applicationRelevantData, 'doc', '')
... if doc:
... print 'Previous draft:'
... print doc
... print 'Changes we need to make:'
... print ('Previous draft:')
... print (doc)
... print ('Changes we need to make:')
... for change in process.workflowRelevantData.tech_changes:
... print change
... print (change)
... else:
... print 'Please write the initial draft'
... print ('Please write the initial draft')
...
... def finish(self, doc):
... self.activity.process.applicationRelevantData.doc = doc
Expand Down Expand Up @@ -896,16 +896,16 @@ We'll reuse the `publish` and `reject` application from the previous
example.

>>> class Final(ApplicationBase):
...
...
... def summary(self):
... process = self.activity.process
... doc = getattr(process.applicationRelevantData, 'doc', '')
... print 'Previous draft:'
... print self.activity.process.applicationRelevantData.doc
... print 'Changes we need to make:'
... print ('Previous draft:')
... print((self.activity.process.applicationRelevantData.doc))
... print ('Changes we need to make:')
... for change in process.workflowRelevantData.ed_changes:
... print change
...
... print (change)
...
... def finish(self, doc):
... self.activity.process.applicationRelevantData.doc = doc
... super(Final, self).finish()
Expand All @@ -926,9 +926,9 @@ changes.
Our process now returns data. When we create a process, we need to
supply an object that it can call back to:

>>> class PublicationContext:
... zope.interface.implements(interfaces.IProcessContext)
...
>>> @zope.interface.implementer(interfaces.IProcessContext)
... class PublicationContext:
...
... def processFinished(self, process, decision):
... self.decision = decision

Expand Down Expand Up @@ -970,7 +970,7 @@ Notice that we transitioned to *two* activities, `tech1` and
Now we'll do a tech review. Let's see what tech1 has:

>>> item = tech1.work_list.pop()
>>> print item.getDoc()
>>> print((item.getDoc()))
I give my pledge, as an American
to save, and faithfully to defend from waste
the natural resources of my Country.
Expand Down Expand Up @@ -1059,7 +1059,7 @@ weren't any technical changes. We're ready to do our editorial review.
We'll request an editorial change:

>>> item = reviewer.work_list.pop()
>>> print item.getDoc()
>>> print((item.getDoc()))
I give my pledge, as an Earthling
to save, and faithfully to defend from waste
the natural resources of my planet.
Expand Down Expand Up @@ -1099,7 +1099,7 @@ We transition to the activity for reviewing the final edits. We
review the document and approve it for publication:

>>> item = reviewer.work_list.pop()
>>> print item.getDoc()
>>> print((item.getDoc()))
I give my pledge, as a Earthling
to save, and faithfully to defend from waste
the natural resources of my planet.
Expand Down Expand Up @@ -1132,3 +1132,5 @@ See also
---------
http://www.wfmc.org
http://www.wfmc.org/standards/standards.htm


24 changes: 13 additions & 11 deletions src/shoobx/wfmc/adapter/integration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ participant:
>>> import zope.interface
>>> from shoobx.wfmc import interfaces

>>> class Participant(object):
>>> @zope.interface.implementer(interfaces.IParticipant)
... class Participant(object):
... zope.component.adapts(interfaces.IActivity)
... zope.interface.implements(interfaces.IParticipant)
...
...
... def __init__(self, activity):
... self.activity = activity

Expand All @@ -97,17 +97,17 @@ And finally, we can define adapters that implement our application:

>>> work_list = []

>>> class ApplicationBase:
>>> @zope.interface.implementer(interfaces.IWorkItem)
... class ApplicationBase:
... zope.component.adapts(interfaces.IParticipant)
... zope.interface.implements(interfaces.IWorkItem)
...
...
... def __init__(self, participant):
... self.participant = participant
... work_list.append(self)
...
...
... def start(self, args):
... pass
...
...
... def finish(self):
... self.participant.activity.workItemFinished(self)

Expand All @@ -124,14 +124,14 @@ And finally, we can define adapters that implement our application:

>>> class Publish(ApplicationBase):
... def start(self, args):
... print "Published"
... print("Published")
... self.finish()

>>> zope.component.provideAdapter(Publish, name=".publish")

>>> class Reject(ApplicationBase):
... def start(self, args):
... print "Rejected"
... print("Rejected")
... self.finish()

>>> zope.component.provideAdapter(Reject, name=".reject")
Expand All @@ -140,7 +140,7 @@ We'll see the workflow executing by registering a subscriber that logs
workflow events:

>>> def log_workflow(event):
... print event
... print(event)

>>> import zope.event
>>> zope.event.subscribers.append(log_workflow)
Expand Down Expand Up @@ -192,3 +192,5 @@ published:
ActivityFinished(Activity('sample.reject'))
ProcessFinished(Process('sample'))
WorkItemStarted('reject')


3 changes: 1 addition & 2 deletions src/shoobx/wfmc/attributeintegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
from zope import interface


@interface.implementer(interfaces.IIntegration)
class AttributeIntegration:
"""Integration component that uses simple attributes
Subclasses provide attributes with suffices Participant or Application to
provide participant and application factories of a given name.
"""

interface.implements(interfaces.IIntegration)

def createParticipant(self, activity, proc, performer):
factory = getattr(self, performer + 'Participant')
return factory(activity, proc)
Expand Down
14 changes: 8 additions & 6 deletions src/shoobx/wfmc/deadline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ Define WorkItems used by the process::
>>> @zope.interface.implementer(interfaces.IWorkItem)
... class OutputWorkItem(object):
... id = None
...
...
... def __init__(self, process, activity):
... self.process = process
... self.activity = activity
...
...
... def start(self, args):
... print "START:", args['message']
... print(("START: " + args['message']))

>>> @zope.interface.implementer(interfaces.IWorkItem)
... class InputWorkItem(object):
... id = None
...
...
... def __init__(self, process, activity):
... self.process = process
... self.activity = activity
...
...
... def start(self, args):
... print "START:", args['message']
... print(("START: " + args['message']))

Define integration object::

Expand Down Expand Up @@ -133,3 +133,5 @@ Do it again without the wait
>>> proc.activities.getActive()[0].finish()
>>> proc.isFinished
True


0 comments on commit db942e0

Please sign in to comment.