Path 1: 345 calls (0.77)

'flask_test' (318) 'testapp' (6) 'appname' (6) 'app' (4) 'appname1' (3) 'flaskgroup' (3) 'app2_foo_bar' (2) 'appname2' (1) 'createapp' (1) 'testappgro...

'/Users/andrehora/Documents/git/projects-pathspotter/flask' (345)

ValueError (345)

1def _find_package_path(import_name):
2    """Find the path that contains the package or module."""
3    root_mod_name, _, _ = import_name.partition(".")
4
5    try:
6        root_spec = importlib.util.find_spec(root_mod_name)
7
8        if root_spec is None:
9            raise ValueError("not found")
10    except (ImportError, ValueError):
11        # ImportError: the machinery told us it does not exist
12        # ValueError:
13        #    - the module name was invalid
14        #    - the module name is __main__
15        #    - we raised `ValueError` due to `root_spec` being `None`
16        return os.getcwd()
17
18    if root_spec.origin in {"namespace", None}:
19        # namespace package
20        package_spec = importlib.util.find_spec(import_name)
21
22        if package_spec is not None and package_spec.submodule_search_locations:
23            # Pick the path in the namespace that contains the submodule.
24            package_path = pathlib.Path(
25                os.path.commonpath(package_spec.submodule_search_locations)
26            )
27            search_location = next(
28                location
29                for location in root_spec.submodule_search_locations
30                if _path_is_relative_to(package_path, location)
31            )
32        else:
33            # Pick the first path.
34            search_location = root_spec.submodule_search_locations[0]
35
36        return os.path.dirname(search_location)
37    elif root_spec.submodule_search_locations:
38        # package with __init__.py
39        return os.path.dirname(os.path.dirname(root_spec.origin))
40    else:
41        # module
42        return os.path.dirname(root_spec.origin)
            

Path 2: 96 calls (0.21)

'test_config' (22) 'test_basic' (20) 'test_helpers' (10) 'test_async' (8) 'test_templating' (7) 'test_cli' (6) 'test_reqctx' (5) 'test_signals' (3) 't...

'/Users/andrehora/Documents/git/projects-pathspotter/flask/tests' (91) '/Users/andrehora/Documents/git/projects-pathspotter/flask/tests/test_apps/hell...

1def _find_package_path(import_name):
2    """Find the path that contains the package or module."""
3    root_mod_name, _, _ = import_name.partition(".")
4
5    try:
6        root_spec = importlib.util.find_spec(root_mod_name)
7
8        if root_spec is None:
9            raise ValueError("not found")
10    except (ImportError, ValueError):
11        # ImportError: the machinery told us it does not exist
12        # ValueError:
13        #    - the module name was invalid
14        #    - the module name is __main__
15        #    - we raised `ValueError` due to `root_spec` being `None`
16        return os.getcwd()
17
18    if root_spec.origin in {"namespace", None}:
19        # namespace package
20        package_spec = importlib.util.find_spec(import_name)
21
22        if package_spec is not None and package_spec.submodule_search_locations:
23            # Pick the path in the namespace that contains the submodule.
24            package_path = pathlib.Path(
25                os.path.commonpath(package_spec.submodule_search_locations)
26            )
27            search_location = next(
28                location
29                for location in root_spec.submodule_search_locations
30                if _path_is_relative_to(package_path, location)
31            )
32        else:
33            # Pick the first path.
34            search_location = root_spec.submodule_search_locations[0]
35
36        return os.path.dirname(search_location)
37    elif root_spec.submodule_search_locations:
38        # package with __init__.py
39        return os.path.dirname(os.path.dirname(root_spec.origin))
40    else:
41        # module
42        return os.path.dirname(root_spec.origin)
            

Path 3: 5 calls (0.01)

'installed_package' (2) 'site_package' (2) 'config_package_app' (1)

'/Users/andrehora/Documents/git/projects-pathspotter/flask/.tox/tmp/py310/test_uninstalled_package_paths0/modules_tmp' (1) '/Users/andrehora/Documents...

1def _find_package_path(import_name):
2    """Find the path that contains the package or module."""
3    root_mod_name, _, _ = import_name.partition(".")
4
5    try:
6        root_spec = importlib.util.find_spec(root_mod_name)
7
8        if root_spec is None:
9            raise ValueError("not found")
10    except (ImportError, ValueError):
11        # ImportError: the machinery told us it does not exist
12        # ValueError:
13        #    - the module name was invalid
14        #    - the module name is __main__
15        #    - we raised `ValueError` due to `root_spec` being `None`
16        return os.getcwd()
17
18    if root_spec.origin in {"namespace", None}:
19        # namespace package
20        package_spec = importlib.util.find_spec(import_name)
21
22        if package_spec is not None and package_spec.submodule_search_locations:
23            # Pick the path in the namespace that contains the submodule.
24            package_path = pathlib.Path(
25                os.path.commonpath(package_spec.submodule_search_locations)
26            )
27            search_location = next(
28                location
29                for location in root_spec.submodule_search_locations
30                if _path_is_relative_to(package_path, location)
31            )
32        else:
33            # Pick the first path.
34            search_location = root_spec.submodule_search_locations[0]
35
36        return os.path.dirname(search_location)
37    elif root_spec.submodule_search_locations:
38        # package with __init__.py
39        return os.path.dirname(os.path.dirname(root_spec.origin))
40    else:
41        # module
42        return os.path.dirname(root_spec.origin)
            

Path 4: 1 calls (0.0)

'namespace.package2' (1)

'/Users/andrehora/Documents/git/projects-pathspotter/flask/.tox/tmp/py310/test_uninstalled_namespace_pat0/project-package2' (1)

GeneratorExit (1)

1def _find_package_path(import_name):
2    """Find the path that contains the package or module."""
3    root_mod_name, _, _ = import_name.partition(".")
4
5    try:
6        root_spec = importlib.util.find_spec(root_mod_name)
7
8        if root_spec is None:
9            raise ValueError("not found")
10    except (ImportError, ValueError):
11        # ImportError: the machinery told us it does not exist
12        # ValueError:
13        #    - the module name was invalid
14        #    - the module name is __main__
15        #    - we raised `ValueError` due to `root_spec` being `None`
16        return os.getcwd()
17
18    if root_spec.origin in {"namespace", None}:
19        # namespace package
20        package_spec = importlib.util.find_spec(import_name)
21
22        if package_spec is not None and package_spec.submodule_search_locations:
23            # Pick the path in the namespace that contains the submodule.
24            package_path = pathlib.Path(
25                os.path.commonpath(package_spec.submodule_search_locations)
26            )
27            search_location = next(
28                location
29                for location in root_spec.submodule_search_locations
30                if _path_is_relative_to(package_path, location)
31            )
32        else:
33            # Pick the first path.
34            search_location = root_spec.submodule_search_locations[0]
35
36        return os.path.dirname(search_location)
37    elif root_spec.submodule_search_locations:
38        # package with __init__.py
39        return os.path.dirname(os.path.dirname(root_spec.origin))
40    else:
41        # module
42        return os.path.dirname(root_spec.origin)