Skip to content

Commit 409ab56

Browse files
Replaced pkg_resources with importlib.metadata.version (#73)
1 parent 1d2e452 commit 409ab56

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

cuvis/General.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import os
33
import platform
4-
import pkg_resources
4+
from importlib.metadata import version as imp_version
55

66
from ._cuvis_il import cuvis_il
77
from .cuvis_aux import SDKException
@@ -12,16 +12,22 @@
1212
from typing import Union, Optional
1313

1414

15-
def init(settings_path: str = ".", global_loglevel: Union[int, str] = logging.DEBUG, logfile_name: Optional[str] = None):
16-
if 'CUVIS_SETTINGS' in os.environ and settings_path == ".":
15+
def init(
16+
settings_path: str = ".",
17+
global_loglevel: Union[int, str] = logging.DEBUG,
18+
logfile_name: Optional[str] = None,
19+
):
20+
if "CUVIS_SETTINGS" in os.environ and settings_path == ".":
1721
# env variable is set and settings path is default kwarg
18-
settings_path = os.environ['CUVIS_SETTINGS']
22+
settings_path = os.environ["CUVIS_SETTINGS"]
1923

2024
if isinstance(global_loglevel, str):
2125
# also support string as input argument
2226
global_loglevel = internal.__strToLogLevel__[global_loglevel]
2327

24-
if cuvis_il.status_ok != cuvis_il.cuvis_init(settings_path, internal.__CuvisLoglevel__[global_loglevel], logfile_name):
28+
if cuvis_il.status_ok != cuvis_il.cuvis_init(
29+
settings_path, internal.__CuvisLoglevel__[global_loglevel], logfile_name
30+
):
2531
raise SDKException()
2632

2733

@@ -38,14 +44,13 @@ def sdk_version() -> str:
3844

3945

4046
def wrapper_version() -> str:
41-
pip_version = pkg_resources.require('cuvis')[0].version
42-
with open(Path(__file__).parent.parent / "git-hash.txt", 'r') as f:
47+
pip_version = imp_version("cuvis")
48+
with open(Path(__file__).parent.parent / "git-hash.txt", "r") as f:
4349
git_hash = f.readline()
44-
return f'{pip_version} {git_hash}'.strip()
50+
return f"{pip_version} {git_hash}".strip()
4551

4652

47-
def set_log_level(lvl: Union[int, str]):
48-
53+
def set_log_level(lvl: Union[int, str]):
4954
if isinstance(lvl, str):
5055
# also support string as input argument
5156
lvl = internal.__strToLogLevel__[lvl]

0 commit comments

Comments
 (0)