From 009843cf6e9b60665d0205e9f0bde60304fb1710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Mon, 29 Jan 2024 16:08:58 +0100 Subject: [PATCH 1/2] Always delete frame after finding stacklevel --- holoviews/util/warnings.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/holoviews/util/warnings.py b/holoviews/util/warnings.py index c24a13f254..2bf6366ebb 100644 --- a/holoviews/util/warnings.py +++ b/holoviews/util/warnings.py @@ -34,14 +34,18 @@ def find_stack_level(): param_dir = os.path.dirname(param.__file__) frame = inspect.currentframe() - stacklevel = 0 - while frame: - fname = inspect.getfile(frame) - if fname.startswith((pkg_dir, param_dir)) and not fname.startswith(test_dir): - frame = frame.f_back - stacklevel += 1 - else: - break + try: + stacklevel = 0 + while frame: + fname = inspect.getfile(frame) + if fname.startswith((pkg_dir, param_dir)) and not fname.startswith(test_dir): + frame = frame.f_back + stacklevel += 1 + else: + break + finally: + # See: https://docs.python.org/3/library/inspect.html#inspect.Traceback + del frame return stacklevel From 819a5346002e14d20f364b32e0342e1d196db93f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Mon, 29 Jan 2024 16:14:09 +0100 Subject: [PATCH 2/2] Use importlib.metadata version --- scripts/check_latest_packages.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/check_latest_packages.py b/scripts/check_latest_packages.py index 9fcada6001..5e4f378425 100644 --- a/scripts/check_latest_packages.py +++ b/scripts/check_latest_packages.py @@ -1,5 +1,6 @@ import sys from datetime import date, datetime, timedelta +from importlib.metadata import version import requests from packaging.version import Version @@ -13,7 +14,7 @@ def main(*packages): url = f"https://pypi.org/pypi/{package}/json" resp = requests.get(url, timeout=20).json() latest = resp["info"]["version"] - current = __import__(package).__version__ + current = version(package) latest_release_date = datetime.fromisoformat( resp["releases"][latest][0]["upload_time_iso_8601"]