Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

config file option doesn't work for dotted names #154

Merged
merged 2 commits into from

2 participants

@ulope

Due to the way __import__ works (see fourth paragraph) dotted config package / module names are not correctly imported.

The most robust solution would probably be to switch to using importlib.import_module(). importlib is bundled with python from 2.7 onwards and is available on PyPI for older python versions down to 2.3.

@nvie
Owner

You mean we need to change the implementation of this function? I'm happy to accept a patch for it. Make sure to depend on importlib only if Python < 2.7 in setup.py.

@ulope

Exactly, thats the place.
I'll put up a pull req' later today.

Edit: I just saw that you already have a conditional dependency on importlib for < 2.7. So the pull request will be very short :)

@nvie
Owner

Hah! That must have been a left-over from the past, which I forgot to remove, then :))

@nvie nvie merged commit a543a38 into from
@nvie
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  rq/scripts/__init__.py
@@ -1,3 +1,4 @@
+import importlib
import redis
from rq import use_connection
@@ -19,7 +20,7 @@ def add_standard_arguments(parser):
def read_config_file(module):
"""Reads all UPPERCASE variables defined in the given module file."""
- settings = __import__(module, [], [], [], -1)
+ settings = importlib.import_module(module)
return dict([(k, v)
for k, v in settings.__dict__.items()
if k.upper() == k])
View
1  tests/dummy_settings.py
@@ -0,0 +1 @@
+REDIS_HOST = "testhost.example.com"
View
8 tests/test_scripts.py
@@ -0,0 +1,8 @@
+from unittest import TestCase
+from rq.scripts import read_config_file
+
+class TestScripts(TestCase):
+ def test_config_file(self):
+ settings = read_config_file("tests.dummy_settings")
+ self.assertIn("REDIS_HOST", settings)
+ self.assertEqual(settings['REDIS_HOST'], "testhost.example.com")
Something went wrong with that request. Please try again.