_find_package_path() — flask Function Reference
Architecture documentation for the _find_package_path() function in scaffold.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD 3e63b545_7895_fecc_eae5_b9d8a7667c97["_find_package_path()"] b48dce3f_427c_079b_4c4a_8f5873f5b51f["scaffold.py"] 3e63b545_7895_fecc_eae5_b9d8a7667c97 -->|defined in| b48dce3f_427c_079b_4c4a_8f5873f5b51f 4edb5aa7_d577_d1ba_2a86_d1b146357835["find_package()"] 4edb5aa7_d577_d1ba_2a86_d1b146357835 -->|calls| 3e63b545_7895_fecc_eae5_b9d8a7667c97 style 3e63b545_7895_fecc_eae5_b9d8a7667c97 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/flask/sansio/scaffold.py lines 709–751
def _find_package_path(import_name: str) -> str:
"""Find the path that contains the package or module."""
root_mod_name, _, _ = import_name.partition(".")
try:
root_spec = importlib.util.find_spec(root_mod_name)
if root_spec is None:
raise ValueError("not found")
except (ImportError, ValueError):
# ImportError: the machinery told us it does not exist
# ValueError:
# - the module name was invalid
# - the module name is __main__
# - we raised `ValueError` due to `root_spec` being `None`
return os.getcwd()
if root_spec.submodule_search_locations:
if root_spec.origin is None or root_spec.origin == "namespace":
# namespace package
package_spec = importlib.util.find_spec(import_name)
if package_spec is not None and package_spec.submodule_search_locations:
# Pick the path in the namespace that contains the submodule.
package_path = pathlib.Path(
os.path.commonpath(package_spec.submodule_search_locations)
)
search_location = next(
location
for location in root_spec.submodule_search_locations
if package_path.is_relative_to(location)
)
else:
# Pick the first path.
search_location = root_spec.submodule_search_locations[0]
return os.path.dirname(search_location)
else:
# package with __init__.py
return os.path.dirname(os.path.dirname(root_spec.origin))
else:
# module
return os.path.dirname(root_spec.origin) # type: ignore[type-var, return-value]
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does _find_package_path() do?
_find_package_path() is a function in the flask codebase, defined in src/flask/sansio/scaffold.py.
Where is _find_package_path() defined?
_find_package_path() is defined in src/flask/sansio/scaffold.py at line 709.
What calls _find_package_path()?
_find_package_path() is called by 1 function(s): find_package.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free