Return the first acceptable shell-embed function from a given list of shell names.
(
shells: Iterable[str] | None = None, known_shells: KnownShellsT | None = None
)
| 99 | |
| 100 | |
| 101 | def get_shell_embed_func( |
| 102 | shells: Iterable[str] | None = None, known_shells: KnownShellsT | None = None |
| 103 | ) -> EmbedFuncT | None: |
| 104 | """Return the first acceptable shell-embed function |
| 105 | from a given list of shell names. |
| 106 | """ |
| 107 | if shells is None: # list, preference order of shells |
| 108 | shells = DEFAULT_PYTHON_SHELLS.keys() |
| 109 | if known_shells is None: # available embeddable shells |
| 110 | known_shells = DEFAULT_PYTHON_SHELLS.copy() |
| 111 | for shell in shells: |
| 112 | if shell in known_shells: |
| 113 | try: |
| 114 | # function test: run all setup code (imports), |
| 115 | # but dont fall into the shell |
| 116 | return known_shells[shell]() |
| 117 | except ImportError: |
| 118 | continue |
| 119 | return None |
| 120 | |
| 121 | |
| 122 | def start_python_console( |