Closed ghost closed 3 years ago
Hello @StephenCarboni,
this feature is included but not (yet) accessible. After you initialize your Task, do this:
# m = Task()
m.skip_references = False # next time markup is updated, include reference labels
m.add_transition(trigger='reset', source="*", dest="Stage 1") # force a markup update
The output looks like this:
As you see, printing the reference function name clutters the output significantly. Imo, just printing the function's name removes too much vital information (that it is a reference and not a callback present in the model). Do you have any suggestions for a good compromise between readability and "informativeness"?
If the callable is passed directly and it exists in the model, then it is practically the same as if I had provided a string. So if we assert that the callable is in the model, then just printing the name should be okay?
If the callable is outside the model, then printing its qualified name (other_module.task.can_go_backwards
) should be enough, but I'm not sure.
Idea: a formatting hook so that users can decide the final string.
I refactored MarkupMachine
a bit and introduced MarkupMachine.format_references
with a default formatting. This works quite well but has to be overridden for classes derived from LockedMachine
. The reason why they are so cluttered in your example is the fact that the partial is wrapped into _locked_method
. This is taken care of in factory
and should now return the proper callback. The example below will be added to the ReadMe:
from transitions.extensions import GraphMachine as Machine
from functools import partial
class Model:
def clear_state(self, deep=False, force=False):
print("Clearing state ...")
return True
model = Model()
machine = Machine(model=model, states=['A', 'B', 'C'],
transitions=[
{'trigger': 'clear', 'source': 'B', 'dest': 'A', 'conditions': model.clear_state},
{'trigger': 'clear', 'source': 'C', 'dest': 'A',
'conditions': partial(model.clear_state, False, force=True)},
],
initial='A', show_conditions=True)
model.get_graph().draw('my_state_diagram.png', prog='dot')
resulting in:
Your example above looks like this:
MarkupMachine.format_references
or (Locked)GraphMachine.format_references
can be overridden if this is not sufficient.
The machine behaves as expected, but the diagram does not show all the conditions.