Skip to content

Commit 261f8ee

Browse files
committed
Allow loading settings from outside of the postgresqleu module
To ease building docker images and prevent having to maintain an in-tree file for local settings, allow a pgeu_system_global_settings module anywhere in the PYTHONPATH for configuration. In addition, also allow overrides to be applied after loading the skin through a pgeu_system_override_settings module in PYTHONPATH.
1 parent e487d96 commit 261f8ee

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

postgresqleu/settings.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,24 @@
303303
# be used instead of TCP.
304304
MEETINGS_STATUS_BASE_URL = None
305305

306-
# If there is a local_settings.py, let it override our settings
306+
# First, attempt to load settings from a pgeu_system_settings module
307+
# available somewhere in the PYTHONPATH.
307308
try:
308-
from .local_settings import *
309+
from pgeu_system_global_settings import *
309310
except ImportError as e:
310311
pass
312+
# Next, give the local_settings.py from the postgresqleu tree a chance
313+
# to provide configuration.
314+
try:
315+
from .local_settings import *
316+
except ImportError as e:
317+
# If there's no local_settings.py within the postgresqleu tree, check
318+
# for a globally available pgeu_system_settings module in any configured
319+
# PYTHONPATH.
320+
try:
321+
from pgeu_system_settings import *
322+
except ImportError as e:
323+
pass
311324

312325
PRELOAD_URLS = []
313326
if 'SYSTEM_SKIN_DIRECTORY' in globals():
@@ -334,6 +347,12 @@
334347
else:
335348
HAS_SKIN = False
336349

350+
# Try to load overrides from PYTHONPATH. This allows overriding skin
351+
# settings for testing purposes.
352+
try:
353+
from pgeu_system_override_settings import *
354+
except ImportError as e:
355+
pass
337356

338357
if not SECRET_KEY:
339358
raise Exception("SECRET_KEY must be configured!")

tools/devsetup/README.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
Configuration
2+
-------------
3+
4+
The traditional approach is to create a local_settings.py file under
5+
the postgresqleu directory, a template is provided.
6+
7+
To allow out-of-module configuration, it is possible to instead
8+
provide a python module pgeu_system_global_settings and extend
9+
PYTHONPATH for it to be detected. Settings in there are loaded first,
10+
in case the above mentioned local_settings.py is available, too, it
11+
will override global settings.
12+
13+
The skin usually provides skin_settings.py and allows customization
14+
through a similar skin_local_settings.py. These again take precedence
15+
over global settings.
16+
17+
Last, a global python module pgeu_system_override_settings is
18+
attempted to be loaded. It allows overriding any settings of the
19+
pgeu-system or the skin.
20+
21+
122
Dependencies needed before running
223
----------------------------------
324

tools/devsetup/dev_setup.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ EOF
3333
chmod +x ../../python
3434
../../python -m pip install -r dev_requirements.txt
3535

36-
cd ../..
37-
cat > postgresqleu/local_settings.py <<EOF
36+
# Configure the test instance. This is done through the traditional
37+
# approach with local_settings.py here. An alternative would be to
38+
# write the very same content to
39+
# venv_dev/lib/python3.11/site-packages/pgeu_system_global_settings.py
40+
cat > ../../postgresqleu/local_settings.py <<EOF
3841
DEBUG=True
3942
DISABLE_HTTPS_REDIRECTS=True
4043
DATABASES={
@@ -53,6 +56,8 @@ CSRF_COOKIE_SECURE=False
5356
SITEBASE="http://localhost:8012/"
5457
EOF
5558

59+
# Switch back to the top level directory and initialize the database.
60+
cd ../..
5661
./python manage.py migrate
5762

5863
cat tools/devsetup/devserver-uwsgi.ini.tmpl | sed -e "s#%DJANGO%#$(pwd)/tools/devsetup/venv_dev#g" > devserver-uwsgi.ini

0 commit comments

Comments
 (0)