Conversation
✅ Deploy Preview for dynaconf ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## master #939 +/- ##
==========================================
- Coverage 99.89% 99.79% -0.10%
==========================================
Files 21 22 +1
Lines 1844 1976 +132
==========================================
+ Hits 1842 1972 +130
- Misses 2 4 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
Dynaconf $ dynaconf inspect --help
Usage: dynaconf inspect [OPTIONS]
Inspect the current value and loading history for settings.
Options:
-k, --key TEXT Filters a single key
-e, --env string filter by environement. Eg: development
-f, --format string output format: json, yaml, table (default: table)
"table": prints the output to stdout
--help Show this message and exit.$ dynaconf inspect -k foo -f json
{
"current": ...,
"history": ...,
}To save a file users can pipe the results or redirect stdout dynaconf inspect -k foo -f json | jq
dynaconf inspect -k foo -f json > file.json
Programmatically the
import inspectSo it is better to rename from dynaconf.utils import inspect_settings
data = inspect_settings(settings) # a full dict with all keys included
foo_data = inspect_settings(settings, "foo") # a full dict with only "foo" history |
|
@rochacbruno what does the "table" format means exactly? Could you provide a snippet of how the following should be rendered? header:
filters:
env: None
key: foo
history_ordering: ascending
active_value: from_environ
history:
- loader: yaml
identifier: /tmp/pytest-of-pedro-psb/pytest-84/test_inspect_print_key0/a.yaml
env: default
merged: false
value:
FOO: from_yaml |
|
Hey @pedro-psb it is just a printed output that can be read in the terminal, in future we can use rich.Table but for now it is enough to just print data, so I think you can just by default output the YAML format directly to the stdout. |
|
On I am not sure it is easy to detect if a variable is a secret, maybe we can by detecting the source being .secrets. or vault. |
|
I guess it would be good to star them out, as someone may want to share this report or something. Not very likely, but this should be easy to do by tracking |
|
Does not work with a custom loader dynaconf on feature/inspect [$] via 🐍 v3.8.13 (.venv)
❯ cd tests_functional/custom_loader
dynaconf/tests_functional/custom_loader on feature/inspect [$] via 🐍 v3.8.13 (.venv)
❯ cat settings.sff
# Stupid File Format
KEYS:name;email;message
VALUES:Bruno Rocha;bruno@rocha.com;Dont use this sff format!
dynaconf/tests_functional/custom_loader on feature/inspect [$] via 🐍 v3.8.13 (.venv)
❯ dynaconf -i app.settings list -k NAME
Working in development environment
NAME<str> 'Bruno Rocha'
dynaconf/tests_functional/custom_loader on feature/inspect [$] via 🐍 v3.8.13 (.venv) 621ms
❯ dynaconf -i app.settings inspect -k NAME
The requested key was not found: 'NAME'
|
@rochacbruno I've cheked the example at # tests_functional/custom_loader/my_custom_loader/sff_loader.py:load
+ source_metadata = SourceMetadata('sff', found_file, env)
if key:
value = data.get(key.lower()) # sff format have lower case keys
+ obj.set(key, value, loader_identifier=source_metadata)
- obj.set(key, value)
else:
+ obj.update(data, loader_identifier=source_metadata)
- obj.update(data)We could:
What do you think? |
|
I think we need to update the docs and test to support history, there are projects out there using custom loaders based on the docs example, so we can point people on how to adjust their loaders to save history. |
rochacbruno
left a comment
There was a problem hiding this comment.
🚀 lets merge it! awesome work!
- write dump() function to yaml_loader
1d51475 to
5d073e2
Compare
Shortlog of commits since last release:
Bruno Rocha (4):
Ignore docs build without a tag
Cancel any running CI job when a Push is made to an existing PR or branch (dynaconf#952)
Fix dynaconf#959 cli get will exit code 1 in case of KeyError. (dynaconf#960)
add tech preview note to inspect docs (dynaconf#961)
Pedro Pessoa (9):
Docs - Update envvar.md custom token e.g. to use add_converter (dynaconf#941)
Feature - Inspect and CLI (dynaconf#939)
Fix - Template substitution with variable update (dynaconf#944)
Assert dynaconf#658 works (dynaconf#945)
fix infinite recursions in special case of django app dynaconf#867 (dynaconf#947)
Fix - Django functions with `add_converter` (dynaconf#951)
Fix hooks not re-running on reload dynaconf#850 (dynaconf#953)
update vault and redis warning recommendations. fix dynaconf#950 (dynaconf#954)
Fix - Enable merge equal False (dynaconf#957)
Shortlog of commits since last release:
Bruno Rocha (5):
Ignore docs build without a tag
Cancel any running CI job when a Push is made to an existing PR or branch (#952)
Fix #959 cli get will exit code 1 in case of KeyError. (#960)
add tech preview note to inspect docs (#961)
Build docs
Hugo Prudente (1):
Doc advanced usage for cli overrides dynaconf settings fix #967 (#970)
Marian Ganisin (1):
Feat: Support for multidoc yaml files (#825)
Pedro Pessoa (11):
Docs - Update envvar.md custom token e.g. to use add_converter (#941)
Feature - Inspect and CLI (#939)
Fix - Template substitution with variable update (#944)
Assert #658 works (#945)
fix infinite recursions in special case of django app #867 (#947)
Fix - Django functions with `add_converter` (#951)
Fix hooks not re-running on reload #850 (#953)
update vault and redis warning recommendations. fix #950 (#954)
Fix - Enable merge equal False (#957)
CI - Test docker-compose pyyaml issue (#964)
Fix: unexpected _bypass_evaluation in BoxList (#966)
pedro-psb (1):
Release version 3.2.0
Inspect functionality (related to #837).
The goal is to provide a way for the users to visualize the "loading-history" of any config key-path.
Changes
Settings._loaded_by_loaderskey type fromstrtoSourceMetadata<NamedTuple>to store more data about each load, namely:loader: the loader type (envvar_global, yaml, redis, vault..)identifier: a loader identifier (eg, for file types it is the filename), for other it may beunique.env: the env in which the data was loadedmerged: if the data was processed with some merge operation.loader_identifierformat (str) with the new one (SourceMetadata) in most data-loading processes (calls toset).inspect_setting(dumping) andget_history(direct access to python data).inspect, which basically portsinspect_settingsto CLI.Tasks
loaded_by_loaders(dict[str, dict]) won't be kept, unless someone requestsDynaBoxandBoxListinto regulardict|list(for pretty-dumping)inspect_settingsand CLI)Related ideas:
vault,.secrets, any other?)inspect_settingsenv filter will always include values fromdefaultenv in active_value. It would be better to filter those out fromactive_valuetoo.inspect_settings(overwriteflag param)Report.envspecific file identifier (it is loaded asenv_global).Sample output
CLI usage
#939 (comment)
Obs
SourceMetadatashould use more memory than the previous one, because it stores all data from all sources. It may be worth taking a look into that.get_history: envs that are no built-in names (default, development, global) won't be loaded if it is not the current env. Eg, a value from envproductionwon't show in history unlessproductionis the current env or is activated (withsettings.from_envor similar). This is because of how env loading works.Testing
Current tests: