Method: flask.cli.ScriptInfo.load_app
Calls: 42, Exceptions: 5, Paths: 7Back
Path 1: 25 calls (0.6)
Flask (25)
1def load_app(self) -> Flask:
2 """Loads the Flask app (if not yet loaded) and returns it. Calling
3 this multiple times will just result in the already loaded app to
4 be returned.
5 """
6 if self._loaded_app is not None:
7 return self._loaded_app
8
9 if self.create_app is not None:
10 app = self.create_app()
11 else:
12 if self.app_import_path:
13 path, name = (
14 re.split(r":(?![\\/])", self.app_import_path, 1) + [None]
15 )[:2]
16 import_name = prepare_import(path)
17 app = locate_app(import_name, name)
18 else:
19 for path in ("wsgi.py", "app.py"):
20 import_name = prepare_import(path)
21 app = locate_app(import_name, None, raise_if_not_found=False)
22
23 if app:
24 break
25
26 if not app:
27 raise NoAppException(
28 "Could not locate a Flask application. Use the"
29 " 'flask --app' option, 'FLASK_APP' environment"
30 " variable, or a 'wsgi.py' or 'app.py' file in the"
31 " current directory."
32 )
33
34 if self.set_debug_flag:
35 # Update the app's debug flag through the descriptor so that
36 # other values repopulate as well.
37 app.debug = get_debug_flag()
38
39 self._loaded_app = app
40 return app
Path 2: 6 calls (0.14)
Flask (6)
1def load_app(self) -> Flask:
2 """Loads the Flask app (if not yet loaded) and returns it. Calling
3 this multiple times will just result in the already loaded app to
4 be returned.
5 """
6 if self._loaded_app is not None:
7 return self._loaded_app
8
9 if self.create_app is not None:
10 app = self.create_app()
11 else:
12 if self.app_import_path:
13 path, name = (
14 re.split(r":(?![\\/])", self.app_import_path, 1) + [None]
15 )[:2]
16 import_name = prepare_import(path)
17 app = locate_app(import_name, name)
18 else:
19 for path in ("wsgi.py", "app.py"):
20 import_name = prepare_import(path)
21 app = locate_app(import_name, None, raise_if_not_found=False)
22
23 if app:
24 break
25
26 if not app:
27 raise NoAppException(
28 "Could not locate a Flask application. Use the"
29 " 'flask --app' option, 'FLASK_APP' environment"
30 " variable, or a 'wsgi.py' or 'app.py' file in the"
31 " current directory."
32 )
33
34 if self.set_debug_flag:
35 # Update the app's debug flag through the descriptor so that
36 # other values repopulate as well.
37 app.debug = get_debug_flag()
38
39 self._loaded_app = app
40 return app
Path 3: 4 calls (0.1)
NoAppException (4)
1def load_app(self) -> Flask:
2 """Loads the Flask app (if not yet loaded) and returns it. Calling
3 this multiple times will just result in the already loaded app to
4 be returned.
5 """
6 if self._loaded_app is not None:
7 return self._loaded_app
8
9 if self.create_app is not None:
10 app = self.create_app()
11 else:
12 if self.app_import_path:
13 path, name = (
14 re.split(r":(?![\\/])", self.app_import_path, 1) + [None]
15 )[:2]
16 import_name = prepare_import(path)
17 app = locate_app(import_name, name)
18 else:
19 for path in ("wsgi.py", "app.py"):
20 import_name = prepare_import(path)
21 app = locate_app(import_name, None, raise_if_not_found=False)
22
23 if app:
24 break
25
26 if not app:
27 raise NoAppException(
28 "Could not locate a Flask application. Use the"
29 " 'flask --app' option, 'FLASK_APP' environment"
30 " variable, or a 'wsgi.py' or 'app.py' file in the"
31 " current directory."
32 )
33
34 if self.set_debug_flag:
35 # Update the app's debug flag through the descriptor so that
36 # other values repopulate as well.
37 app.debug = get_debug_flag()
38
39 self._loaded_app = app
40 return app
Path 4: 3 calls (0.07)
Flask (3)
1def load_app(self) -> Flask:
2 """Loads the Flask app (if not yet loaded) and returns it. Calling
3 this multiple times will just result in the already loaded app to
4 be returned.
5 """
6 if self._loaded_app is not None:
7 return self._loaded_app
8
9 if self.create_app is not None:
10 app = self.create_app()
11 else:
12 if self.app_import_path:
13 path, name = (
14 re.split(r":(?![\\/])", self.app_import_path, 1) + [None]
15 )[:2]
16 import_name = prepare_import(path)
17 app = locate_app(import_name, name)
18 else:
19 for path in ("wsgi.py", "app.py"):
20 import_name = prepare_import(path)
21 app = locate_app(import_name, None, raise_if_not_found=False)
22
23 if app:
24 break
25
26 if not app:
27 raise NoAppException(
28 "Could not locate a Flask application. Use the"
29 " 'flask --app' option, 'FLASK_APP' environment"
30 " variable, or a 'wsgi.py' or 'app.py' file in the"
31 " current directory."
32 )
33
34 if self.set_debug_flag:
35 # Update the app's debug flag through the descriptor so that
36 # other values repopulate as well.
37 app.debug = get_debug_flag()
38
39 self._loaded_app = app
40 return app
Path 5: 2 calls (0.05)
Flask (2)
1def load_app(self) -> Flask:
2 """Loads the Flask app (if not yet loaded) and returns it. Calling
3 this multiple times will just result in the already loaded app to
4 be returned.
5 """
6 if self._loaded_app is not None:
7 return self._loaded_app
8
9 if self.create_app is not None:
10 app = self.create_app()
11 else:
12 if self.app_import_path:
13 path, name = (
14 re.split(r":(?![\\/])", self.app_import_path, 1) + [None]
15 )[:2]
16 import_name = prepare_import(path)
17 app = locate_app(import_name, name)
18 else:
19 for path in ("wsgi.py", "app.py"):
20 import_name = prepare_import(path)
21 app = locate_app(import_name, None, raise_if_not_found=False)
22
23 if app:
24 break
25
26 if not app:
27 raise NoAppException(
28 "Could not locate a Flask application. Use the"
29 " 'flask --app' option, 'FLASK_APP' environment"
30 " variable, or a 'wsgi.py' or 'app.py' file in the"
31 " current directory."
32 )
33
34 if self.set_debug_flag:
35 # Update the app's debug flag through the descriptor so that
36 # other values repopulate as well.
37 app.debug = get_debug_flag()
38
39 self._loaded_app = app
40 return app
Path 6: 1 calls (0.02)
Flask (1)
1def load_app(self) -> Flask:
2 """Loads the Flask app (if not yet loaded) and returns it. Calling
3 this multiple times will just result in the already loaded app to
4 be returned.
5 """
6 if self._loaded_app is not None:
7 return self._loaded_app
8
9 if self.create_app is not None:
10 app = self.create_app()
11 else:
12 if self.app_import_path:
13 path, name = (
14 re.split(r":(?![\\/])", self.app_import_path, 1) + [None]
15 )[:2]
16 import_name = prepare_import(path)
17 app = locate_app(import_name, name)
18 else:
19 for path in ("wsgi.py", "app.py"):
20 import_name = prepare_import(path)
21 app = locate_app(import_name, None, raise_if_not_found=False)
22
23 if app:
24 break
25
26 if not app:
27 raise NoAppException(
28 "Could not locate a Flask application. Use the"
29 " 'flask --app' option, 'FLASK_APP' environment"
30 " variable, or a 'wsgi.py' or 'app.py' file in the"
31 " current directory."
32 )
33
34 if self.set_debug_flag:
35 # Update the app's debug flag through the descriptor so that
36 # other values repopulate as well.
37 app.debug = get_debug_flag()
38
39 self._loaded_app = app
40 return app
Path 7: 1 calls (0.02)
Exception (1)
1def load_app(self) -> Flask:
2 """Loads the Flask app (if not yet loaded) and returns it. Calling
3 this multiple times will just result in the already loaded app to
4 be returned.
5 """
6 if self._loaded_app is not None:
7 return self._loaded_app
8
9 if self.create_app is not None:
10 app = self.create_app()
11 else:
12 if self.app_import_path:
13 path, name = (
14 re.split(r":(?![\\/])", self.app_import_path, 1) + [None]
15 )[:2]
16 import_name = prepare_import(path)
17 app = locate_app(import_name, name)
18 else:
19 for path in ("wsgi.py", "app.py"):
20 import_name = prepare_import(path)
21 app = locate_app(import_name, None, raise_if_not_found=False)
22
23 if app:
24 break
25
26 if not app:
27 raise NoAppException(
28 "Could not locate a Flask application. Use the"
29 " 'flask --app' option, 'FLASK_APP' environment"
30 " variable, or a 'wsgi.py' or 'app.py' file in the"
31 " current directory."
32 )
33
34 if self.set_debug_flag:
35 # Update the app's debug flag through the descriptor so that
36 # other values repopulate as well.
37 app.debug = get_debug_flag()
38
39 self._loaded_app = app
40 return app