From 1a0226a7efef822fc5315943166a1c05939f2d6a Mon Sep 17 00:00:00 2001 From: Olivier Ramonat Date: Mon, 9 Sep 2019 08:49:23 +0200 Subject: [PATCH] Take into account several plan lines in context plan_line attribute is reused to store several plan lines separated by ';'. Long term solution would be to rename it plan_lines and to have a tuple of plan lines. For #293 --- e3/electrolyt/plan.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/e3/electrolyt/plan.py b/e3/electrolyt/plan.py index bd4af289..27e70b10 100644 --- a/e3/electrolyt/plan.py +++ b/e3/electrolyt/plan.py @@ -251,31 +251,40 @@ def _add_action(self, name, *args, **kwargs): if self.ignore_disabled and not self.env.enabled: return + # ??? sometimes to understand the context it would be better to have + # several lines of plan, e.g. when an action is created by calling + # a function defined in a plan. Include all these lines separated + # by ';'. A better fix would be to change plan_line to plan_lines + # containing a tuple of plan_line. plan_line = 'unknown filename:unknown lineno' # Retrieve the plan line try: caller_frames = inspect.getouterframes( frame=inspect.currentframe()) - caller_frame = None + caller_frames_in_plan = [] for frame in caller_frames: if isinstance(frame, tuple): # py2-only frame_filename = frame[1] else: # py3-only frame_filename = frame.filename if frame_filename.endswith(self.plan.plan_ext): - caller_frame = frame + caller_frames_in_plan.append(frame) except Exception: # defensive code # do not crash when inspect frames fails pass else: - if caller_frame is None: # defensive code + if not caller_frames_in_plan: # No information ? pass - elif isinstance(caller_frame, tuple): # py2-only - plan_line = '{}:{}'.format(caller_frame[1], caller_frame[2]) + elif isinstance(caller_frames_in_plan[0], tuple): # py2-only + plan_line = ';'.join(( + '{}:{}'.format(caller_frame[1], caller_frame[2]) + for caller_frame in caller_frames_in_plan)) else: # py3-only - plan_line = '{}:{}'.format( - caller_frame.filename, caller_frame.lineno) + plan_line = ';'.join(( + '{}:{}'.format( + caller_frame.filename, caller_frame.lineno) + for caller_frame in caller_frames_in_plan)) # First create our initial object based on current scope env result = self.env.copy()