From 6365cc9ba0fee6b3974a727fab0a840540ed0726 Mon Sep 17 00:00:00 2001 From: birkholz-cubert Date: Mon, 10 Nov 2025 14:22:20 +0100 Subject: [PATCH] Replaced pkg_resources with importlib.metadata.version --- cuvis/General.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/cuvis/General.py b/cuvis/General.py index 724cddb..384b3bb 100644 --- a/cuvis/General.py +++ b/cuvis/General.py @@ -1,7 +1,7 @@ import logging import os import platform -import pkg_resources +from importlib.metadata import version as imp_version from ._cuvis_il import cuvis_il from .cuvis_aux import SDKException @@ -12,16 +12,22 @@ from typing import Union, Optional -def init(settings_path: str = ".", global_loglevel: Union[int, str] = logging.DEBUG, logfile_name: Optional[str] = None): - if 'CUVIS_SETTINGS' in os.environ and settings_path == ".": +def init( + settings_path: str = ".", + global_loglevel: Union[int, str] = logging.DEBUG, + logfile_name: Optional[str] = None, +): + if "CUVIS_SETTINGS" in os.environ and settings_path == ".": # env variable is set and settings path is default kwarg - settings_path = os.environ['CUVIS_SETTINGS'] + settings_path = os.environ["CUVIS_SETTINGS"] if isinstance(global_loglevel, str): # also support string as input argument global_loglevel = internal.__strToLogLevel__[global_loglevel] - if cuvis_il.status_ok != cuvis_il.cuvis_init(settings_path, internal.__CuvisLoglevel__[global_loglevel], logfile_name): + if cuvis_il.status_ok != cuvis_il.cuvis_init( + settings_path, internal.__CuvisLoglevel__[global_loglevel], logfile_name + ): raise SDKException() @@ -38,14 +44,13 @@ def sdk_version() -> str: def wrapper_version() -> str: - pip_version = pkg_resources.require('cuvis')[0].version - with open(Path(__file__).parent.parent / "git-hash.txt", 'r') as f: + pip_version = imp_version("cuvis") + with open(Path(__file__).parent.parent / "git-hash.txt", "r") as f: git_hash = f.readline() - return f'{pip_version} {git_hash}'.strip() + return f"{pip_version} {git_hash}".strip() -def set_log_level(lvl: Union[int, str]): - +def set_log_level(lvl: Union[int, str]): if isinstance(lvl, str): # also support string as input argument lvl = internal.__strToLogLevel__[lvl]