Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions cuvis/General.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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.parent / "git-hash.txt", 'r') as f:
git_hash = f.readline()
return f'{pip_version} {git_hash}'.strip()


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},
}
Expand All @@ -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],
Expand Down
1 change: 1 addition & 0 deletions git-hash.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unknown
17 changes: 14 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))

Expand Down Expand Up @@ -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', 'HEAD']).decode('ascii').strip()
except subprocess.CalledProcessError:
return 'unknown'

# taken from https://github.com/navdeep-G/setup.py/blob/master/setup.py


Expand Down Expand Up @@ -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__']))
Expand All @@ -90,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]
Expand All @@ -116,6 +125,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,
Expand Down