Method: flask.scaffold.find_package
Calls: 447, Exceptions: 0, Paths: 2Back
Path 1: 441 calls (0.99)
'flask_test' (318) 'test_config' (22) 'test_basic' (20) 'test_helpers' (10) 'test_async' (8) 'test_templating' (7) 'testapp' (6) 'appname' (6) 'test_c...
(None, '/Users/andrehora/Documents/git/projects-pathspotter/flask') (345) (None, '/Users/andrehora/Documents/git/projects-pathspotter/flask/tests') (9...
1def find_package(import_name: str):
2 """Find the prefix that a package is installed under, and the path
3 that it would be imported from.
4
5 The prefix is the directory containing the standard directory
6 hierarchy (lib, bin, etc.). If the package is not installed to the
7 system (:attr:`sys.prefix`) or a virtualenv (``site-packages``),
8 ``None`` is returned.
9
10 The path is the entry in :attr:`sys.path` that contains the package
11 for import. If the package is not installed, it's assumed that the
12 package was imported from the current working directory.
13 """
14 package_path = _find_package_path(import_name)
15 py_prefix = os.path.abspath(sys.prefix)
16
17 # installed to the system
18 if _path_is_relative_to(pathlib.PurePath(package_path), py_prefix):
19 return py_prefix, package_path
20
21 site_parent, site_folder = os.path.split(package_path)
22
23 # installed to a virtualenv
24 if site_folder.lower() == "site-packages":
25 parent, folder = os.path.split(site_parent)
26
27 # Windows (prefix/lib/site-packages)
28 if folder.lower() == "lib":
29 return parent, package_path
30
31 # Unix (prefix/lib/pythonX.Y/site-packages)
32 if os.path.basename(parent).lower() == "lib":
33 return os.path.dirname(parent), package_path
34
35 # something else (prefix/site-packages)
36 return site_parent, package_path
37
38 # not installed
39 return None, package_path
Path 2: 6 calls (0.01)
'site_app' (2) 'installed_package' (2) 'site_package' (2)
('/Users/andrehora/Documents/git/projects-pathspotter/flask/.tox/tmp/py310/test_installed_module_paths_Tr0/modules_tmp', '/Users/andrehora/Documents/g...
1def find_package(import_name: str):
2 """Find the prefix that a package is installed under, and the path
3 that it would be imported from.
4
5 The prefix is the directory containing the standard directory
6 hierarchy (lib, bin, etc.). If the package is not installed to the
7 system (:attr:`sys.prefix`) or a virtualenv (``site-packages``),
8 ``None`` is returned.
9
10 The path is the entry in :attr:`sys.path` that contains the package
11 for import. If the package is not installed, it's assumed that the
12 package was imported from the current working directory.
13 """
14 package_path = _find_package_path(import_name)
15 py_prefix = os.path.abspath(sys.prefix)
16
17 # installed to the system
18 if _path_is_relative_to(pathlib.PurePath(package_path), py_prefix):
19 return py_prefix, package_path
20
21 site_parent, site_folder = os.path.split(package_path)
22
23 # installed to a virtualenv
24 if site_folder.lower() == "site-packages":
25 parent, folder = os.path.split(site_parent)
26
27 # Windows (prefix/lib/site-packages)
28 if folder.lower() == "lib":
29 return parent, package_path
30
31 # Unix (prefix/lib/pythonX.Y/site-packages)
32 if os.path.basename(parent).lower() == "lib":
33 return os.path.dirname(parent), package_path
34
35 # something else (prefix/site-packages)
36 return site_parent, package_path
37
38 # not installed
39 return None, package_path