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

Fix cli init command for flask (#705) #774

Merged
merged 2 commits into from
Jul 27, 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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ test_examples:
cd example/issues/722_docs_example;pwd;python app.py
cd example/issues/729_use_default_when_setting_is_blank;pwd;python app.py
cd example/issues/741_envvars_ignored;pwd;sh recreate.sh
cd example/issues/705_flask_dynaconf_init;pwd;make test;make clean

test_vault:
# @cd example/vault;pwd;python write.py
Expand Down
3 changes: 2 additions & 1 deletion dynaconf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ def set_settings(ctx, instance=None):
elif "FLASK_APP" in os.environ: # pragma: no cover
with suppress(ImportError, click.UsageError):
from flask.cli import ScriptInfo # noqa
from dynaconf import FlaskDynaconf

flask_app = ScriptInfo().load_app()
settings = flask_app.config
settings = FlaskDynaconf(flask_app, **flask_app.config).settings
click.echo(
click.style(
"Flask app detected", fg="white", bg="bright_black"
Expand Down
12 changes: 12 additions & 0 deletions example/issues/705_flask_dynaconf_init/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.PHONY: test clean

export FLASK_APP=app:create_app

test: clean
dynaconf init -v test_var
grep '\[development\]' settings.toml

clean:
rm -rf settings.toml
rm -rf .secrets.toml
rm -rf .gitignore
18 changes: 18 additions & 0 deletions example/issues/705_flask_dynaconf_init/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations

from flask import Blueprint
from flask import Flask

blueprint = Blueprint("default", __name__)


@blueprint.route("/")
def index():
return "Default route."


def create_app():
app = Flask(__name__)
app.register_blueprint(blueprint)
app.config["ENV"] = "development"
return app