Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take into account several plan lines in context #294

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions e3/electrolyt/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down