jenkins-bot merged this change.
[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.