1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
3 NAMEBASE= python-transitions
7 SDESC[py310]= Extensible state machine implementation (3.10)
8 SDESC[v11]= Extensible state machine implementation (3.11)
9 HOMEPAGE= https://github.com/pytransitions/transitions
10 CONTACT= Python_Automaton[python@ironwolf.systems]
13 SITES[main]= PYPIWHL/ee/35/77e8f975da682e14e1581ae0f47f4e3beed29871794f26ce7c9d4dd32b14
14 DISTFILE[1]= transitions-0.9.0-py2.py3-none-any.whl:main
19 OPTIONS_AVAILABLE= PY310 PY311
20 OPTIONS_STANDARD= none
21 VOPTS[py310]= PY310=ON PY311=OFF
22 VOPTS[v11]= PY310=OFF PY311=ON
24 DISTNAME= transitions-0.9.0.dist-info
28 [PY310].RUN_DEPENDS_ON= python-six:single:py310
29 [PY310].USES_ON= python:py310,wheel
31 [PY311].RUN_DEPENDS_ON= python-six:single:v11
32 [PY311].USES_ON= python:v11,wheel
34 [FILE:3186:descriptions/desc.single]
37 They say [a good example is worth] 100 pages of API documentation, a
38 million directives, or a thousand words.
40 Well, "they" probably lie... but here's an example anyway:
43 from transitions import Machine
46 class NarcolepticSuperhero(object):
48 # Define some states. Most of the time, narcoleptic superheroes are
50 # everyone else. Except for...
51 states = ['asleep', 'hanging out', 'hungry', 'sweaty', 'saving the
54 def __init__(self, name):
56 # No anonymous superheroes on my watch! Every narcoleptic superhero
58 # a name. Any name at all. SleepyMan. SlumberGirl. You get the
62 # What have we accomplished today?
63 self.kittens_rescued = 0
65 # Initialize the state machine
66 self.machine = Machine(model=self,
67 states=NarcolepticSuperhero.states, initial='asleep')
69 # Add some transitions. We could also define these using a static
71 # dictionaries, as we did with states above, and then pass the list
73 # the Machine initializer as the transitions= argument.
75 # At some point, every superhero must rise and shine.
76 self.machine.add_transition(trigger='wake_up', source='asleep',
79 # Superheroes need to keep in shape.
80 self.machine.add_transition('work_out', 'hanging out', 'hungry')
82 # Those calories won't replenish themselves!
83 self.machine.add_transition('eat', 'hungry', 'hanging out')
85 # Superheroes are always on call. ALWAYS. But they're not always
86 # dressed in work-appropriate clothing.
87 self.machine.add_transition('distress_call', '*', 'saving the
89 before='change_into_super_secret_costume')
91 # When they get off work, they're all sweaty and disgusting. But
93 # they do anything else, they have to meticulously log their latest
94 # escapades. Because the legal department says so.
95 self.machine.add_transition('complete_mission', 'saving the world',
97 after='update_journal')
99 # Sweat is a disorder that can be remedied with water.
100 # Unless you've had a particularly long day, in which case... bed
102 self.machine.add_transition('clean_up', 'sweaty', 'asleep',
103 conditions=['is_exhausted'])
104 self.machine.add_transition('clean_up', 'sweaty', 'hanging out')
106 # Our NarcolepticSuperhero can fall asleep at pretty much any time.
107 self.machine.add_transition('nap', '*', 'asleep')
109 def update_journal(self):
110 """ Dear Diary, today I saved Mr. Whiskers. Again. """
111 self.kittens_rescued += 1
114 def is_exhausted(self):
115 """ Basically a coin toss. """
116 return random.random() < 0.5
118 def change_into_super_secret_costume(self):
122 There, now you've baked a state machine into `NarcolepticSuperhero`. Let's
123 take him/her/it out for a spin...
126 >>> batman = NarcolepticSuperhero("Batman")
138 5687ee8c6a3200830e44f988d16b0045f53293f7a873002d7bff70852331a078 97706 transitions-0.9.0-py2.py3-none-any.whl