jenkins-bot merged this change.

View Change

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
[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(-)

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)

To view, visit change 432766. To unsubscribe, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I19262a9e24ce5f0e8515353b1750bae0de83de12
Gerrit-Change-Number: 432766
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999@gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-Reviewer: jenkins-bot <>