@@ -340,7 +340,8 @@ class ScriptInfo(object):
340
340
onwards as click object.
341
341
"""
342
342
343
- def __init__ (self , app_import_path = None , create_app = None ):
343
+ def __init__ (self , app_import_path = None , create_app = None ,
344
+ set_debug_flag = True ):
344
345
#: Optionally the import path for the Flask application.
345
346
self .app_import_path = app_import_path or os .environ .get ('FLASK_APP' )
346
347
#: Optionally a function that is passed the script info to create
@@ -349,6 +350,7 @@ def __init__(self, app_import_path=None, create_app=None):
349
350
#: A dictionary with arbitrary data that can be associated with
350
351
#: this script info.
351
352
self .data = {}
353
+ self .set_debug_flag = set_debug_flag
352
354
self ._loaded_app = None
353
355
354
356
def load_app (self ):
@@ -386,12 +388,10 @@ def load_app(self):
386
388
'"app.py" module was not found in the current directory.'
387
389
)
388
390
389
- debug = get_debug_flag ()
390
-
391
- # Update the app's debug flag through the descriptor so that other
392
- # values repopulate as well.
393
- if debug is not None :
394
- app .debug = debug
391
+ if self .set_debug_flag :
392
+ # Update the app's debug flag through the descriptor so that
393
+ # other values repopulate as well.
394
+ app .debug = get_debug_flag ()
395
395
396
396
self ._loaded_app = app
397
397
return app
@@ -459,14 +459,17 @@ class FlaskGroup(AppGroup):
459
459
:param load_dotenv: Load the nearest :file:`.env` and :file:`.flaskenv`
460
460
files to set environment variables. Will also change the working
461
461
directory to the directory containing the first file found.
462
+ :param set_debug_flag: Set the app's debug flag based on the active
463
+ environment
462
464
463
465
.. versionchanged:: 1.0
464
466
If installed, python-dotenv will be used to load environment variables
465
467
from :file:`.env` and :file:`.flaskenv` files.
466
468
"""
467
469
468
470
def __init__ (self , add_default_commands = True , create_app = None ,
469
- add_version_option = True , load_dotenv = True , ** extra ):
471
+ add_version_option = True , load_dotenv = True ,
472
+ set_debug_flag = True , ** extra ):
470
473
params = list (extra .pop ('params' , None ) or ())
471
474
472
475
if add_version_option :
@@ -475,6 +478,7 @@ def __init__(self, add_default_commands=True, create_app=None,
475
478
AppGroup .__init__ (self , params = params , ** extra )
476
479
self .create_app = create_app
477
480
self .load_dotenv = load_dotenv
481
+ self .set_debug_flag = set_debug_flag
478
482
479
483
if add_default_commands :
480
484
self .add_command (run_command )
@@ -550,7 +554,8 @@ def main(self, *args, **kwargs):
550
554
obj = kwargs .get ('obj' )
551
555
552
556
if obj is None :
553
- obj = ScriptInfo (create_app = self .create_app )
557
+ obj = ScriptInfo (create_app = self .create_app ,
558
+ set_debug_flag = self .set_debug_flag )
554
559
555
560
kwargs ['obj' ] = obj
556
561
kwargs .setdefault ('auto_envvar_prefix' , 'FLASK' )
0 commit comments