Path 1: 12 calls (0.38)

'cliapp.factory' (8) 'cliapp.app' (4)

'testapp' (3) 'create_app' (1) 'create_app()' (1) 'create_app2("foo", "bar")' (1) 'create_app2("foo", "bar", )' (1) ' create_app () ' (1) 'notanapp' (...

True (12)

Flask (8) None (4)

NoAppException (4)

1def locate_app(module_name, app_name, raise_if_not_found=True):
2    try:
3        __import__(module_name)
4    except ImportError:
5        # Reraise the ImportError if it occurred within the imported module.
6        # Determine this by checking whether the trace has a depth > 1.
7        if sys.exc_info()[2].tb_next:
8            raise NoAppException(
9                f"While importing {module_name!r}, an ImportError was"
10                f" raised:\n\n{traceback.format_exc()}"
11            ) from None
12        elif raise_if_not_found:
13            raise NoAppException(f"Could not import {module_name!r}.") from None
14        else:
15            return
16
17    module = sys.modules[module_name]
18
19    if app_name is None:
20        return find_best_app(module)
21    else:
22        return find_app_by_string(module, app_name)
            

Path 2: 10 calls (0.31)

'wsgi' (4) 'app' (4) 'notanapp.py' (1) 'cliapp.wsgi' (1)

None (10)

False (10)

None (10)

ModuleNotFoundError (10)

1def locate_app(module_name, app_name, raise_if_not_found=True):
2    try:
3        __import__(module_name)
4    except ImportError:
5        # Reraise the ImportError if it occurred within the imported module.
6        # Determine this by checking whether the trace has a depth > 1.
7        if sys.exc_info()[2].tb_next:
8            raise NoAppException(
9                f"While importing {module_name!r}, an ImportError was"
10                f" raised:\n\n{traceback.format_exc()}"
11            ) from None
12        elif raise_if_not_found:
13            raise NoAppException(f"Could not import {module_name!r}.") from None
14        else:
15            return
16
17    module = sys.modules[module_name]
18
19    if app_name is None:
20        return find_best_app(module)
21    else:
22        return find_app_by_string(module, app_name)
            

Path 3: 5 calls (0.16)

'cliapp.app' (3) 'cliapp.factory' (1) 'wsgi' (1)

None (5)

True (3) False (2)

Flask (5)

1def locate_app(module_name, app_name, raise_if_not_found=True):
2    try:
3        __import__(module_name)
4    except ImportError:
5        # Reraise the ImportError if it occurred within the imported module.
6        # Determine this by checking whether the trace has a depth > 1.
7        if sys.exc_info()[2].tb_next:
8            raise NoAppException(
9                f"While importing {module_name!r}, an ImportError was"
10                f" raised:\n\n{traceback.format_exc()}"
11            ) from None
12        elif raise_if_not_found:
13            raise NoAppException(f"Could not import {module_name!r}.") from None
14        else:
15            return
16
17    module = sys.modules[module_name]
18
19    if app_name is None:
20        return find_best_app(module)
21    else:
22        return find_app_by_string(module, app_name)
            

Path 4: 3 calls (0.09)

'notanapp.py' (1) 'cliapp/app' (1) 'cliapp.message.txt' (1)

None (3)

True (3)

NoAppException (3)

1def locate_app(module_name, app_name, raise_if_not_found=True):
2    try:
3        __import__(module_name)
4    except ImportError:
5        # Reraise the ImportError if it occurred within the imported module.
6        # Determine this by checking whether the trace has a depth > 1.
7        if sys.exc_info()[2].tb_next:
8            raise NoAppException(
9                f"While importing {module_name!r}, an ImportError was"
10                f" raised:\n\n{traceback.format_exc()}"
11            ) from None
12        elif raise_if_not_found:
13            raise NoAppException(f"Could not import {module_name!r}.") from None
14        else:
15            return
16
17    module = sys.modules[module_name]
18
19    if app_name is None:
20        return find_best_app(module)
21    else:
22        return find_app_by_string(module, app_name)
            

Path 5: 2 calls (0.06)

'cliapp.importerrorapp' (2)

None (2)

True (1) False (1)

NoAppException (2)

1def locate_app(module_name, app_name, raise_if_not_found=True):
2    try:
3        __import__(module_name)
4    except ImportError:
5        # Reraise the ImportError if it occurred within the imported module.
6        # Determine this by checking whether the trace has a depth > 1.
7        if sys.exc_info()[2].tb_next:
8            raise NoAppException(
9                f"While importing {module_name!r}, an ImportError was"
10                f" raised:\n\n{traceback.format_exc()}"
11            ) from None
12        elif raise_if_not_found:
13            raise NoAppException(f"Could not import {module_name!r}.") from None
14        else:
15            return
16
17    module = sys.modules[module_name]
18
19    if app_name is None:
20        return find_best_app(module)
21    else:
22        return find_app_by_string(module, app_name)