diff options
| author | jason | 2018-07-18 14:00:27 -0600 |
|---|---|---|
| committer | jason | 2018-07-18 14:02:56 -0600 |
| commit | d4ee6d1abb525ea96b08e45daa873ef2a4591798 (patch) | |
| tree | f7b52c41764f70c75c6a974576f95d40506030d0 | |
| parent | 3a01685a8e800d567ce2f97e9e34705d0209ab17 (diff) | |
| download | eventmq-d4ee6d1abb525ea96b08e45daa873ef2a4591798.tar.gz eventmq-d4ee6d1abb525ea96b08e45daa873ef2a4591798.zip | |
Fix bug not allowing env vars to be used without a config file
| -rw-r--r-- | eventmq/__init__.py | 2 | ||||
| -rw-r--r-- | eventmq/utils/settings.py | 74 | ||||
| -rw-r--r-- | 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 @@ | |||
| 1 | __author__ = 'EventMQ Contributors' | 1 | __author__ = 'EventMQ Contributors' |
| 2 | __version__ = '0.3.8' | 2 | __version__ = '0.3.9' |
| 3 | 3 | ||
| 4 | PROTOCOL_VERSION = 'eMQP/1.0' | 4 | PROTOCOL_VERSION = 'eMQP/1.0' |
| 5 | 5 | ||
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'): | |||
| 51 | 'Tried to read nonexistent section {} from {}'.format( | 51 | 'Tried to read nonexistent section {} from {}'.format( |
| 52 | section, config_path)) | 52 | section, config_path)) |
| 53 | 53 | ||
| 54 | for name in dir(conf): | 54 | for name in dir(conf): |
| 55 | if name.startswith('_'): | 55 | if name.startswith('_'): |
| 56 | continue | 56 | continue |
| 57 | 57 | ||
| 58 | value = None | 58 | value = None |
| 59 | found_value = False | 59 | found_value = False |
| 60 | default_value = getattr(conf, name) | 60 | default_value = getattr(conf, name) |
| 61 | 61 | ||
| 62 | # Favor environment variables over the config file definition | 62 | # Favor environment variables over the config file definition |
| 63 | try: | 63 | try: |
| 64 | value = os.environ['EVENTMQ_{}'.format(name)] | 64 | value = os.environ['EVENTMQ_{}'.format(name)] |
| 65 | found_value = True | 65 | found_value = True |
| 66 | except KeyError: | 66 | except KeyError: |
| 67 | if use_config_file: | 67 | if use_config_file: |
| 68 | try: | 68 | try: |
| 69 | value = config.get(section, name) | 69 | value = config.get(section, name) |
| 70 | found_value = True | 70 | found_value = True |
| 71 | except NoOptionError: | 71 | except NoOptionError: |
| 72 | found_value = False | 72 | found_value = False |
| 73 | 73 | ||
| 74 | if found_value: | 74 | if found_value: |
| 75 | t = type(getattr(conf, name)) | 75 | t = type(getattr(conf, name)) |
| 76 | 76 | ||
| 77 | if t in (list, tuple): | 77 | if t in (list, tuple): |
| 78 | try: | 78 | try: |
| 79 | value = t(json.loads(value)) | 79 | value = t(json.loads(value)) |
| 80 | except ValueError: | 80 | except ValueError: |
| 81 | raise ValueError( | 81 | raise ValueError( |
| 82 | "Invalid JSON syntax for {} setting".format(name)) | 82 | "Invalid JSON syntax for {} setting".format(name)) |
| 83 | # json.loads coverts all arrays to lists, but if the first | 83 | # json.loads coverts all arrays to lists, but if the first |
| 84 | # element in the default is a tuple (like in QUEUES) then | 84 | # element in the default is a tuple (like in QUEUES) then |
| 85 | # convert those elements, otherwise whatever it's type is | 85 | # convert those elements, otherwise whatever it's type is |
| 86 | # correct | 86 | # correct |
| 87 | if isinstance(default_value[0], tuple): | 87 | if isinstance(default_value[0], tuple): |
| 88 | setattr(conf, name, t(map(tuplify, value))) | 88 | setattr(conf, name, t(map(tuplify, value))) |
| 89 | else: | ||
| 90 | setattr(conf, name, t(value)) | ||
| 91 | elif isinstance(default_value, bool): | ||
| 92 | setattr(conf, name, | ||
| 93 | True if 't' in value.lower() else False) | ||
| 94 | else: | 89 | else: |
| 95 | setattr(conf, name, t(value)) | 90 | setattr(conf, name, t(value)) |
| 91 | elif isinstance(default_value, bool): | ||
| 92 | setattr(conf, name, | ||
| 93 | True if 't' in value.lower() else False) | ||
| 94 | else: | ||
| 95 | setattr(conf, name, t(value)) | ||
| 96 | 96 | ||
| 97 | logger.debug("Setting conf.{} to {}".format( | 97 | logger.debug("Setting conf.{} to {}".format( |
| 98 | name, getattr(conf, name))) | 98 | name, getattr(conf, name))) |
| @@ -2,12 +2,20 @@ | |||
| 2 | EventMQ setup.py file for distribution | 2 | EventMQ setup.py file for distribution |
| 3 | 3 | ||
| 4 | """ | 4 | """ |
| 5 | import ast | ||
| 5 | 6 | ||
| 6 | from setuptools import find_packages, setup | 7 | from setuptools import find_packages, setup |
| 7 | 8 | ||
| 9 | version = 'unknown' | ||
| 10 | with open('eventmq/__init__.py') as f: | ||
| 11 | for line in f: | ||
| 12 | if line.startswith('__version__'): | ||
| 13 | version = ast.parse(line).body[0].value.s | ||
| 14 | break | ||
| 15 | |||
| 8 | setup( | 16 | setup( |
| 9 | name='eventmq', | 17 | name='eventmq', |
| 10 | version='0.3.8', | 18 | version=version, |
| 11 | description='EventMQ job execution and messaging system based on ZeroMQ', | 19 | description='EventMQ job execution and messaging system based on ZeroMQ', |
| 12 | packages=find_packages(), | 20 | packages=find_packages(), |
| 13 | install_requires=['pyzmq==15.4.0', | 21 | install_requires=['pyzmq==15.4.0', |