From d4ee6d1abb525ea96b08e45daa873ef2a4591798 Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 18 Jul 2018 14:00:27 -0600 Subject: Fix bug not allowing env vars to be used without a config file --- eventmq/__init__.py | 2 +- eventmq/utils/settings.py | 74 +++++++++++++++++++++++------------------------ setup.py | 10 ++++++- 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/eventmq/__init__.py b/eventmq/__init__.py index ed64a39..4143854 100644 --- a/eventmq/__init__.py +++ b/eventmq/__init__.py @@ -1,5 +1,5 @@ __author__ = 'EventMQ Contributors' -__version__ = '0.3.8' +__version__ = '0.3.9' PROTOCOL_VERSION = 'eMQP/1.0' diff --git a/eventmq/utils/settings.py b/eventmq/utils/settings.py index 9365bff..3999e39 100644 --- a/eventmq/utils/settings.py +++ b/eventmq/utils/settings.py @@ -51,48 +51,48 @@ def import_settings(section='global'): 'Tried to read nonexistent section {} from {}'.format( section, config_path)) - for name in dir(conf): - if name.startswith('_'): - continue + for name in dir(conf): + if name.startswith('_'): + continue - value = None - found_value = False - default_value = getattr(conf, name) + value = None + found_value = False + default_value = getattr(conf, name) - # Favor environment variables over the config file definition - try: - value = os.environ['EVENTMQ_{}'.format(name)] - found_value = True - except KeyError: - if use_config_file: - try: - value = config.get(section, name) - found_value = True - except NoOptionError: - found_value = False + # Favor environment variables over the config file definition + try: + value = os.environ['EVENTMQ_{}'.format(name)] + found_value = True + except KeyError: + if use_config_file: + try: + value = config.get(section, name) + found_value = True + except NoOptionError: + found_value = False - if found_value: - t = type(getattr(conf, name)) + if found_value: + t = type(getattr(conf, name)) - if t in (list, tuple): - try: - value = t(json.loads(value)) - except ValueError: - raise ValueError( - "Invalid JSON syntax for {} setting".format(name)) - # json.loads coverts all arrays to lists, but if the first - # element in the default is a tuple (like in QUEUES) then - # convert those elements, otherwise whatever it's type is - # correct - if isinstance(default_value[0], tuple): - setattr(conf, name, t(map(tuplify, value))) - else: - setattr(conf, name, t(value)) - elif isinstance(default_value, bool): - setattr(conf, name, - True if 't' in value.lower() else False) + if t in (list, tuple): + try: + value = t(json.loads(value)) + except ValueError: + raise ValueError( + "Invalid JSON syntax for {} setting".format(name)) + # json.loads coverts all arrays to lists, but if the first + # element in the default is a tuple (like in QUEUES) then + # convert those elements, otherwise whatever it's type is + # correct + if isinstance(default_value[0], tuple): + setattr(conf, name, t(map(tuplify, value))) else: setattr(conf, name, t(value)) + elif isinstance(default_value, bool): + setattr(conf, name, + True if 't' in value.lower() else False) + else: + setattr(conf, name, t(value)) - logger.debug("Setting conf.{} to {}".format( + logger.debug("Setting conf.{} to {}".format( name, getattr(conf, name))) diff --git a/setup.py b/setup.py index 741a517..1427d67 100644 --- a/setup.py +++ b/setup.py @@ -2,12 +2,20 @@ EventMQ setup.py file for distribution """ +import ast from setuptools import find_packages, setup +version = 'unknown' +with open('eventmq/__init__.py') as f: + for line in f: + if line.startswith('__version__'): + version = ast.parse(line).body[0].value.s + break + setup( name='eventmq', - version='0.3.8', + version=version, description='EventMQ job execution and messaging system based on ZeroMQ', packages=find_packages(), install_requires=['pyzmq==15.4.0', -- cgit v1.2.1