summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2024-12-06 17:01:46 +0100
committerGitHub <noreply@github.com>2024-12-06 17:01:46 +0100
commit94bd7b9afb8f905a443644c55b1cea2f786d7077 (patch)
tree2e905f0e199e415079925c348bccb381ef122e12
parentf181ac199a6723165b71b7210e990002fc32d71f (diff)
downloadspack-94bd7b9afb8f905a443644c55b1cea2f786d7077.tar.gz
spack-94bd7b9afb8f905a443644c55b1cea2f786d7077.tar.bz2
spack-94bd7b9afb8f905a443644c55b1cea2f786d7077.tar.xz
spack-94bd7b9afb8f905a443644c55b1cea2f786d7077.zip
build_environment: drop off by one fix (#47960)
-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)