#!/usr/bin/env python3"""Spawns an interactive Python shell and imports the pywikibot library.To exit the shell, type :kbd:`ctrl-D` (Linux) or :kbd:`ctrl-Z` (Windows)or use the :func:`exit` function.The following local option is supported:-noimport Do not import the pywikibot library. All other arguments are ignored in this case.Usage:: python pwb.py shell [args].. versionchanged:: 7.0 moved to pywikibot.scripts"""# (C) Pywikibot team, 2014-2024## Distributed under the terms of the MIT license.#from__future__importannotationsimportcodeimportsys
[docs]defmain(*args:str)->None:"""Script entry point. .. versionchanged:: 8.2 *exitmsg* was added for :func:`code.interact`. """args=list(args)if'-noimport'inargs:args.remove('-noimport')env=Nonewarn_type='Ignoring'else:importpywikibotargs=pywikibot.handle_args(args)env={'pywikibot':pywikibot}warn_type='Unknown'ifargs:print('{} arguments: {}\n'# noqa: T201.format(warn_type,', '.join(args)))# Various stuffs in Python 3.4+, such as history file.# This is defined in the site module of the Python Standard Library,# and usually called by the built-in CPython interactive shell.ifhasattr(sys,'__interactivehook__'):sys.__interactivehook__()code.interact('Welcome to the Pywikibot interactive shell!',local=env,exitmsg='Thank you for using Pywikibot; exiting now...\n')