From 0a384924652ec1e4614149c1919f270e6cc291b5 Mon Sep 17 00:00:00 2001 From: Simon Birkholz Date: Wed, 20 Nov 2024 11:57:34 +0100 Subject: [PATCH 1/4] added function to retrive wrapper version --- cuvis/General.py | 32 ++++++++++++++++++++++++-------- git-hash.txt | 1 + setup.py | 14 ++++++++++++-- 3 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 git-hash.txt diff --git a/cuvis/General.py b/cuvis/General.py index b03a3ba..e16141b 100644 --- a/cuvis/General.py +++ b/cuvis/General.py @@ -1,17 +1,19 @@ import logging import os import platform +import pkg_resources from ._cuvis_il import cuvis_il from .cuvis_aux import SDKException from .cuvis_types import ComponentType +from pathlib import Path import cuvis.cuvis_types as internal from dataclasses import dataclass -def init(settings_path:str=".", log_path:str="", global_loglevel:int=logging.DEBUG): +def init(settings_path: str = ".", log_path: str = "", global_loglevel: int = logging.DEBUG): FORMAT = '%(asctime)s -- %(levelname)s: %(message)s' if os.path.exists(log_path): pass @@ -21,9 +23,9 @@ def init(settings_path:str=".", log_path:str="", global_loglevel:int=logging.DEB elif platform.system() == "Windows": log_path = "C:\\ProgramData\\cuvis" os.makedirs(log_path, exist_ok=True) - + if os.path.exists(log_path): - logging.basicConfig(filename= os.path.join(log_path, "cuvisSDK_python.log"), + logging.basicConfig(filename=os.path.join(log_path, "cuvisSDK_python.log"), format=FORMAT, encoding='utf-8', level=global_loglevel, @@ -36,21 +38,35 @@ def init(settings_path:str=".", log_path:str="", global_loglevel:int=logging.DEB if cuvis_il.status_ok != cuvis_il.cuvis_init(settings_path, internal.__CuvisLoglevel__[global_loglevel]): raise SDKException() + def shutdown(): cuvis_il.cuvis_shutdown() + def version() -> str: return cuvis_il.cuvis_version_swig() + +def sdk_version() -> str: + return version() + + +def wrapper_version() -> str: + pip_version = pkg_resources.require('cuvis')[0].version + with open(Path(__file__).parent / "git-hash.txt", 'r') as f: + git_hash = f.readline() + return f'{pip_version} {git_hash}' + + def set_log_level(lvl): lvl_dict = {"info": {"cuvis": cuvis_il.loglevel_info, - "logging": logging.INFO}, + "logging": logging.INFO}, "debug": {"cuvis": cuvis_il.loglevel_debug, - "logging": logging.DEBUG}, + "logging": logging.DEBUG}, "error": {"cuvis": cuvis_il.loglevel_error, - "logging": logging.ERROR}, + "logging": logging.ERROR}, "fatal": {"cuvis": cuvis_il.loglevel_fatal, - "logging": logging.CRITICAL}, + "logging": logging.CRITICAL}, "warning": {"cuvis": cuvis_il.loglevel_warning, "logging": logging.WARNING}, } @@ -75,7 +91,7 @@ def _get_internal(self): ci.userfield = self.user_field ci.pixelformat = self.pixel_format return ci - + @classmethod def _from_internal(cls, ci): return cls(type=internal.__ComponentType__[ci.type], diff --git a/git-hash.txt b/git-hash.txt new file mode 100644 index 0000000..87edf79 --- /dev/null +++ b/git-hash.txt @@ -0,0 +1 @@ +unknown \ No newline at end of file diff --git a/setup.py b/setup.py index 21a324e..13dca0f 100644 --- a/setup.py +++ b/setup.py @@ -2,10 +2,11 @@ import platform import sys import io - +import subprocess from shutil import rmtree, copy from setuptools import setup, find_packages, Command from setuptools.command import develop +from pathlib import Path here = os.path.abspath(os.path.dirname(__file__)) @@ -34,6 +35,13 @@ Exception( 'CUVIS SDK does not seem to exist on this machine! Make sure that the environment variable CUVIS is set.') + +def get_git_commit_hash() -> str: + try: + return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip() + except subprocess.CalledProcessError: + return 'unknown' + # taken from https://github.com/navdeep-G/setup.py/blob/master/setup.py @@ -67,7 +75,7 @@ def run(self): os.system('python setup.py sdist'.format(sys.executable)) self.status('Uploading the package to PyPI via Twine…') - os.system('twine upload -r testpypi dist/*') + os.system('twine upload dist/*') # self.status('Pushing git tags…') # os.system('git tag v{0}'.format(about['__version__'])) @@ -116,6 +124,8 @@ def __createManifest__(subdirs): except FileNotFoundError: long_description = DESCRIPTION +with open(Path(__file__).parent / "git-hash.txt", 'w') as f: + f.write(f'{get_git_commit_hash()}\n') setup( name=NAME, From 6f5d3c53f457a23dbd1cc706f53daac985c19808 Mon Sep 17 00:00:00 2001 From: Simon Birkholz Date: Wed, 20 Nov 2024 12:48:14 +0100 Subject: [PATCH 2/4] include in manifest --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 13dca0f..e6904aa 100644 --- a/setup.py +++ b/setup.py @@ -98,7 +98,8 @@ def __createManifest__(subdirs): current = os.path.dirname(__file__) relative_paths = [os.path.relpath(path, current) for path in subdirs] - single_files = [os.path.join(here, 'README.md')] + single_files = [os.path.join(here, 'README.md'), + os.path.join(here, 'git-hash.txt')] rel_single_files = [os.path.relpath(path, current) for path in single_files] From 281c00ec0872816ecf6b644b022810ea7c0bf7c6 Mon Sep 17 00:00:00 2001 From: Simon Birkholz Date: Wed, 20 Nov 2024 12:50:33 +0100 Subject: [PATCH 3/4] removed short hash --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e6904aa..610b234 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ def get_git_commit_hash() -> str: try: - return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip() + return subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip() except subprocess.CalledProcessError: return 'unknown' From df838d63f5fba1ce157bab8f0f72bbeee7ce060f Mon Sep 17 00:00:00 2001 From: Simon Birkholz Date: Wed, 20 Nov 2024 12:57:40 +0100 Subject: [PATCH 4/4] fixes --- cuvis/General.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cuvis/General.py b/cuvis/General.py index e16141b..46f8c0f 100644 --- a/cuvis/General.py +++ b/cuvis/General.py @@ -53,9 +53,9 @@ def sdk_version() -> str: def wrapper_version() -> str: pip_version = pkg_resources.require('cuvis')[0].version - with open(Path(__file__).parent / "git-hash.txt", 'r') as f: + with open(Path(__file__).parent.parent / "git-hash.txt", 'r') as f: git_hash = f.readline() - return f'{pip_version} {git_hash}' + return f'{pip_version} {git_hash}'.strip() def set_log_level(lvl):