MCPcopy Index your code
hub / github.com/tortoise/tortoise-orm / _launch_ptpython_shell

Function _launch_ptpython_shell

tortoise/cli/cli.py:119–148  ·  view source on GitHub ↗

Launch ptpython shell asynchronously. Args: namespace: The namespace dict to make available in the shell

(namespace: dict[str, Any])

Source from the content-addressed store, hash-verified

117
118
119async def _launch_ptpython_shell(namespace: dict[str, Any]) -> None:
120 """Launch ptpython shell asynchronously.
121
122 Args:
123 namespace: The namespace dict to make available in the shell
124 """
125 # Apply Windows patch for ptpython signal handler issues
126 if platform.system() == "Windows":
127 _patch_loop_factory_for_ptpython()
128
129 model_names = [
130 k for k in namespace.keys() if k not in ("Tortoise", "tortoise", "connections", "apps")
131 ]
132
133 # Print banner before launching ptpython
134 models_info = (
135 f"Available models: {', '.join(model_names)}" if model_names else "No models loaded"
136 )
137 print("Tortoise ORM Shell (ptpython)")
138 print(models_info)
139 print("Use 'await' directly for async operations (e.g., 'await YourModel.all()').\n")
140
141 with contextlib.suppress(EOFError, ValueError):
142 await ptpython_embed(
143 globals=namespace,
144 title="Tortoise Shell",
145 vi_mode=True,
146 return_asyncio_coroutine=True,
147 patch_stdout=True,
148 )
149
150
151@contextlib.asynccontextmanager

Callers 1

shellFunction · 0.85

Calls 2

keysMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…