Skip to content

Commit

Permalink
Fix runtime version (#67)
Browse files Browse the repository at this point in the history
* Fix runtime version

* Use logging instead of warning

* Filter warnings from setuptools_scm

* better warning

Co-authored-by: Konstantinos Kavvadias <kavvkon@gmail.com>
  • Loading branch information
corralien and kavvkon committed Feb 21, 2020
1 parent 4cc0681 commit 60bca26
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions dispaset/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import logging.config
import os

# Sets the __version__ variable
from .common import commons

try:
from setuptools_scm import get_version
version = get_version(version_scheme='post-release',
local_scheme=lambda version: version.format_choice("" if version.exact else "+{node}", "+dirty"),
root='..', relative_to=__file__)
except (ImportError, LookupError):
import pkg_resources
version = pkg_resources.get_distribution(__package__).version
__version__ = version

# Logging: # TODO: Parametrize in dispacli or external config
_LOGCONFIG = {
"version": 1,
Expand Down Expand Up @@ -53,6 +42,34 @@
}
}

# Setting logging configuration:
try:
logging.config.dictConfig(_LOGCONFIG)
except Exception:
# if it didn't work, it might be due to ipython messing with the output
# typical error: Unable to configure handler 'console': IOStream has no fileno
# try without console output:
print('WARNING: the colored console output is failing (possibly because of ipython). Switching to monochromatic output')
_LOGCONFIG['handlers']['console']['class'] = "logging.StreamHandler"
logging.config.dictConfig(_LOGCONFIG)

# Sets the __version__ variable
try:
from setuptools_scm import get_version
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
version = get_version(version_scheme='post-release',
local_scheme=lambda version: version.format_choice("" if version.exact else "+{node}", "+dirty"),
root='..', relative_to=__file__)
except (ImportError, LookupError):
try:
from pkg_resources import get_distribution, DistributionNotFound
version = get_distribution(__package__).version
except DistributionNotFound:
logging.warning("Unable to detect version, most probably because you did not install it properly. To avoid further errors, please install it by running 'pip install -e .'.")
version = 'N/A'
__version__ = version

# Importing the main Dispa-SET functions so that they can be called with "ds.function"
from .preprocessing.data_handler import load_config_excel, load_config_yaml, load_config, export_yaml_config
Expand All @@ -73,14 +90,3 @@
os.remove(filename)
except OSError:
print ('Could not erase previous log file ' + filename)

# Setting logging configuration:
try:
logging.config.dictConfig(_LOGCONFIG)
except Exception:
# if it didn't work, it might be due to ipython messing with the output
# typical error: Unable to configure handler 'console': IOStream has no fileno
# try without console output:
print('WARNING: the colored console output is failing (possibly because of ipython). Switching to monochromatic output')
_LOGCONFIG['handlers']['console']['class'] = "logging.StreamHandler"
logging.config.dictConfig(_LOGCONFIG)

0 comments on commit 60bca26

Please sign in to comment.