From 316379dd7c1ee6b07a3bdbfac75e51ae30a11d28 Mon Sep 17 00:00:00 2001 From: Marcel Verkerk Date: Thu, 18 Jan 2018 00:47:25 -0700 Subject: [PATCH] fix: print more meaningful error message upon API exception fix: remove redundant config code --- setup.py | 2 +- timingsclient/__init__.py | 14 +++++------ timingsclient/config.py | 52 --------------------------------------- timingsclient/perf.py | 3 ++- 4 files changed, 10 insertions(+), 61 deletions(-) delete mode 100644 timingsclient/config.py diff --git a/setup.py b/setup.py index 29baad5..549b369 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ def required_packages_list(file_name, exclude_version=False): author='GoDaddy Operating Company, LLC', author_email='mverkerk@godaddy.com', license='MIT', - version='1.0.1', + version='1.0.2', install_requires=required_packages_list('requirements.txt'), packages=find_packages( exclude=['*.tests', '*.tests.*', 'tests.*', 'tests'])) diff --git a/timingsclient/__init__.py b/timingsclient/__init__.py index ffd6eec..013727d 100644 --- a/timingsclient/__init__.py +++ b/timingsclient/__init__.py @@ -1,7 +1,7 @@ -""" Init file for timingsclient """ -from __future__ import absolute_import - -from .perf import Perf -from . import config, perf - -__all__ = ['perf', 'config', 'Perf'] +""" Init file for timingsclient """ +from __future__ import absolute_import + +from .perf import Perf +from . import perf + +__all__ = ['perf', 'Perf'] diff --git a/timingsclient/config.py b/timingsclient/config.py deleted file mode 100644 index 8956512..0000000 --- a/timingsclient/config.py +++ /dev/null @@ -1,52 +0,0 @@ -"""Utility to allow user to load the config settings""" -import yaml - -DEFAULT = 'default' - -_CONFIG_MAP = {} - - -def load_config(filespec, name): - """ - Loads the configuration from the file path specified and caches this for - later use by future callers. - To set the default, pass in DEFAULT as the name - :param filespec: The file path to the target configuration file. - :param name: The name to associate with this config. Set to DEFAULT for - default. - :return: The Conf associated with the configuration. - """ - conf = Conf(filespec) - _CONFIG_MAP[name] = conf - return conf - - -def get_config(name=None): - """ - Returns a cached version of the config based on name. When None, returns - the default. - :param name: The name to cache this under. None assumes DEFAULT - :return: The config object associated with the provided name. - :raises: KeyError when the config was not previously loaded. - """ - if name is None: - return _CONFIG_MAP[DEFAULT] - return _CONFIG_MAP[name] - - -class Conf(): - def __init__(self, filespec): - self._filespec = filespec - self._config = self._read_conf(filespec) - - def _read_conf(self, filespec): - with open(filespec, 'r') as stream: - try: - config = yaml.load(stream) - except yaml.YAMLError as exc: - print(exc) - - return config - - def get_filespec(self): - return self._filespec diff --git a/timingsclient/perf.py b/timingsclient/perf.py index 14b30da..96c02f4 100644 --- a/timingsclient/perf.py +++ b/timingsclient/perf.py @@ -104,11 +104,12 @@ def _call_api(self, data, endpoint): json=data, timeout=api_timeout ) if not 200 <= response.status_code <= 299: + print('timingsclient: Unexpected response from API {}'.format(response)) return {'error': "Error: Unexpected response {}".format(response)} return response.json() except requests.exceptions.RequestException as err: - print(err) + print('timingsclient: exception in API request: ' + str(err)) return {'error': err} def _load_conf(self):