Skip to content

Commit

Permalink
docs: Add some more docs for how to use derived_settings.
Browse files Browse the repository at this point in the history
This was a little hard to grok so I added a little example to make it
easier to understand.
  • Loading branch information
feanil committed Jan 16, 2025
1 parent eeaa646 commit 3da7044
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions openedx/core/lib/derived.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3da7044

Please sign in to comment.