summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Wanner2024-11-24 17:40:58 +0000
committerMagnus Hagander2025-10-07 19:45:44 +0000
commit5232fad84ceafcd7dc16247e096c7f4815527c6e (patch)
treea49dece33283805350cb6e5669917029e945ac49
parenta8b8612324a5ed2e81e1c68ce4c536d3a25300e4 (diff)
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.
-rw-r--r--postgresqleu/settings.py23
-rw-r--r--tools/devsetup/README.txt21
-rwxr-xr-xtools/devsetup/dev_setup.sh4
3 files changed, 46 insertions, 2 deletions
diff --git a/postgresqleu/settings.py b/postgresqleu/settings.py
index 0b7996ec..c1a26cae 100644
--- a/postgresqleu/settings.py
+++ b/postgresqleu/settings.py
@@ -303,11 +303,24 @@ MEETINGS_WS_BASE_URL = None
# be used instead of TCP.
MEETINGS_STATUS_BASE_URL = None
-# If there is a local_settings.py, let it override our settings
+# First, attempt to load settings from a pgeu_system_settings module
+# available somewhere in the PYTHONPATH.
try:
- from .local_settings import *
+ from pgeu_system_global_settings import *
except ImportError as e:
pass
+# Next, give the local_settings.py from the postgresqleu tree a chance
+# to provide configuration.
+try:
+ from .local_settings import *
+except ImportError as e:
+ # If there's no local_settings.py within the postgresqleu tree, check
+ # for a globally available pgeu_system_settings module in any configured
+ # PYTHONPATH.
+ try:
+ from pgeu_system_settings import *
+ except ImportError as e:
+ pass
PRELOAD_URLS = []
if 'SYSTEM_SKIN_DIRECTORY' in globals():
@@ -334,6 +347,12 @@ if 'SYSTEM_SKIN_DIRECTORY' in globals():
else:
HAS_SKIN = False
+# Try to load overrides from PYTHONPATH. This allows overriding skin
+# settings for testing purposes.
+try:
+ from pgeu_system_override_settings import *
+except ImportError as e:
+ pass
if not SECRET_KEY:
raise Exception("SECRET_KEY must be configured!")
diff --git a/tools/devsetup/README.txt b/tools/devsetup/README.txt
index 57f4d94e..733a570f 100644
--- a/tools/devsetup/README.txt
+++ b/tools/devsetup/README.txt
@@ -1,3 +1,24 @@
+Configuration
+-------------
+
+The traditional approach is to create a local_settings.py file under
+the postgresqleu directory, a template is provided.
+
+To allow out-of-module configuration, it is possible to instead
+provide a python module pgeu_system_global_settings and extend
+PYTHONPATH for it to be detected. Settings in there are loaded first,
+in case the above mentioned local_settings.py is available, too, it
+will override global settings.
+
+The skin usually provides skin_settings.py and allows customization
+through a similar skin_local_settings.py. These again take precedence
+over global settings.
+
+Last, a global python module pgeu_system_override_settings is
+attempted to be loaded. It allows overriding any settings of the
+pgeu-system or the skin.
+
+
Dependencies needed before running
----------------------------------
diff --git a/tools/devsetup/dev_setup.sh b/tools/devsetup/dev_setup.sh
index de104b95..3802a859 100755
--- a/tools/devsetup/dev_setup.sh
+++ b/tools/devsetup/dev_setup.sh
@@ -33,6 +33,10 @@ EOF
chmod +x ../../python
../../python -m pip install -r dev_requirements.txt
+# Configure the test instance. This is done through the traditional
+# approach with local_settings.py here. An alternative would be to
+# write the very same content to
+# venv_dev/lib/python3.11/site-packages/pgeu_system_global_settings.py
cd ../..
cat > postgresqleu/local_settings.py <<EOF
DEBUG=True