From a7c40748fda4309d5b334458d8c53c7b8e738840 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Sun, 3 Dec 2023 21:17:53 -0800 Subject: [PATCH] dev_settings: Allow user to override settings in a git-ignored file. This should make doing an ongoing development project related to a settings variant significantly more convenient. --- .gitignore | 1 + docs/subsystems/settings.md | 8 ++++++++ zproject/configured_settings.py | 16 ++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/.gitignore b/.gitignore index 4fef9ac094..d5c2f2f699 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 af7301ceb0..49707c5381 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 66037087a8..612f9da28e 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.