Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/detect casting comb token from converters (#784)
- Loading branch information
1 parent
078aaef
commit 5297d07
Showing
3 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
from dynaconf import Dynaconf | ||
from dynaconf.utils import parse_conf | ||
|
||
settings = Dynaconf( | ||
envvar_prefix="DYNACONF", | ||
settings_files=["settings.toml"], | ||
environments=True, | ||
) | ||
|
||
# Add a custom casting token casting string to pathlib.Path object | ||
parse_conf.converters["@path"] = ( | ||
lambda value: value.set_casting(Path) | ||
if isinstance(value, parse_conf.Lazy) | ||
else Path(value) | ||
) | ||
|
||
assert isinstance(settings.parent, Path) | ||
assert isinstance(settings.child, Path) | ||
assert str(settings.child).find("@format") == -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[default] | ||
parent = "@path @format {env[HOME]}/parent" | ||
child = "@path @format {this.parent}/child" |