Skip to content

Commit 86c3fdc

Browse files
committed
Allow to load setting from a non python path
1 parent b13df19 commit 86c3fdc

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

manage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
if __name__ == "__main__":
66
os.environ.setdefault(
77
"DJANGO_SETTINGS_MODULE",
8-
"umap.settings.local"
8+
"umap.settings"
99
)
1010

1111
from django.core.management import execute_from_command_line

umap/settings/__init__.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import imp
2+
import os
3+
import sys
4+
5+
from django.utils.termcolors import colorize
6+
7+
from .base import * # NOQA, default values
8+
9+
# Allow to override setting from any file, may be out of the PYTHONPATH,
10+
# to make it easier for non python people.
11+
path = os.environ.get('UMAP_SETTINGS')
12+
if path:
13+
d = imp.new_module('config')
14+
d.__file__ = path
15+
try:
16+
with open(path) as config_file:
17+
exec(compile(config_file.read(), path, 'exec'), d.__dict__)
18+
except IOError as e:
19+
msg = 'Unable to import {} from UMAP_SETTINGS'.format(path)
20+
print(colorize(msg, fg='red'))
21+
sys.exit(e)
22+
else:
23+
print('Loaded local config from', path)
24+
for key in dir(d):
25+
if key.isupper():
26+
globals()[key] = getattr(d, key)
27+
else:
28+
# Retrocompat
29+
try:
30+
from .local import * # NOQA
31+
except ImportError:
32+
pass

0 commit comments

Comments
 (0)