Loads the Flask app (if not yet loaded) and returns it. Calling this multiple times will just result in the already loaded app to be returned.
(self)
| 331 | self._loaded_app: Flask | None = None |
| 332 | |
| 333 | def load_app(self) -> Flask: |
| 334 | """Loads the Flask app (if not yet loaded) and returns it. Calling |
| 335 | this multiple times will just result in the already loaded app to |
| 336 | be returned. |
| 337 | """ |
| 338 | if self._loaded_app is not None: |
| 339 | return self._loaded_app |
| 340 | app: Flask | None = None |
| 341 | if self.create_app is not None: |
| 342 | app = self.create_app() |
| 343 | else: |
| 344 | if self.app_import_path: |
| 345 | path, name = ( |
| 346 | re.split(r":(?![\\/])", self.app_import_path, maxsplit=1) + [None] |
| 347 | )[:2] |
| 348 | import_name = prepare_import(path) |
| 349 | app = locate_app(import_name, name) |
| 350 | else: |
| 351 | for path in ("wsgi.py", "app.py"): |
| 352 | import_name = prepare_import(path) |
| 353 | app = locate_app(import_name, None, raise_if_not_found=False) |
| 354 | |
| 355 | if app is not None: |
| 356 | break |
| 357 | |
| 358 | if app is None: |
| 359 | raise NoAppException( |
| 360 | "Could not locate a Flask application. Use the" |
| 361 | " 'flask --app' option, 'FLASK_APP' environment" |
| 362 | " variable, or a 'wsgi.py' or 'app.py' file in the" |
| 363 | " current directory." |
| 364 | ) |
| 365 | |
| 366 | if self.set_debug_flag: |
| 367 | # Update the app's debug flag through the descriptor so that |
| 368 | # other values repopulate as well. |
| 369 | app.debug = get_debug_flag() |
| 370 | |
| 371 | self._loaded_app = app |
| 372 | return app |
| 373 | |
| 374 | |
| 375 | pass_script_info = click.make_pass_decorator(ScriptInfo, ensure=True) |