summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/build_environment.py13
1 files changed, 3 insertions, 10 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index c46db63c83..337ec98eb1 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -1426,27 +1426,20 @@ def get_package_context(traceback, context=3):
# We found obj, the Package implementation we care about.
# Point out the location in the install method where we failed.
filename = inspect.getfile(frame.f_code)
- lineno = frame.f_lineno
- if os.path.basename(filename) == "package.py":
- # subtract 1 because we inject a magic import at the top of package files.
- # TODO: get rid of the magic import.
- lineno -= 1
-
- lines = ["{0}:{1:d}, in {2}:".format(filename, lineno, frame.f_code.co_name)]
+ lines = [f"{filename}:{frame.f_lineno}, in {frame.f_code.co_name}:"]
# Build a message showing context in the install method.
sourcelines, start = inspect.getsourcelines(frame)
# Calculate lineno of the error relative to the start of the function.
- fun_lineno = lineno - start
+ fun_lineno = frame.f_lineno - start
start_ctx = max(0, fun_lineno - context)
sourcelines = sourcelines[start_ctx : fun_lineno + context + 1]
for i, line in enumerate(sourcelines):
is_error = start_ctx + i == fun_lineno
- mark = ">> " if is_error else " "
# Add start to get lineno relative to start of file, not function.
- marked = " {0}{1:-6d}{2}".format(mark, start + start_ctx + i, line.rstrip())
+ marked = f" {'>> ' if is_error else ' '}{start + start_ctx + i:-6d}{line.rstrip()}"
if is_error:
marked = colorize("@R{%s}" % cescape(marked))
lines.append(marked)