Skip to content

Commit

Permalink
Fix cli init command for flask (#705) (#774)
Browse files Browse the repository at this point in the history
Co-authored-by: Bruno Rocha <rochacbruno@users.noreply.github.com>
  • Loading branch information
obaranov and rochacbruno committed Jul 27, 2022
1 parent df2da01 commit 7bb4e4b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
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
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
@@ -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
@@ -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

0 comments on commit 7bb4e4b

Please sign in to comment.