Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the usage with python -m #710

Merged
merged 4 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ test_examples:
cd example/project_root/;pwd;rm -rf /tmp/dynaconf_project_root_test/settings.py;mkdir -p /tmp/dynaconf_project_root_test/;echo "MESSAGE = 'Hello from tmp'" > /tmp/dynaconf_project_root_test/settings.py;python app.py;rm -rf /tmp/dynaconf_project_root_test/
cd example/settings_file/;pwd;rm -rf /tmp/settings_file_test/settings.py;mkdir -p /tmp/settings_file_test/;echo "MESSAGE = 'Hello from tmp'" > /tmp/settings_file_test/settings.py;python app.py;rm -rf /tmp/settings_file_test/
cd example/configure/;pwd;rm -rf /tmp/configure_test/settings.py;mkdir -p /tmp/configure_test/;echo "MESSAGE = 'Hello from tmp'" > /tmp/configure_test/settings.py;python app.py;rm -rf /tmp/configure_test/
cd example/-m_case/;pwd;python -m module

@echo '############### Calling from outer folder ###############'
python example/common/program.py
Expand Down Expand Up @@ -208,7 +209,7 @@ publish:

clean:
@find ./ -name '*.pyc' -exec rm -f {} \;
@find ./ -name '__pycache__' -exec rm -rf {} \;
@find ./ -name '__pycache__' -prune -exec rm -rf {} \;
@find ./ -name 'Thumbs.db' -exec rm -f {} \;
@find ./ -name '*~' -exec rm -f {} \;
rm -rf .cache
Expand Down
4 changes: 4 additions & 0 deletions docs/settings_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ from dynaconf import Dynaconf
settings = Dynaconf(settings_files=["settings.toml", "/etc/program/foo.yaml"])
```

!!! info
To use `python -m module`, where the module uses dynaconf you will need to
specify your `settings.toml` path, for example, like this: `settings_file="module/config/settings.toml"`.

### settings.toml

In the above example, dynaconf will try to load `settings.toml` from the same
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions example/-m_case/module/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dynaconf import Dynaconf

settings = Dynaconf(
settings_file="module/config/settings.toml",
environments=True,
)


print(settings.WORKS) # noqa


assert "-m_case" == getattr(settings, "WORKS")
2 changes: 2 additions & 0 deletions example/-m_case/module/config/settings.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[default]
works = '-m_case'
2 changes: 1 addition & 1 deletion example/format/.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
USERNAME='robert_plant'
FORMAT_USERNAME='robert_plant'
4 changes: 2 additions & 2 deletions example/format/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from dynaconf import settings

assert settings.get("USERNAME") is None
assert settings.get("FORMAT_USERNAME") is None
assert settings.DATABASE_NAME == "my_database.db"
assert os.environ["USERNAME"] == "robert_plant"
assert os.environ["FORMAT_USERNAME"] == "robert_plant"

DB_PATH = "/home/robert_plant/databases/my_database.db"
assert settings.DATABASE_PATH == DB_PATH, settings.DATABASE_PATH
Expand Down
4 changes: 2 additions & 2 deletions example/format/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
database_name = 'my_database.db'

[development]
database_path = '@format /home/{env[USERNAME]}/databases/{this[database_name]}'
database_path_jinja = '@jinja /home/{{env.USERNAME}}/{{this.current_env | lower}}/{{this["database_name"] }}'
database_path = '@format /home/{env[FORMAT_USERNAME]}/databases/{this[database_name]}'
database_path_jinja = '@jinja /home/{{env.FORMAT_USERNAME}}/{{this.current_env | lower}}/{{this["database_name"] }}'