Method: flask.cli.find_best_app
Calls: 17, Exceptions: 4, Paths: 7Back
Path 1: 6 calls (0.35)
test_find_best_app.
Flask (6)
1def find_best_app(module):
2 """Given a module instance this tries to find the best possible
3 application in the module or raises an exception.
4 """
5 from . import Flask
6
7 # Search for the most common names first.
8 for attr_name in ("app", "application"):
9 app = getattr(module, attr_name, None)
10
11 if isinstance(app, Flask):
12 return app
13
14 # Otherwise find the only object that is a Flask instance.
15 matches = [v for v in module.__dict__.values() if isinstance(v, Flask)]
16
17 if len(matches) == 1:
18 return matches[0]
19 elif len(matches) > 1:
20 raise NoAppException(
21 "Detected multiple Flask applications in module"
22 f" '{module.__name__}'. Use '{module.__name__}:name'"
23 " to specify the correct one."
24 )
25
26 # Search for app factory functions.
27 for attr_name in ("create_app", "make_app"):
28 app_factory = getattr(module, attr_name, None)
29
30 if inspect.isfunction(app_factory):
31 try:
32 app = app_factory()
33
34 if isinstance(app, Flask):
35 return app
36 except TypeError as e:
37 if not _called_with_wrong_args(app_factory):
38 raise
39
40 raise NoAppException(
41 f"Detected factory '{attr_name}' in module '{module.__name__}',"
42 " but could not call it without arguments. Use"
43 f" '{module.__name__}:{attr_name}(args)'"
44 " to specify arguments."
45 ) from e
46
47 raise NoAppException(
48 "Failed to find Flask application or factory in module"
49 f" '{module.__name__}'. Use '{module.__name__}:name'"
50 " to specify one."
51 )
Path 2: 4 calls (0.24)
test_find_best_app.
Flask (4)
1def find_best_app(module):
2 """Given a module instance this tries to find the best possible
3 application in the module or raises an exception.
4 """
5 from . import Flask
6
7 # Search for the most common names first.
8 for attr_name in ("app", "application"):
9 app = getattr(module, attr_name, None)
10
11 if isinstance(app, Flask):
12 return app
13
14 # Otherwise find the only object that is a Flask instance.
15 matches = [v for v in module.__dict__.values() if isinstance(v, Flask)]
16
17 if len(matches) == 1:
18 return matches[0]
19 elif len(matches) > 1:
20 raise NoAppException(
21 "Detected multiple Flask applications in module"
22 f" '{module.__name__}'. Use '{module.__name__}:name'"
23 " to specify the correct one."
24 )
25
26 # Search for app factory functions.
27 for attr_name in ("create_app", "make_app"):
28 app_factory = getattr(module, attr_name, None)
29
30 if inspect.isfunction(app_factory):
31 try:
32 app = app_factory()
33
34 if isinstance(app, Flask):
35 return app
36 except TypeError as e:
37 if not _called_with_wrong_args(app_factory):
38 raise
39
40 raise NoAppException(
41 f"Detected factory '{attr_name}' in module '{module.__name__}',"
42 " but could not call it without arguments. Use"
43 f" '{module.__name__}:{attr_name}(args)'"
44 " to specify arguments."
45 ) from e
46
47 raise NoAppException(
48 "Failed to find Flask application or factory in module"
49 f" '{module.__name__}'. Use '{module.__name__}:name'"
50 " to specify one."
51 )
Path 3: 3 calls (0.18)
test_find_best_app.
Flask (3)
1def find_best_app(module):
2 """Given a module instance this tries to find the best possible
3 application in the module or raises an exception.
4 """
5 from . import Flask
6
7 # Search for the most common names first.
8 for attr_name in ("app", "application"):
9 app = getattr(module, attr_name, None)
10
11 if isinstance(app, Flask):
12 return app
13
14 # Otherwise find the only object that is a Flask instance.
15 matches = [v for v in module.__dict__.values() if isinstance(v, Flask)]
16
17 if len(matches) == 1:
18 return matches[0]
19 elif len(matches) > 1:
20 raise NoAppException(
21 "Detected multiple Flask applications in module"
22 f" '{module.__name__}'. Use '{module.__name__}:name'"
23 " to specify the correct one."
24 )
25
26 # Search for app factory functions.
27 for attr_name in ("create_app", "make_app"):
28 app_factory = getattr(module, attr_name, None)
29
30 if inspect.isfunction(app_factory):
31 try:
32 app = app_factory()
33
34 if isinstance(app, Flask):
35 return app
36 except TypeError as e:
37 if not _called_with_wrong_args(app_factory):
38 raise
39
40 raise NoAppException(
41 f"Detected factory '{attr_name}' in module '{module.__name__}',"
42 " but could not call it without arguments. Use"
43 f" '{module.__name__}:{attr_name}(args)'"
44 " to specify arguments."
45 ) from e
46
47 raise NoAppException(
48 "Failed to find Flask application or factory in module"
49 f" '{module.__name__}'. Use '{module.__name__}:name'"
50 " to specify one."
51 )
Path 4: 1 calls (0.06)
test_find_best_app.
NoAppException (1)
1def find_best_app(module):
2 """Given a module instance this tries to find the best possible
3 application in the module or raises an exception.
4 """
5 from . import Flask
6
7 # Search for the most common names first.
8 for attr_name in ("app", "application"):
9 app = getattr(module, attr_name, None)
10
11 if isinstance(app, Flask):
12 return app
13
14 # Otherwise find the only object that is a Flask instance.
15 matches = [v for v in module.__dict__.values() if isinstance(v, Flask)]
16
17 if len(matches) == 1:
18 return matches[0]
19 elif len(matches) > 1:
20 raise NoAppException(
21 "Detected multiple Flask applications in module"
22 f" '{module.__name__}'. Use '{module.__name__}:name'"
23 " to specify the correct one."
24 )
25
26 # Search for app factory functions.
27 for attr_name in ("create_app", "make_app"):
28 app_factory = getattr(module, attr_name, None)
29
30 if inspect.isfunction(app_factory):
31 try:
32 app = app_factory()
33
34 if isinstance(app, Flask):
35 return app
36 except TypeError as e:
37 if not _called_with_wrong_args(app_factory):
38 raise
39
40 raise NoAppException(
41 f"Detected factory '{attr_name}' in module '{module.__name__}',"
42 " but could not call it without arguments. Use"
43 f" '{module.__name__}:{attr_name}(args)'"
44 " to specify arguments."
45 ) from e
46
47 raise NoAppException(
48 "Failed to find Flask application or factory in module"
49 f" '{module.__name__}'. Use '{module.__name__}:name'"
50 " to specify one."
51 )
Path 5: 1 calls (0.06)
test_find_best_app.
NoAppException (1)
1def find_best_app(module):
2 """Given a module instance this tries to find the best possible
3 application in the module or raises an exception.
4 """
5 from . import Flask
6
7 # Search for the most common names first.
8 for attr_name in ("app", "application"):
9 app = getattr(module, attr_name, None)
10
11 if isinstance(app, Flask):
12 return app
13
14 # Otherwise find the only object that is a Flask instance.
15 matches = [v for v in module.__dict__.values() if isinstance(v, Flask)]
16
17 if len(matches) == 1:
18 return matches[0]
19 elif len(matches) > 1:
20 raise NoAppException(
21 "Detected multiple Flask applications in module"
22 f" '{module.__name__}'. Use '{module.__name__}:name'"
23 " to specify the correct one."
24 )
25
26 # Search for app factory functions.
27 for attr_name in ("create_app", "make_app"):
28 app_factory = getattr(module, attr_name, None)
29
30 if inspect.isfunction(app_factory):
31 try:
32 app = app_factory()
33
34 if isinstance(app, Flask):
35 return app
36 except TypeError as e:
37 if not _called_with_wrong_args(app_factory):
38 raise
39
40 raise NoAppException(
41 f"Detected factory '{attr_name}' in module '{module.__name__}',"
42 " but could not call it without arguments. Use"
43 f" '{module.__name__}:{attr_name}(args)'"
44 " to specify arguments."
45 ) from e
46
47 raise NoAppException(
48 "Failed to find Flask application or factory in module"
49 f" '{module.__name__}'. Use '{module.__name__}:name'"
50 " to specify one."
51 )
Path 6: 1 calls (0.06)
test_find_best_app.
NoAppException (1)
1def find_best_app(module):
2 """Given a module instance this tries to find the best possible
3 application in the module or raises an exception.
4 """
5 from . import Flask
6
7 # Search for the most common names first.
8 for attr_name in ("app", "application"):
9 app = getattr(module, attr_name, None)
10
11 if isinstance(app, Flask):
12 return app
13
14 # Otherwise find the only object that is a Flask instance.
15 matches = [v for v in module.__dict__.values() if isinstance(v, Flask)]
16
17 if len(matches) == 1:
18 return matches[0]
19 elif len(matches) > 1:
20 raise NoAppException(
21 "Detected multiple Flask applications in module"
22 f" '{module.__name__}'. Use '{module.__name__}:name'"
23 " to specify the correct one."
24 )
25
26 # Search for app factory functions.
27 for attr_name in ("create_app", "make_app"):
28 app_factory = getattr(module, attr_name, None)
29
30 if inspect.isfunction(app_factory):
31 try:
32 app = app_factory()
33
34 if isinstance(app, Flask):
35 return app
36 except TypeError as e:
37 if not _called_with_wrong_args(app_factory):
38 raise
39
40 raise NoAppException(
41 f"Detected factory '{attr_name}' in module '{module.__name__}',"
42 " but could not call it without arguments. Use"
43 f" '{module.__name__}:{attr_name}(args)'"
44 " to specify arguments."
45 ) from e
46
47 raise NoAppException(
48 "Failed to find Flask application or factory in module"
49 f" '{module.__name__}'. Use '{module.__name__}:name'"
50 " to specify one."
51 )
Path 7: 1 calls (0.06)
test_find_best_app.
TypeError (1)
1def find_best_app(module):
2 """Given a module instance this tries to find the best possible
3 application in the module or raises an exception.
4 """
5 from . import Flask
6
7 # Search for the most common names first.
8 for attr_name in ("app", "application"):
9 app = getattr(module, attr_name, None)
10
11 if isinstance(app, Flask):
12 return app
13
14 # Otherwise find the only object that is a Flask instance.
15 matches = [v for v in module.__dict__.values() if isinstance(v, Flask)]
16
17 if len(matches) == 1:
18 return matches[0]
19 elif len(matches) > 1:
20 raise NoAppException(
21 "Detected multiple Flask applications in module"
22 f" '{module.__name__}'. Use '{module.__name__}:name'"
23 " to specify the correct one."
24 )
25
26 # Search for app factory functions.
27 for attr_name in ("create_app", "make_app"):
28 app_factory = getattr(module, attr_name, None)
29
30 if inspect.isfunction(app_factory):
31 try:
32 app = app_factory()
33
34 if isinstance(app, Flask):
35 return app
36 except TypeError as e:
37 if not _called_with_wrong_args(app_factory):
38 raise
39
40 raise NoAppException(
41 f"Detected factory '{attr_name}' in module '{module.__name__}',"
42 " but could not call it without arguments. Use"
43 f" '{module.__name__}:{attr_name}(args)'"
44 " to specify arguments."
45 ) from e
46
47 raise NoAppException(
48 "Failed to find Flask application or factory in module"
49 f" '{module.__name__}'. Use '{module.__name__}:name'"
50 " to specify one."
51 )