Skip to content

Commit

Permalink
qc: add a utility function for finding stack level
Browse files Browse the repository at this point in the history
  • Loading branch information
JoepVanlier committed Mar 4, 2024
1 parent cc6a744 commit 271eeb1
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lumicks/pylake/detail/utilities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import math
import contextlib
import pathlib
import inspect

import numpy as np
import cachetools
Expand Down Expand Up @@ -213,3 +215,22 @@ def temp_seed(seed):
yield
finally:
np.random.seed(None)


def find_stack_level() -> int:
"""Find where we leave the module"""
import lumicks.pylake as lk

pylake_folder = pathlib.Path(lk.__file__).parent

depth = 0
frame = inspect.currentframe()
while frame:
current_path = pathlib.Path(inspect.getfile(frame))
if pylake_folder in current_path.parents and "tests" not in current_path.parts:
frame = frame.f_back
depth += 1
else:
break

return depth

0 comments on commit 271eeb1

Please sign in to comment.