Skip to content

Commit 94bd7b9

Browse files
authored
build_environment: drop off by one fix (spack#47960)
1 parent f181ac1 commit 94bd7b9

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

lib/spack/spack/build_environment.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,27 +1426,20 @@ def make_stack(tb, stack=None):
14261426
# We found obj, the Package implementation we care about.
14271427
# Point out the location in the install method where we failed.
14281428
filename = inspect.getfile(frame.f_code)
1429-
lineno = frame.f_lineno
1430-
if os.path.basename(filename) == "package.py":
1431-
# subtract 1 because we inject a magic import at the top of package files.
1432-
# TODO: get rid of the magic import.
1433-
lineno -= 1
1434-
1435-
lines = ["{0}:{1:d}, in {2}:".format(filename, lineno, frame.f_code.co_name)]
1429+
lines = [f"{filename}:{frame.f_lineno}, in {frame.f_code.co_name}:"]
14361430

14371431
# Build a message showing context in the install method.
14381432
sourcelines, start = inspect.getsourcelines(frame)
14391433

14401434
# Calculate lineno of the error relative to the start of the function.
1441-
fun_lineno = lineno - start
1435+
fun_lineno = frame.f_lineno - start
14421436
start_ctx = max(0, fun_lineno - context)
14431437
sourcelines = sourcelines[start_ctx : fun_lineno + context + 1]
14441438

14451439
for i, line in enumerate(sourcelines):
14461440
is_error = start_ctx + i == fun_lineno
1447-
mark = ">> " if is_error else " "
14481441
# Add start to get lineno relative to start of file, not function.
1449-
marked = " {0}{1:-6d}{2}".format(mark, start + start_ctx + i, line.rstrip())
1442+
marked = f" {'>> ' if is_error else ' '}{start + start_ctx + i:-6d}{line.rstrip()}"
14501443
if is_error:
14511444
marked = colorize("@R{%s}" % cescape(marked))
14521445
lines.append(marked)

0 commit comments

Comments
 (0)