Use better scheme for getting root directory
This commit is contained in:
parent
6c854246aa
commit
de7171db8a
@ -69,9 +69,13 @@ def set_stacktrace(flag):
|
|||||||
def process_stacktrace(countback):
|
def process_stacktrace(countback):
|
||||||
"""Gives file and line frame 'countback' frames from the bottom"""
|
"""Gives file and line frame 'countback' frames from the bottom"""
|
||||||
st = traceback.extract_stack()
|
st = traceback.extract_stack()
|
||||||
# First entry should be bin/spack. Use this to get spack 'root'.
|
# All entries will be spack files based on how this function is called.
|
||||||
# bin/spack is 9 characters, the length of the 'root' is then len-9.
|
# We use commonprefix to find what the spack 'root' directory is.
|
||||||
root_len = len(st[0][0]) - 9
|
file_list = []
|
||||||
|
for frame in st:
|
||||||
|
file_list.append(frame[0])
|
||||||
|
root_dir = os.path.commonprefix(file_list)
|
||||||
|
root_len = len(root_dir)
|
||||||
st_idx = len(st) - countback - 1
|
st_idx = len(st) - countback - 1
|
||||||
st_text = "%s:%i " % (st[st_idx][0][root_len:], st[st_idx][1])
|
st_text = "%s:%i " % (st[st_idx][0][root_len:], st[st_idx][1])
|
||||||
return st_text
|
return st_text
|
||||||
|
Loading…
Reference in New Issue
Block a user