jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/432766 )
Change subject: [IMPR] Always import pywikibot in shell.py by default ......................................................................
[IMPR] Always import pywikibot in shell.py by default
- Don't import pywikibot if -noimport option is given - If additional options are given with -noimport print a message that they are ignored - If pywikibot is imported and arguments are given print a message that they are unknown if they couldn't be handled by handle_args
Bug: T194456 Change-Id: I19262a9e24ce5f0e8515353b1750bae0de83de12 --- M scripts/shell.py 1 file changed, 20 insertions(+), 6 deletions(-)
Approvals: Zhuyifei1999: Looks good to me, but someone else must approve Framawiki: Looks good to me, but someone else must approve Dvorapa: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/shell.py b/scripts/shell.py index 8b1ac12..b119a6c 100755 --- a/scripts/shell.py +++ b/scripts/shell.py @@ -1,7 +1,12 @@ #!/usr/bin/python # -*- coding: utf-8 -*- """ -Spawns an interactive Python shell. +Spawns an interactive Python shell and imports the pywikibot library. + +The following local option is supported: + +-noimport Do not import the pywikibot library. All other arguments are + ignored in this case.
Usage:
@@ -13,16 +18,25 @@ # # Distributed under the terms of the MIT license. # -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import, print_function, unicode_literals
def main(*args): """Script entry point.""" - env = None - if args: + args = list(args) + if '-noimport' in args: + args.remove('-noimport') + env = None + warn_type = 'Ignoring' + else: import pywikibot - pywikibot.handle_args(args) - env = locals() + args = pywikibot.handle_args(args) + env = {'pywikibot': pywikibot} + warn_type = 'Unknown' + + if args: + print('{} arguments: {}\n' # noqa: T001 + .format(warn_type, ', '.join(args)))
import code code.interact("""Welcome to the Pywikibot interactive shell!""", local=env)