banner is displayed directly after the version information. welcome_message is passed on to Repl and displayed in the statusbar.
(
args: list[str] | None = None,
locals_: dict[str, Any] | None = None,
banner: str | None = None,
welcome_message: str | None = None,
)
| 177 | |
| 178 | |
| 179 | def main( |
| 180 | args: list[str] | None = None, |
| 181 | locals_: dict[str, Any] | None = None, |
| 182 | banner: str | None = None, |
| 183 | welcome_message: str | None = None, |
| 184 | ) -> Any: |
| 185 | """ |
| 186 | banner is displayed directly after the version information. |
| 187 | welcome_message is passed on to Repl and displayed in the statusbar. |
| 188 | """ |
| 189 | translations.init() |
| 190 | |
| 191 | def curtsies_arguments(parser: argparse._ArgumentGroup) -> None: |
| 192 | parser.add_argument( |
| 193 | "--paste", |
| 194 | "-p", |
| 195 | action="store_true", |
| 196 | help=_("start by pasting lines of a file into session"), |
| 197 | ) |
| 198 | |
| 199 | config, options, exec_args = bpargs.parse( |
| 200 | args, |
| 201 | ( |
| 202 | _("curtsies arguments"), |
| 203 | _("Additional arguments specific to the curtsies-based REPL."), |
| 204 | curtsies_arguments, |
| 205 | ), |
| 206 | ) |
| 207 | |
| 208 | interp = None |
| 209 | paste = None |
| 210 | exit_value: tuple[Any, ...] = () |
| 211 | if exec_args: |
| 212 | if not options: |
| 213 | raise ValueError("don't pass in exec_args without options") |
| 214 | if options.paste: |
| 215 | paste = curtsies.events.PasteEvent() |
| 216 | encoding = inspection.get_encoding_file(exec_args[0]) |
| 217 | with open(exec_args[0], encoding=encoding) as f: |
| 218 | sourcecode = f.read() |
| 219 | paste.events.extend(sourcecode) |
| 220 | else: |
| 221 | try: |
| 222 | interp = Interp(locals=locals_) |
| 223 | bpargs.exec_code(interp, exec_args) |
| 224 | except SystemExit as e: |
| 225 | exit_value = e.args |
| 226 | if not options.interactive: |
| 227 | return extract_exit_value(exit_value) |
| 228 | else: |
| 229 | # expected for interactive sessions (vanilla python does it) |
| 230 | sys.path.insert(0, "") |
| 231 | |
| 232 | if not options.quiet: |
| 233 | print(bpargs.version_banner()) |
| 234 | if banner is not None: |
| 235 | print(banner) |
| 236 | if welcome_message is None and not options.quiet and config.help_key: |
no test coverage detected