Launch ptpython shell asynchronously. Args: namespace: The namespace dict to make available in the shell
(namespace: dict[str, Any])
| 117 | |
| 118 | |
| 119 | async 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 |
no test coverage detected
searching dependent graphs…