Skip to content

Commit

Permalink
Fix bug not allowing env vars to be used without a config file
Browse files Browse the repository at this point in the history
  • Loading branch information
com4 committed Jul 18, 2018
1 parent 3a01685 commit d4ee6d1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
2 changes: 1 addition & 1 deletion eventmq/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = 'EventMQ Contributors'
__version__ = '0.3.8'
__version__ = '0.3.9'

PROTOCOL_VERSION = 'eMQP/1.0'

Expand Down
74 changes: 37 additions & 37 deletions eventmq/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit d4ee6d1

Please sign in to comment.