jenkins-bot has submitted this change and it was merged.
Change subject: use ImportWarning for missing package __init__ ......................................................................
use ImportWarning for missing package __init__
If a script is located in a directory without an __init__, a warning was printed on stderr. Script creators complained about this on pywikipedia-l, as stderr can be used to contain data to be piped to other processes.
Also add main().
Change-Id: Ia4aa8dab7203fa1498c0684759641d6ef7c8e139 --- M pwb.py 1 file changed, 12 insertions(+), 3 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py index b96b002..45415c0 100755 --- a/pwb.py +++ b/pwb.py @@ -28,6 +28,8 @@ import sys import types
+from warnings import warn + pwb = None
@@ -182,7 +184,9 @@ []) sys.exit(1)
-if __name__ == "__main__": + +def main(): + """Command line entry point.""" if len(sys.argv) > 1 and not re.match('-{1,2}help', sys.argv[1]): file_package = None tryimport_pwb() @@ -223,9 +227,14 @@ try: __import__(file_package) except ImportError as e: - print('Parent module %s not found: %s' - % (file_package, e), file=sys.stderr) + warn('Parent module %s not found: %s' + % (file_package, e), ImportWarning)
run_python_file(filename, argv, argvu, file_package) + return True else: + return False + +if __name__ == '__main__': + if not main(): print(__doc__)
pywikibot-commits@lists.wikimedia.org