From 90f37d9ec59b757718fb7ece9ff363ae72edbf88 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Thu, 16 Jan 2025 15:40:01 -0500 Subject: [PATCH] docs: Add some more docs for how to use derived_settings. This was a little hard to grok so I added a little example to make it easier to understand. --- openedx/core/lib/derived.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/openedx/core/lib/derived.py b/openedx/core/lib/derived.py index a62731ef5432..47e191614fee 100644 --- a/openedx/core/lib/derived.py +++ b/openedx/core/lib/derived.py @@ -3,6 +3,30 @@ via callable methods/lambdas. The derivation time can be controlled to happen after all other settings have been set. The derived setting can also be overridden by setting the derived setting to an actual value. + +Example + +In `lms/envs/common.py`: + +``` +# Double some other value that might get set later. +VALUE = lambda settings: settings.SOME_OTHER_VALUE * 2 +# Register this value as one that needs to be derived later. +derived(VALUE) +``` + +Later in a settings file that depends on common.py + +``` +from lms.envs.common * + +# Set some other value however you want. +SOME_OTHER_VALUE = 4 + +# Derive any settings and pass them this settings file for reference. +# This will update VALUE so that it is the scaler `8` instead of a lambda. +derive_settings(__name__) +``` """ import sys