-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
Flask App factory PR #1 #8418
Flask App factory PR #1 #8418
Changes from 3 commits
56e6c1a
21e3494
be37d24
9d31fff
259a307
9f8fe89
89bba87
fb9cf33
01aafb5
9bf6333
db25d4d
0ab9f0a
921c285
095529f
428655b
97e4cda
9f686cd
f1318d5
947622b
91a39f5
f675ad4
78990d1
7e37cef
3b95e96
7f1dadc
01607c4
3a66b07
5764936
74cd1bf
8d53bd7
037cb2c
3c0d7da
c3c480d
90a25f2
d8e74a2
55d5c27
92e7922
798d723
b943d68
ab7a69c
f72438a
b30ff82
b333044
a9ecc7a
ccd0338
03a3e4a
cf0dac2
d2f4ada
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,7 @@ def post_init(self) -> None: | |
pass | ||
|
||
def configure_celery(self) -> None: | ||
celery_app.config_from_object(self.config.get("CELERY_CONFIG")) | ||
celery_app.config_from_object(self.config["CELERY_CONFIG"]) | ||
celery_app.set_default() | ||
|
||
def init_views(self) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we simply make all our views blueprints and register them accordingly? This may simplify things in the future and/or reduce the cyclical dependency issues we often run into. We (Airbnb) have found the model of using blueprints for everything has worked quite successfully and the Flask app really just glues everything together in a somewhat lightweight fashion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, definitely. I want to pull up all occurrences of things like Again, this PR was intended to be the first step in chipping away at this pattern migration. Thoughts on going for it?? @mistercrunch ?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure that FAB's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yap, it's |
||
|
@@ -112,7 +112,7 @@ def init_app_in_ctx(self) -> None: | |
|
||
# Hook that provides administrators a handle on the Flask APP | ||
# after initialization | ||
flask_app_mutator = self.config.get("FLASK_APP_MUTATOR") | ||
flask_app_mutator = self.config["FLASK_APP_MUTATOR"] | ||
if flask_app_mutator: | ||
flask_app_mutator(self.flask_app) | ||
|
||
|
@@ -155,8 +155,8 @@ def setup_event_logger(self): | |
|
||
def configure_data_sources(self): | ||
# Registering sources | ||
module_datasource_map = self.config.get("DEFAULT_MODULE_DS_MAP") | ||
module_datasource_map.update(self.config.get("ADDITIONAL_MODULE_DS_MAP")) | ||
module_datasource_map = self.config["DEFAULT_MODULE_DS_MAP"] | ||
module_datasource_map.update(self.config["ADDITIONAL_MODULE_DS_MAP"]) | ||
ConnectorRegistry.register_sources(module_datasource_map) | ||
|
||
def configure_cache(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like the cookie-cutter example one could have a method which registers all extensions. |
||
|
@@ -167,10 +167,10 @@ def configure_feature_flags(self): | |
feature_flag_manager.init_app(self.flask_app) | ||
|
||
def configure_fab(self): | ||
if self.config.get("SILENCE_FAB"): | ||
if self.config["SILENCE_FAB"]: | ||
logging.getLogger("flask_appbuilder").setLevel(logging.ERROR) | ||
|
||
custom_sm = self.config.get("CUSTOM_SECURITY_MANAGER") or SupersetSecurityManager | ||
custom_sm = self.config["CUSTOM_SECURITY_MANAGER"] or SupersetSecurityManager | ||
if not issubclass(custom_sm, SupersetSecurityManager): | ||
raise Exception( | ||
"""Your CUSTOM_SECURITY_MANAGER must now extend SupersetSecurityManager, | ||
|
@@ -185,17 +185,17 @@ def configure_fab(self): | |
appbuilder.init_app(self.flask_app, db.session) | ||
|
||
def configure_middlewares(self): | ||
if self.config.get("ENABLE_CORS"): | ||
if self.config["ENABLE_CORS"]: | ||
from flask_cors import CORS | ||
|
||
CORS(self.flask_app, **self.config.get("CORS_OPTIONS")) | ||
CORS(self.flask_app, **self.config["CORS_OPTIONS"]) | ||
|
||
if self.config.get("ENABLE_PROXY_FIX"): | ||
if self.config["ENABLE_PROXY_FIX"]: | ||
from werkzeug.middleware.proxy_fix import ProxyFix | ||
|
||
self.flask_app.wsgi_app = ProxyFix(self.flask_app.wsgi_app, **self.config.get("PROXY_FIX_CONFIG")) | ||
self.flask_app.wsgi_app = ProxyFix(self.flask_app.wsgi_app, **self.config["PROXY_FIX_CONFIG"]) | ||
|
||
if self.config.get("ENABLE_CHUNK_ENCODING"): | ||
if self.config["ENABLE_CHUNK_ENCODING"]: | ||
|
||
class ChunkedEncodingFix(object): | ||
def __init__(self, app): | ||
|
@@ -210,17 +210,17 @@ def __call__(self, environ, start_response): | |
|
||
self.flask_app.wsgi_app = ChunkedEncodingFix(self.flask_app.wsgi_app) | ||
|
||
if self.config.get("UPLOAD_FOLDER"): | ||
if self.config["UPLOAD_FOLDER"]: | ||
try: | ||
os.makedirs(self.config.get("UPLOAD_FOLDER")) | ||
os.makedirs(self.config["UPLOAD_FOLDER"]) | ||
except OSError: | ||
pass | ||
|
||
for middleware in self.config.get("ADDITIONAL_MIDDLEWARE"): | ||
for middleware in self.config["ADDITIONAL_MIDDLEWARE"]: | ||
self.flask_app.wsgi_app = middleware(self.flask_app.wsgi_app) | ||
|
||
# Flask-Compress | ||
if self.config.get("ENABLE_FLASK_COMPRESS"): | ||
if self.config["ENABLE_FLASK_COMPRESS"]: | ||
Compress(self.flask_app) | ||
|
||
if self.config["TALISMAN_ENABLED"]: | ||
|
@@ -240,14 +240,14 @@ def setup_db(self): | |
migrate.init_app(self.flask_app, db=db, directory=APP_DIR + "/migrations") | ||
|
||
def configure_wtf(self): | ||
if self.config.get("WTF_CSRF_ENABLED"): | ||
if self.config["WTF_CSRF_ENABLED"]: | ||
csrf = CSRFProtect(self.flask_app) | ||
csrf_exempt_list = self.config.get("WTF_CSRF_EXEMPT_LIST", []) | ||
craig-rueda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for ex in csrf_exempt_list: | ||
csrf.exempt(ex) | ||
|
||
def register_blueprints(self): | ||
for bp in self.config.get("BLUEPRINTS"): | ||
for bp in self.config["BLUEPRINTS"]: | ||
try: | ||
logger.info("Registering blueprint: '{}'".format(bp.name)) | ||
self.flask_app.register_blueprint(bp) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. Can we lowercase this like the other packages. Package names are case insensitive.