jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/402653 )
Change subject: imagecopy: Raise Tkinter ImportError before the first call of it ......................................................................
imagecopy: Raise Tkinter ImportError before the first call of it
Raise `Tkinter` ImportError (if there's any) before the first call of `Tkinter` instead of raising it on the top of the module, so we don't get `Tkinter` ImportError when Tkinter fails to import when we import the `imagecopy` and `imagecopy_self` module, especially from the tests module.
Change-Id: Iaf9195fc0e7096f0c1fa15869f6e720a489545fb --- M scripts/imagecopy.py M scripts/imagecopy_self.py M tests/script_tests.py 3 files changed, 14 insertions(+), 19 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/imagecopy.py b/scripts/imagecopy.py index 377f3c6..9424c52 100644 --- a/scripts/imagecopy.py +++ b/scripts/imagecopy.py @@ -54,7 +54,7 @@ # # Another rewrite by: # (C) Multichill 2008-2011 -# (C) Pywikibot team, 2007-2017 +# (C) Pywikibot team, 2007-2018 # # Distributed under the terms of the MIT license. # @@ -76,18 +76,15 @@ from scripts import image
if not PY2: - import tkinter as Tkinter - from urllib.parse import urlencode from urllib.request import urlopen else: - import Tkinter - from urllib import urlencode, urlopen
try: - from pywikibot.userinterfaces.gui import Tkdialog + from pywikibot.userinterfaces.gui import Tkdialog, Tkinter except ImportError as _tk_error: + Tkinter = _tk_error Tkdialog = object
NL = '' @@ -383,6 +380,10 @@ def __init__(self, image_title, content, uploader, url, templates, commonsconflict=0): """Constructor.""" + # Check if `Tkinter` wasn't imported + if isinstance(Tkinter, ImportError): + raise Tkinter + super(TkdialogIC, self).__init__() self.root = Tkinter.Tk() # "%dx%d%+d%+d" % (width, height, xoffset, yoffset) diff --git a/scripts/imagecopy_self.py b/scripts/imagecopy_self.py index ab34888..dcbc8f1 100644 --- a/scripts/imagecopy_self.py +++ b/scripts/imagecopy_self.py @@ -44,7 +44,7 @@ # English Wikipedia specific bot by: # (C) Multichill 2010-2012 # -# (C) Pywikibot team, 2010-2017 +# (C) Pywikibot team, 2010-2018 # # Distributed under the terms of the MIT license. # @@ -66,17 +66,14 @@ from scripts import imagerecat, image
if not PY2: - import tkinter as Tkinter - from queue import Queue else: - import Tkinter - from Queue import Queue
try: - from pywikibot.userinterfaces.gui import Tkdialog + from pywikibot.userinterfaces.gui import Tkdialog, Tkinter except ImportError as _tk_error: + Tkinter = _tk_error Tkdialog = object
NL = '' @@ -694,6 +691,10 @@ categories """ """Constructor.""" + # Check if `Tkinter` wasn't imported + if isinstance(Tkinter, ImportError): + raise Tkinter + self.root = Tkinter.Tk() # "%dx%d%+d%+d" % (width, height, xoffset, yoffset) # Always appear the same size and in the bottom-left corner diff --git a/tests/script_tests.py b/tests/script_tests.py index 249ae42..77c516b 100644 --- a/tests/script_tests.py +++ b/tests/script_tests.py @@ -25,19 +25,12 @@
archive_path = join_root_path('scripts', 'archive')
-if PY2: - TK_IMPORT = 'Tkinter' -else: - TK_IMPORT = 'tkinter' - # These dependencies are not always the package name which is in setup.py. # e.g. 'PIL.ImageTk' is a object provided by several different pypi packages, # and setup.py requests that 'Pillow' is installed to provide 'PIL.ImageTk'. # Here, it doesnt matter which pypi package was requested and installed. # Here, the name given to the module which will be imported is required. script_deps = { - 'imagecopy': [TK_IMPORT], - 'imagecopy_self': [TK_IMPORT], 'script_wui': ['crontab', 'lua'], # Note: package 'lunatic-python' provides module 'lua' 'flickrripper': ['flickrapi'],
pywikibot-commits@lists.wikimedia.org