prepare_import() — flask Function Reference
Architecture documentation for the prepare_import() function in cli.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD d3588a10_397e_57ef_4714_4c8c478b107b["prepare_import()"] a96499c3_f8a9_e782_f156_1c1ee4a86c69["cli.py"] d3588a10_397e_57ef_4714_4c8c478b107b -->|defined in| a96499c3_f8a9_e782_f156_1c1ee4a86c69 6cabef6b_f1ce_76af_5916_c4e9a439548c["load_app()"] 6cabef6b_f1ce_76af_5916_c4e9a439548c -->|calls| d3588a10_397e_57ef_4714_4c8c478b107b style d3588a10_397e_57ef_4714_4c8c478b107b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/flask/cli.py lines 200–226
def prepare_import(path: str) -> str:
"""Given a filename this will try to calculate the python path, add it
to the search path and return the actual module name that is expected.
"""
path = os.path.realpath(path)
fname, ext = os.path.splitext(path)
if ext == ".py":
path = fname
if os.path.basename(path) == "__init__":
path = os.path.dirname(path)
module_name = []
# move up until outside package structure (no __init__.py)
while True:
path, name = os.path.split(path)
module_name.append(name)
if not os.path.exists(os.path.join(path, "__init__.py")):
break
if sys.path[0] != path:
sys.path.insert(0, path)
return ".".join(module_name[::-1])
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does prepare_import() do?
prepare_import() is a function in the flask codebase, defined in src/flask/cli.py.
Where is prepare_import() defined?
prepare_import() is defined in src/flask/cli.py at line 200.
What calls prepare_import()?
prepare_import() is called by 1 function(s): load_app.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free