Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

dev_settings: Allow user to override settings in a git-ignored file.

Tim Abbotta7c40748fda4
diff --git a/.gitignore b/.gitignore
index 4fef9ac094e..d5c2f2f6992 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,7 @@
/zproject/apns-dev.pem
/zproject/apns-dev-key.p8
/zproject/dev-secrets.conf
+/zproject/custom_dev_settings.py
/tools/conf.ini
/tools/custom_provision
/tools/droplets/conf.ini
diff --git a/docs/subsystems/settings.md b/docs/subsystems/settings.md
index af7301ceb0f..49707c53815 100644
--- a/docs/subsystems/settings.md
+++ b/docs/subsystems/settings.md
@@ -110,6 +110,14 @@ additionally:
You can see a full list with `git grep development_only=True`, or
add additional settings of this form if needed.
+- If you need to override a setting in your development environment,
+ you can do so by creating a `zproject/custom_dev_settings.py`
+ setting the values you'd like to override (the test suites ignore
+ this file). This optional file is processed just after
+ `dev_settings.py` in `configured_settings.py`, so
+ `zproject/computed_settings.py` will correctly use your custom
+ settings when calculating any computed settings that depend on them.
+
- `zproject/test_settings.py` imports everything from
`zproject/settings.py` and `zproject/test_extra_settings.py`.
diff --git a/zproject/configured_settings.py b/zproject/configured_settings.py
index 66037087a85..612f9da28ea 100644
--- a/zproject/configured_settings.py
+++ b/zproject/configured_settings.py
@@ -23,5 +23,21 @@ else:
from .prod_settings_template import * # noqa: F403 isort: skip
from .dev_settings import * # noqa: F403 isort: skip
+ # Support for local overrides to dev_settings.py is implemented here.
+ #
+ # We're careful to avoid those overrides applying to automated tests.
+ if not TEST_SUITE: # nocoverage
+ import contextlib
+
+ with contextlib.suppress(ImportError):
+ from zproject.custom_dev_settings import * # type: ignore[import, unused-ignore] # noqa: F403
+
+ # Print that we've got settings changes, so you know if you're testing non-base code.
+ #
+ # TODO: Figure out how to make this not be printed several
+ # times, and maybe print the actual keys that are
+ # overridden.
+ print("Using custom settings from zproject/custom_dev_settings.py.")
+
# Do not add any code after these wildcard imports! Add it to
# computed_settings instead.