jenkins-bot has submitted this change and it was merged.
Change subject: Re-order imports ......................................................................
Re-order imports
Use both OpenStack hacking H306 and flake8-import-order I201 to enforce the imports in each group are alphabetically sorted, and that whitespace is added between types of imports, respectively.
Change-Id: Id3ed6a443c9c14f08c59261ef1cc1727ac324a37 --- M pywikibot/__init__.py M pywikibot/comms/rcstream.py M pywikibot/compat/userlib.py M pywikibot/daemonize.py M pywikibot/data/api.py M pywikibot/data/wikidataquery.py M pywikibot/family.py M pywikibot/i18n.py M pywikibot/login.py M pywikibot/page.py M pywikibot/site.py M pywikibot/userinterfaces/gui.py M pywikibot/userinterfaces/terminal_interface_base.py M pywikibot/version.py M pywikibot/weblib.py M pywikibot/xmlreader.py M scripts/add_text.py M scripts/archivebot.py M scripts/blockpageschecker.py M scripts/blockreview.py M scripts/casechecker.py M scripts/category.py M scripts/category_redirect.py M scripts/checkimages.py M scripts/clean_sandbox.py M scripts/commons_link.py M scripts/data_ingestion.py M scripts/djvutext.py M scripts/editarticle.py M scripts/featured.py M scripts/imagecopy_self.py M scripts/imagerecat.py M scripts/interwiki.py M scripts/listpages.py M scripts/login.py M scripts/maintenance/cache.py M scripts/maintenance/compat2core.py M scripts/maintenance/make_i18n_dict.py M scripts/maintenance/wikimedia_sites.py M scripts/makecat.py M scripts/match_images.py M scripts/misspelling.py M scripts/movepages.py M scripts/newitem.py M scripts/pagefromfile.py M scripts/patrol.py M scripts/redirect.py M scripts/reflinks.py M scripts/replace.py M scripts/replicate_wiki.py M scripts/revertbot.py M scripts/script_wui.py M scripts/spamremove.py M scripts/states_redirect.py M scripts/template.py M scripts/templatecount.py M scripts/touch.py M scripts/upload.py M scripts/version.py M scripts/watchlist.py M scripts/weblinkchecker.py M scripts/welcome.py M tests/__init__.py M tests/aspects.py M tests/cache_tests.py M tests/data_ingestion_tests.py M tests/djvu_tests.py M tests/edit_tests.py M tests/interwiki_link_tests.py M tests/interwikidata_tests.py M tests/oauth_tests.py M tests/page_tests.py M tests/proofreadpage_tests.py M tests/pwb/print_env.py M tests/replacebot_tests.py M tests/site_tests.py M tests/thread_tests.py M tests/timestripper_tests.py M tests/uploadbot_tests.py M tests/utils.py M tests/wikibase_edit_tests.py M tests/wikibase_tests.py M tests/wikidataquery_tests.py M tox.ini 84 files changed, 272 insertions(+), 163 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index 7c83b5f..343f1bb 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -11,11 +11,13 @@ __version__ = '$Id$' __url__ = 'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Pywikibot'
+import atexit import datetime import math import re import sys import threading + from decimal import Decimal
if sys.version_info[0] > 2: @@ -33,6 +35,7 @@ )
from pywikibot import config2 as config + from pywikibot.bot import ( input, input_choice, input_yn, inputChoice, handle_args, showHelp, ui, calledModuleName, Bot, CurrentPageBot, WikidataBot, @@ -729,7 +732,6 @@ except IndexError: pass
-import atexit atexit.register(stopme)
diff --git a/pywikibot/comms/rcstream.py b/pywikibot/comms/rcstream.py index f6bc183..4a04189 100644 --- a/pywikibot/comms/rcstream.py +++ b/pywikibot/comms/rcstream.py @@ -19,6 +19,11 @@ else: from Queue import Queue, Empty
+try: + import socketIO_client +except ImportError as e: + socketIO_client = e + from pywikibot.bot import debug, warning
_logger = 'pywikibot.rcstream' @@ -77,7 +82,6 @@ self.total = total self.count = 0
- import socketIO_client debug('Opening connection to %r' % self, _logger) self.client = socketIO_client.SocketIO(rchost, rcport)
@@ -166,13 +170,7 @@ [1]: See mediawiki/includes/rcfeed/MachineReadableRCFeedFormatter.php
""" - try: - # this is just to test whether socketIO_client is installed or not, - # as the ImportError would otherwise pop up in the worker thread - # where it's not easily caught. We don't use it, so we silence - # flake8 with noqa. - import socketIO_client # noqa - except ImportError: + if isinstance(socketIO_client, Exception): raise ImportError('socketIO_client is required for the rc stream; ' 'install it with pip install socketIO_client')
diff --git a/pywikibot/compat/userlib.py b/pywikibot/compat/userlib.py index fe7d17f..07dbaa5 100644 --- a/pywikibot/compat/userlib.py +++ b/pywikibot/compat/userlib.py @@ -16,7 +16,7 @@ __version__ = '$Id$'
-from pywikibot import User +from pywikibot.page import User from pywikibot.tools import ModuleDeprecationWrapper
__all__ = ('User',) diff --git a/pywikibot/daemonize.py b/pywikibot/daemonize.py index 702ae7b..af5b323 100644 --- a/pywikibot/daemonize.py +++ b/pywikibot/daemonize.py @@ -9,9 +9,9 @@
__version__ = '$Id$'
+import codecs import os import sys -import codecs
is_daemon = False
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index bf3c944..86cf089 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -9,34 +9,37 @@
__version__ = '$Id$'
-from collections import Container, MutableMapping -from email.mime.nonmultipart import MIMENonMultipart import datetime import hashlib import inspect import json import os +import pprint +import re +import time +import traceback + +from collections import Container, MutableMapping +from email.mime.nonmultipart import MIMENonMultipart +from warnings import warn + try: import cPickle as pickle except ImportError: import pickle -import pprint -import re -import traceback -import time - -from warnings import warn
import pywikibot + from pywikibot import config, login + +from pywikibot.comms import http +from pywikibot.exceptions import ( + Server504Error, Server414Error, FatalServerError, NoUsername, Error +) from pywikibot.tools import ( MediaWikiVersion, deprecated, itergroup, ip, PY2, getargspec, ) from pywikibot.tools.formatter import color_format -from pywikibot.exceptions import ( - Server504Error, Server414Error, FatalServerError, NoUsername, Error -) -from pywikibot.comms import http
if not PY2: # Subclassing necessary to fix a possible bug of the email package diff --git a/pywikibot/data/wikidataquery.py b/pywikibot/data/wikidataquery.py index a2e39db..9772706 100644 --- a/pywikibot/data/wikidataquery.py +++ b/pywikibot/data/wikidataquery.py @@ -6,23 +6,26 @@ # Distributed under the terms of the MIT license. from __future__ import absolute_import, unicode_literals
+import hashlib import json +import os +import pickle import sys +import tempfile +import time + if sys.version_info[0] > 2: from urllib.parse import quote basestring = (str, ) else: from urllib2 import quote -import pickle -import os -import hashlib -import time -import tempfile
import pywikibot + from pywikibot.comms import http -from pywikibot.page import ItemPage, PropertyPage, Claim + from pywikibot import config +from pywikibot.page import ItemPage, PropertyPage, Claim
def listify(x): diff --git a/pywikibot/family.py b/pywikibot/family.py index ec2fcae..4fe4b47 100644 --- a/pywikibot/family.py +++ b/pywikibot/family.py @@ -10,12 +10,12 @@ __version__ = '$Id$' #
-import sys -import logging -import re import collections import imp +import logging +import re import string +import sys import warnings
if sys.version_info[0] > 2: @@ -27,12 +27,13 @@
import pywikibot
-from pywikibot import config2 as config +from pywikibot import config + +from pywikibot.exceptions import UnknownFamily, FamilyMaintenanceWarning from pywikibot.tools import ( deprecated, deprecated_args, issue_deprecation_warning, FrozenDict, ) -from pywikibot.exceptions import UnknownFamily, FamilyMaintenanceWarning
logger = logging.getLogger("pywiki.wiki.family")
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py index 7259abd..fa60f4b 100644 --- a/pywikibot/i18n.py +++ b/pywikibot/i18n.py @@ -26,11 +26,11 @@ __version__ = '$Id$' #
-import re -import locale import json +import locale import os import pkgutil +import re
from collections import defaultdict, Mapping from warnings import warn @@ -38,8 +38,8 @@ import pywikibot
from pywikibot import __url__ -from pywikibot import Error from pywikibot import config +from pywikibot.exceptions import Error from pywikibot.plural import plural_rules from pywikibot.tools import deprecated, issue_deprecation_warning, StringTypes
diff --git a/pywikibot/login.py b/pywikibot/login.py index af995fc..2463a7f 100644 --- a/pywikibot/login.py +++ b/pywikibot/login.py @@ -26,8 +26,8 @@ import pywikibot
from pywikibot import config -from pywikibot.tools import deprecated_args, normalize_username from pywikibot.exceptions import NoUsername +from pywikibot.tools import deprecated_args, normalize_username
class OAuthImpossible(ImportError): diff --git a/pywikibot/page.py b/pywikibot/page.py index d1ea5bc..be4e146 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -47,9 +47,9 @@ import pywikibot
from pywikibot import config +from pywikibot import textlib + from pywikibot.comms import http -from pywikibot.family import Family -from pywikibot.site import Namespace from pywikibot.exceptions import ( AutoblockUser, _EmailUserError, @@ -57,6 +57,8 @@ SiteDefinitionError, UserRightsError, ) +from pywikibot.family import Family +from pywikibot.site import Namespace from pywikibot.tools import ( PYTHON_VERSION, PY2, MediaWikiVersion, UnicodeMixin, ComparableMixin, DotReadableDict, @@ -67,7 +69,6 @@ ) from pywikibot.tools.ip import ip_regexp # noqa & deprecated from pywikibot.tools.ip import is_IP -from pywikibot import textlib
logger = logging.getLogger("pywiki.wiki.page") diff --git a/pywikibot/site.py b/pywikibot/site.py index 54c40d9..98ab01f 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -15,36 +15,28 @@ __version__ = '$Id$' #
+import copy import datetime +import functools import hashlib import itertools -import functools +import json +import mimetypes import os import re import sys import threading import time -import json -import copy -import mimetypes
from collections import Iterable, Container, namedtuple, Mapping from warnings import warn
import pywikibot import pywikibot.family -from pywikibot.tools import ( - itergroup, UnicodeMixin, ComparableMixin, SelfCallMixin, SelfCallString, - deprecated, deprecate_arg, deprecated_args, remove_last_args, - redirect_func, issue_deprecation_warning, - manage_wrapping, MediaWikiVersion, first_upper, normalize_username, - merge_unique_dicts, - PY2, -) + from pywikibot.comms.http import get_authentication -from pywikibot.tools.ip import is_IP -from pywikibot.throttle import Throttle from pywikibot.data import api +from pywikibot.echo import Notification from pywikibot.exceptions import ( Error, PageRelatedError, @@ -69,18 +61,27 @@ UserBlocked, EntityTypeUnknownException, ) - -from pywikibot.echo import Notification +from pywikibot.throttle import Throttle +from pywikibot.tools import ( + itergroup, UnicodeMixin, ComparableMixin, SelfCallMixin, SelfCallString, + deprecated, deprecate_arg, deprecated_args, remove_last_args, + redirect_func, issue_deprecation_warning, + manage_wrapping, MediaWikiVersion, first_upper, normalize_username, + merge_unique_dicts, + PY2, +) +from pywikibot.tools.ip import is_IP
if sys.version_info[0] > 2: + from itertools import zip_longest from urllib.parse import urlencode, urlparse + basestring = (str,) unicode = str - from itertools import zip_longest else: + from itertools import izip_longest as zip_longest from urllib import urlencode from urlparse import urlparse - from itertools import izip_longest as zip_longest
_logger = "wiki.site" diff --git a/pywikibot/userinterfaces/gui.py b/pywikibot/userinterfaces/gui.py index 3936713..2186e71 100644 --- a/pywikibot/userinterfaces/gui.py +++ b/pywikibot/userinterfaces/gui.py @@ -18,15 +18,17 @@ #
import sys + if sys.version_info[0] > 2: import tkinter as Tkinter from tkinter.scrolledtext import ScrolledText from tkinter import simpledialog as tkSimpleDialog else: import Tkinter - from ScrolledText import ScrolledText import tkSimpleDialog
+ from ScrolledText import ScrolledText + from idlelib import SearchDialog, ReplaceDialog, configDialog from idlelib.configHandler import idleConf from idlelib.MultiCall import MultiCallCreator diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py index 3049041..4540e2c 100755 --- a/pywikibot/userinterfaces/terminal_interface_base.py +++ b/pywikibot/userinterfaces/terminal_interface_base.py @@ -14,6 +14,7 @@ import math import re import sys +import threading
import pywikibot
@@ -473,7 +474,6 @@ """
# create a class-level lock that can be shared by all instances - import threading sharedlock = threading.RLock()
def __init__(self, UI, strm=None): diff --git a/pywikibot/version.py b/pywikibot/version.py index 5ac6e1d..66f5ff9 100644 --- a/pywikibot/version.py +++ b/pywikibot/version.py @@ -12,16 +12,16 @@ __version__ = '$Id$' #
+import codecs +import datetime import os +import subprocess import sys import time -import datetime -import subprocess -import codecs import xml.dom.minidom
+from distutils.sysconfig import get_python_lib from io import BytesIO - from warnings import warn
try: @@ -477,8 +477,7 @@ if not modules: modules = sys.modules.keys()
- import distutils.sysconfig - std_lib_dir = distutils.sysconfig.get_python_lib(standard_lib=True) + std_lib_dir = get_python_lib(standard_lib=True)
root_packages = set([key.split('.')[0] for key in modules]) diff --git a/pywikibot/weblib.py b/pywikibot/weblib.py index 60f99e1..df8a7b5 100644 --- a/pywikibot/weblib.py +++ b/pywikibot/weblib.py @@ -9,7 +9,9 @@
__version__ = '$Id$'
+import json import sys +import xml.etree.ElementTree as ET
if sys.version_info[0] > 2: from urllib.parse import urlencode @@ -32,7 +34,6 @@ moment is returned. Format: YYYYMMDDhhmmss or part thereof.
""" - import json uri = u'https://archive.org/wayback/available?'
query = {'url': url} @@ -61,7 +62,6 @@ moment is returned. Format: YYYYMMDDhhmmss or part thereof.
""" - import xml.etree.ElementTree as ET uri = u'http://www.webcitation.org/query?'
query = {'returnxml': 'true', diff --git a/pywikibot/xmlreader.py b/pywikibot/xmlreader.py index 216e3aa..cb47bc8 100644 --- a/pywikibot/xmlreader.py +++ b/pywikibot/xmlreader.py @@ -18,9 +18,11 @@ __version__ = '$Id$' #
-import threading import re +import threading + from xml.etree.cElementTree import iterparse + import xml.sax
from pywikibot.tools import open_archive diff --git a/scripts/add_text.py b/scripts/add_text.py index 9c13048..bfe9365 100755 --- a/scripts/add_text.py +++ b/scripts/add_text.py @@ -73,11 +73,12 @@ __version__ = '$Id$' #
-import re import codecs +import re import time
import pywikibot + from pywikibot import config, i18n, pagegenerators, textlib from pywikibot.tools.formatter import color_format
diff --git a/scripts/archivebot.py b/scripts/archivebot.py index 069e986..d87e72c 100755 --- a/scripts/archivebot.py +++ b/scripts/archivebot.py @@ -97,14 +97,16 @@ __version__ = '$Id$' # import datetime -import time +import locale import os import re -import locale +import time + from hashlib import md5 from math import ceil
import pywikibot + from pywikibot import i18n from pywikibot.textlib import TimeStripper from pywikibot.textlib import to_local_digits diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py index 20de823..73262ba 100755 --- a/scripts/blockpageschecker.py +++ b/scripts/blockpageschecker.py @@ -59,14 +59,15 @@ __version__ = '$Id$' #
-import time import re +import time import webbrowser
import pywikibot + +from pywikibot import config from pywikibot import i18n from pywikibot import pagegenerators -from pywikibot import config from pywikibot.tools.formatter import color_format
# This is required for the text that is shown when you run this script diff --git a/scripts/blockreview.py b/scripts/blockreview.py index 5e3261b..599e1d0 100755 --- a/scripts/blockreview.py +++ b/scripts/blockreview.py @@ -25,7 +25,10 @@ #
import pywikibot + from pywikibot import i18n +from pywikibot import pagegenerators as pg + from pywikibot.tools.formatter import color_format
@@ -147,7 +150,6 @@ # test for pt-wiki # just print all sysops talk pages elif self.site.sitename == 'wikipedia:pt': - from pywikibot import pagegenerators as pg gen = pg.PreloadingGenerator(self.SysopGenerator()) for sysop in gen: print(sysop.title()) diff --git a/scripts/casechecker.py b/scripts/casechecker.py index 1a58aab..d1858de 100755 --- a/scripts/casechecker.py +++ b/scripts/casechecker.py @@ -17,6 +17,7 @@ import pywikibot
from pywikibot import i18n + from pywikibot.data import api from pywikibot.tools import first_lower, first_upper
diff --git a/scripts/category.py b/scripts/category.py index cf7308b..f2ae4d0 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -119,12 +119,14 @@ __version__ = '$Id$' #
+import codecs import os -import re import pickle +import re import sys
import pywikibot + from pywikibot import config, pagegenerators from pywikibot import i18n, textlib from pywikibot.bot import ( @@ -1069,7 +1071,6 @@ pywikibot.output(u'') if self.filename: pywikibot.output(u'Saving results in %s' % self.filename) - import codecs f = codecs.open(self.filename, 'a', 'utf-8') f.write(tree) f.close() diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py index 9d78f7d..7305b76 100755 --- a/scripts/category_redirect.py +++ b/scripts/category_redirect.py @@ -31,11 +31,14 @@
__version__ = '$Id$' # -import sys import re +import sys import time + from datetime import timedelta + import pywikibot + from pywikibot import i18n, pagegenerators, config
if sys.version_info[0] > 2: diff --git a/scripts/checkimages.py b/scripts/checkimages.py index 58ae4c4..0e752e5 100755 --- a/scripts/checkimages.py +++ b/scripts/checkimages.py @@ -94,8 +94,8 @@
import pywikibot
-from pywikibot import pagegenerators as pg from pywikibot import i18n +from pywikibot import pagegenerators as pg
from pywikibot.exceptions import NotEmailableError from pywikibot.family import Family diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py index 590db4b..6dfe4e1 100755 --- a/scripts/clean_sandbox.py +++ b/scripts/clean_sandbox.py @@ -39,9 +39,11 @@ __version__ = '$Id$' #
-import time import datetime +import time + import pywikibot + from pywikibot import i18n, Bot, pagegenerators
content = { diff --git a/scripts/commons_link.py b/scripts/commons_link.py index d74b844..f00c3fd 100755 --- a/scripts/commons_link.py +++ b/scripts/commons_link.py @@ -36,7 +36,9 @@ __version__ = '$Id$'
import re + import pywikibot + from pywikibot import textlib, pagegenerators, i18n, Bot
docuReplacements = { diff --git a/scripts/data_ingestion.py b/scripts/data_ingestion.py index c77f393..68f6880 100755 --- a/scripts/data_ingestion.py +++ b/scripts/data_ingestion.py @@ -36,6 +36,7 @@ import pywikibot
from pywikibot import pagegenerators + from pywikibot.comms.http import fetch from pywikibot.tools import deprecated, deprecated_args
diff --git a/scripts/djvutext.py b/scripts/djvutext.py index bdf442a..806b99f 100644 --- a/scripts/djvutext.py +++ b/scripts/djvutext.py @@ -41,9 +41,10 @@ import pywikibot
from pywikibot import i18n + from pywikibot.bot import SingleSiteBot -from pywikibot.tools.djvu import DjVuFile from pywikibot.proofreadpage import ProofreadPage +from pywikibot.tools.djvu import DjVuFile
class DjVuTextBot(SingleSiteBot): diff --git a/scripts/editarticle.py b/scripts/editarticle.py index 1762fa8..44803f4 100755 --- a/scripts/editarticle.py +++ b/scripts/editarticle.py @@ -32,13 +32,15 @@ __version__ = '$Id$' #
+import argparse import os import sys -import argparse import tempfile
import pywikibot + from pywikibot import i18n + from pywikibot.editor import TextEditor
diff --git a/scripts/featured.py b/scripts/featured.py index 6fc81ee..c49a5dc 100755 --- a/scripts/featured.py +++ b/scripts/featured.py @@ -69,10 +69,12 @@ import pickle import re import sys + import pywikibot + from pywikibot import i18n, textlib, config + from pywikibot.pagegenerators import PreloadingGenerator -from pywikibot.config2 import LS # line separator from pywikibot.tools.formatter import color_format
if sys.version_info[0] > 2: @@ -578,8 +580,8 @@ # Moving {{Link FA|xx}} to top of interwikis iw = textlib.getLanguageLinks(text, tosite) text = textlib.removeLanguageLinks(text, tosite) - text += u"%s{{%s|%s}}%s" % (LS, add_tl[0], - fromsite.code, LS) + text += u"%s{{%s|%s}}%s" % (config.LS, add_tl[0], + fromsite.code, config.LS) text = textlib.replaceLanguageLinks(text, iw, tosite) changed = True diff --git a/scripts/imagecopy_self.py b/scripts/imagecopy_self.py index d385a7f..18480f5 100644 --- a/scripts/imagecopy_self.py +++ b/scripts/imagecopy_self.py @@ -69,9 +69,11 @@
if not PY2: import tkinter as Tkinter + from queue import Queue else: import Tkinter + from Queue import Queue
try: diff --git a/scripts/imagerecat.py b/scripts/imagerecat.py index 39cd2d0..30fd9bf 100755 --- a/scripts/imagerecat.py +++ b/scripts/imagerecat.py @@ -37,12 +37,13 @@ #
import re -import time import socket -import xml.etree.ElementTree import sys +import time +import xml.etree.ElementTree
import pywikibot + from pywikibot import pagegenerators, textlib from pywikibot.comms.http import fetch
diff --git a/scripts/interwiki.py b/scripts/interwiki.py index 5cd4406..fb20f58 100755 --- a/scripts/interwiki.py +++ b/scripts/interwiki.py @@ -347,19 +347,21 @@ __version__ = '$Id$' #
-import sys -import re -import os -import time -import datetime import codecs +import datetime +import os import pickle +import re +import shelve import socket +import sys +import time
import pywikibot
from pywikibot import config, i18n, pagegenerators, textlib, interwiki_graph from pywikibot import titletranslate + from pywikibot.bot import ListOption, StandardOption from pywikibot.tools import first_upper from pywikibot.tools.formatter import color_format @@ -680,7 +682,6 @@ setattr(self, attr, getattr(page, attr))
if not StoredPage.SPpath: - import shelve index = 1 while True: path = config.datafilepath('cache', 'pagestore' + str(index)) diff --git a/scripts/listpages.py b/scripts/listpages.py index d519835..8c3c8f7 100755 --- a/scripts/listpages.py +++ b/scripts/listpages.py @@ -92,8 +92,8 @@ __version__ = '$Id$' #
-import re import os +import re
import pywikibot from pywikibot import config2 as config, i18n diff --git a/scripts/login.py b/scripts/login.py index 4350dc4..a980ce3 100755 --- a/scripts/login.py +++ b/scripts/login.py @@ -62,11 +62,14 @@ __version__ = '$Id$' #
-import pywikibot from os.path import join + +import pywikibot + from pywikibot import config -from pywikibot.login import OauthLoginManager + from pywikibot.exceptions import SiteDefinitionError +from pywikibot.login import OauthLoginManager
def _get_consumer_token(site): diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py index d87f543..daf92cf 100755 --- a/scripts/maintenance/cache.py +++ b/scripts/maintenance/cache.py @@ -67,15 +67,17 @@ __version__ = '$Id$' #
-import os import datetime -import pickle import hashlib +import os +import pickle + import pywikibot + from pywikibot.data import api
-from pywikibot.site import APISite, DataSite, LoginStatus # noqa from pywikibot.page import User # noqa +from pywikibot.site import APISite, DataSite, LoginStatus # noqa
class ParseError(Exception): diff --git a/scripts/maintenance/compat2core.py b/scripts/maintenance/compat2core.py index ed1f1bd..a3b0168 100755 --- a/scripts/maintenance/compat2core.py +++ b/scripts/maintenance/compat2core.py @@ -35,9 +35,10 @@ __version__ = '$Id$' #
+import codecs import os import re -import codecs + import pywikibot
# be careful with replacement order! diff --git a/scripts/maintenance/make_i18n_dict.py b/scripts/maintenance/make_i18n_dict.py index 5f2150b..2283bdf 100755 --- a/scripts/maintenance/make_i18n_dict.py +++ b/scripts/maintenance/make_i18n_dict.py @@ -36,9 +36,9 @@ __version__ = '$Id$' #
-import os -import json import codecs +import json +import os
from pywikibot import config
diff --git a/scripts/maintenance/wikimedia_sites.py b/scripts/maintenance/wikimedia_sites.py index f627f3c..d26c958 100755 --- a/scripts/maintenance/wikimedia_sites.py +++ b/scripts/maintenance/wikimedia_sites.py @@ -12,12 +12,14 @@ __version__ = '$Id$' #
-import re import codecs -from xml.etree import cElementTree +import re import sys
+from xml.etree import cElementTree + import pywikibot + from pywikibot.family import Family
if sys.version_info[0] > 2: diff --git a/scripts/makecat.py b/scripts/makecat.py index 3417c61..217e31b 100755 --- a/scripts/makecat.py +++ b/scripts/makecat.py @@ -42,10 +42,13 @@ __version__ = '$Id$' #
-import sys import codecs +import sys + import pywikibot + from pywikibot import pagegenerators, i18n, textlib + from pywikibot.tools import DequeGenerator
diff --git a/scripts/match_images.py b/scripts/match_images.py index b855f94..296f336 100755 --- a/scripts/match_images.py +++ b/scripts/match_images.py @@ -33,11 +33,12 @@ from __future__ import absolute_import, division, unicode_literals __version__ = '$Id$'
- import io + from PIL import Image
import pywikibot + from pywikibot.comms import http
diff --git a/scripts/misspelling.py b/scripts/misspelling.py index c54ccc0..3551f2a 100755 --- a/scripts/misspelling.py +++ b/scripts/misspelling.py @@ -34,6 +34,7 @@ import pywikibot
from pywikibot import i18n, pagegenerators + from pywikibot.tools import PY2
from scripts.solve_disambiguation import DisambiguationRobot diff --git a/scripts/movepages.py b/scripts/movepages.py index b28ff40..00336b7 100755 --- a/scripts/movepages.py +++ b/scripts/movepages.py @@ -44,8 +44,11 @@ #
import re + import pywikibot + from pywikibot import i18n, pagegenerators + from pywikibot.bot import MultipleSitesBot
# This is required for the text that is shown when you run this script diff --git a/scripts/newitem.py b/scripts/newitem.py index a4be270..c8f2700 100755 --- a/scripts/newitem.py +++ b/scripts/newitem.py @@ -29,10 +29,12 @@ __version__ = '$Id$' #
-import pywikibot -from pywikibot import pagegenerators, WikidataBot from datetime import timedelta
+import pywikibot + +from pywikibot import pagegenerators, WikidataBot +
class NewItemRobot(WikidataBot):
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py index 38d4fe3..f5fbd9d 100755 --- a/scripts/pagefromfile.py +++ b/scripts/pagefromfile.py @@ -66,12 +66,14 @@ __version__ = '$Id$' #
+import codecs import os import re -import codecs + from warnings import warn
import pywikibot + from pywikibot import config, Bot, i18n from pywikibot.exceptions import ArgumentDeprecationWarning
diff --git a/scripts/patrol.py b/scripts/patrol.py index 1f4b5b8..9c57bf2 100755 --- a/scripts/patrol.py +++ b/scripts/patrol.py @@ -55,6 +55,7 @@ import pywikibot
from pywikibot import pagegenerators + from pywikibot.bot import SingleSiteBot
_logger = 'patrol' diff --git a/scripts/redirect.py b/scripts/redirect.py index 9084e2d..a968711 100755 --- a/scripts/redirect.py +++ b/scripts/redirect.py @@ -81,9 +81,11 @@ __version__ = '$Id$' #
-import sys import datetime +import sys + import pywikibot + from pywikibot import i18n, xmlreader, Bot from pywikibot.tools.formatter import color_format
diff --git a/scripts/reflinks.py b/scripts/reflinks.py index 435b10c..df99205 100755 --- a/scripts/reflinks.py +++ b/scripts/reflinks.py @@ -46,15 +46,15 @@ __version__ = '$Id$' #
+import codecs +import gzip +import io +import os import re import socket -import codecs import subprocess -import tempfile -import os -import gzip import sys -import io +import tempfile
from functools import partial
diff --git a/scripts/replace.py b/scripts/replace.py index da09945..ddfef30 100755 --- a/scripts/replace.py +++ b/scripts/replace.py @@ -140,13 +140,14 @@ import codecs import collections import re -import time import sys +import time import warnings
import pywikibot
from pywikibot import i18n, textlib, pagegenerators, Bot + from pywikibot import editor as editarticle
# Imports predefined replacements tasks from fixes.py diff --git a/scripts/replicate_wiki.py b/scripts/replicate_wiki.py index 7ab9444..97aa610 100755 --- a/scripts/replicate_wiki.py +++ b/scripts/replicate_wiki.py @@ -49,6 +49,8 @@
import sys
+from argparse import ArgumentParser + import pywikibot
from pywikibot import config, Page @@ -232,8 +234,6 @@
def main(*args): - from argparse import ArgumentParser - my_args = pywikibot.handle_args(args)
parser = ArgumentParser(add_help=False) diff --git a/scripts/revertbot.py b/scripts/revertbot.py index 1f677a1..6a47536 100755 --- a/scripts/revertbot.py +++ b/scripts/revertbot.py @@ -27,9 +27,12 @@ #
import re + import pywikibot + from pywikibot import i18n from pywikibot import pagegenerators + from pywikibot.tools.formatter import color_format
docuReplacements = { diff --git a/scripts/script_wui.py b/scripts/script_wui.py index 217a328..a5d9df5 100755 --- a/scripts/script_wui.py +++ b/scripts/script_wui.py @@ -64,21 +64,24 @@ __version__ = '$Id$' #
- import datetime -import threading -import sys -import os -import traceback import gc -import resource +import logging +import os import re +import resource +import sys +import threading +import traceback + +from io import StringIO
# https://labix.org/lunatic-python is bit-rotting, and there are maintained # versions on github: # https://github.com/bastibe/lunatic-python.git # https://github.com/AlereDevices/lunatic-python.git import lua + # The crontab package is https://github.com/josiahcarlson/parse-crontab # version 0.20 installs a package called 'tests' which conflicts with our # test suite. The patch to fix this has been merged, but is not released. @@ -88,6 +91,7 @@ import pywikibot # pywikibot.botirc depends on https://pypi.python.org/pypi/irc import pywikibot.botirc + from pywikibot.tools.formatter import color_format
if sys.version_info[0] > 2: @@ -218,9 +222,6 @@ def main_script(page, rev=None, params=NotImplemented): # pylint: disable=unused-argument """Main thread.""" # http://opensourcehacker.com/2011/02/23/temporarily-capturing-python-logging-... - # https://docs.python.org/release/2.6/library/logging.html - from io import StringIO - import logging
# safety; default mode is safe (no writing) pywikibot.config.simulate = True diff --git a/scripts/spamremove.py b/scripts/spamremove.py index 0a8044d..246e5c1 100755 --- a/scripts/spamremove.py +++ b/scripts/spamremove.py @@ -34,7 +34,9 @@ #
import pywikibot + from pywikibot import i18n + from pywikibot.editor import TextEditor from pywikibot.tools.formatter import color_format
diff --git a/scripts/states_redirect.py b/scripts/states_redirect.py index 5318979..4b29eea 100755 --- a/scripts/states_redirect.py +++ b/scripts/states_redirect.py @@ -26,7 +26,9 @@
import re import sys + import pywikibot + from pywikibot import i18n
try: diff --git a/scripts/template.py b/scripts/template.py index 27cd99a..6aa9563 100755 --- a/scripts/template.py +++ b/scripts/template.py @@ -119,6 +119,7 @@ import pywikibot
from pywikibot import i18n, pagegenerators, Bot + from pywikibot.exceptions import ArgumentDeprecationWarning from pywikibot.pagegenerators import XMLDumpPageGenerator
diff --git a/scripts/templatecount.py b/scripts/templatecount.py index a5cf3c8..7f50cfe 100755 --- a/scripts/templatecount.py +++ b/scripts/templatecount.py @@ -41,6 +41,7 @@ __version__ = '$Id$'
import datetime + import pywikibot
templates = ['ref', 'note', 'ref label', 'note label', 'reflist'] diff --git a/scripts/touch.py b/scripts/touch.py index c9162e2..cc59ca7 100755 --- a/scripts/touch.py +++ b/scripts/touch.py @@ -25,7 +25,9 @@ #
import pywikibot + from pywikibot import pagegenerators + from pywikibot.bot import MultipleSitesBot
docuReplacements = {'¶ms;': pagegenerators.parameterHelp} diff --git a/scripts/upload.py b/scripts/upload.py index ce7032a..3f9935d 100755 --- a/scripts/upload.py +++ b/scripts/upload.py @@ -56,16 +56,18 @@ __version__ = '$Id$' #
-import os -import time -import tempfile -import re import math +import os +import re import sys +import tempfile +import time
import pywikibot import pywikibot.data.api + from pywikibot import config + from pywikibot.bot import suggest_help, BaseBot from pywikibot.tools import ( deprecated @@ -75,10 +77,11 @@ if sys.version_info[0] > 2: from urllib.parse import urlparse from urllib.request import URLopener + basestring = (str,) else: - from urlparse import urlparse from urllib import URLopener + from urlparse import urlparse
class UploadRobot(BaseBot): diff --git a/scripts/version.py b/scripts/version.py index 87f6a29..dbb1dd4 100755 --- a/scripts/version.py +++ b/scripts/version.py @@ -13,11 +13,14 @@ __version__ = '$Id$' #
-import sys -import os import codecs +import os +import sys + import pywikibot + from pywikibot.version import getversion + try: import requests except ImportError: diff --git a/scripts/watchlist.py b/scripts/watchlist.py index 8e2e6f5..73a1ba7 100755 --- a/scripts/watchlist.py +++ b/scripts/watchlist.py @@ -27,9 +27,13 @@ #
import os + import pywikibot + from pywikibot import config + from pywikibot.data.api import CachedRequest + from scripts.maintenance.cache import CacheEntry
diff --git a/scripts/weblinkchecker.py b/scripts/weblinkchecker.py index 015f108..86c0da7 100755 --- a/scripts/weblinkchecker.py +++ b/scripts/weblinkchecker.py @@ -99,14 +99,14 @@
__version__ = '$Id$'
-import re import codecs import datetime import pickle +import re import socket +import sys import threading import time -import sys
from functools import partial from warnings import warn @@ -119,6 +119,7 @@ import pywikibot
from pywikibot import i18n, config, pagegenerators, textlib, weblib + from pywikibot.bot import ExistingPageBot, SingleSiteBot from pywikibot.pagegenerators import ( XMLDumpPageGenerator as _XMLDumpPageGenerator, @@ -127,15 +128,16 @@
# TODO: Convert to httlib2 if sys.version_info[0] > 2: + import http.client as httplib import urllib.parse as urlparse import urllib.request as urllib - import http.client as httplib + basestring = (str, ) unicode = str else: - import urlparse - import urllib import httplib + import urllib + import urlparse
docuReplacements = { '¶ms;': pagegenerators.parameterHelp diff --git a/scripts/welcome.py b/scripts/welcome.py index de433ec..11224e7 100755 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -183,15 +183,18 @@ __version__ = '$Id$' #
-import time -import re -import locale import codecs -from random import choice +import locale +import re import sys +import time + +from random import choice + import pywikibot -from pywikibot import i18n + from pywikibot import config +from pywikibot import i18n
if sys.version_info[0] > 2: unicode = str diff --git a/tests/__init__.py b/tests/__init__.py index 5f3b16e..4ed946b 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -37,8 +37,9 @@
from pywikibot import config from pywikibot import i18n -from pywikibot.data.api import Request as _original_Request + from pywikibot.data.api import CachedRequest +from pywikibot.data.api import Request as _original_Request
_root_dir = os.path.split(os.path.split(__file__)[0])[0]
diff --git a/tests/aspects.py b/tests/aspects.py index 4b9035c..5b2670a 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -44,6 +44,7 @@ import pywikibot.config2 as config
from pywikibot import Site + from pywikibot.comms import http from pywikibot.data.api import Request as _original_Request from pywikibot.exceptions import ServerError, NoUsername diff --git a/tests/cache_tests.py b/tests/cache_tests.py index e4161f8..5d5c7b6 100644 --- a/tests/cache_tests.py +++ b/tests/cache_tests.py @@ -11,6 +11,7 @@ #
from pywikibot.site import BaseSite + import scripts.maintenance.cache as cache
from tests import join_cache_path diff --git a/tests/data_ingestion_tests.py b/tests/data_ingestion_tests.py index 16c3ea5..d9ec3f3 100644 --- a/tests/data_ingestion_tests.py +++ b/tests/data_ingestion_tests.py @@ -10,9 +10,10 @@
__version__ = '$Id$'
+from scripts import data_ingestion + from tests import join_data_path, join_images_path from tests.aspects import unittest, TestCase, ScriptMainTestCase -from scripts import data_ingestion
class TestPhoto(TestCase): diff --git a/tests/djvu_tests.py b/tests/djvu_tests.py index 5d8da3e..e256fca 100644 --- a/tests/djvu_tests.py +++ b/tests/djvu_tests.py @@ -12,9 +12,10 @@
import subprocess
+from pywikibot.tools.djvu import DjVuFile + from tests import join_data_path, create_path_func from tests.aspects import unittest, TestCase -from pywikibot.tools.djvu import DjVuFile
join_djvu_data_path = create_path_func(join_data_path, 'djvu')
diff --git a/tests/edit_tests.py b/tests/edit_tests.py index a45134a..5333eb8 100644 --- a/tests/edit_tests.py +++ b/tests/edit_tests.py @@ -14,8 +14,8 @@
import pywikibot
-from pywikibot import page_put_queue from pywikibot import config +from pywikibot import page_put_queue
from tests.aspects import unittest, TestCase from tests.oauth_tests import OAuthSiteTestCase diff --git a/tests/interwiki_link_tests.py b/tests/interwiki_link_tests.py index e5050b6..111940d 100644 --- a/tests/interwiki_link_tests.py +++ b/tests/interwiki_link_tests.py @@ -10,8 +10,10 @@ __version__ = '$Id$'
from pywikibot import config2 as config -from pywikibot.page import Link + from pywikibot.exceptions import InvalidTitle +from pywikibot.page import Link + from tests.aspects import ( unittest, AlteredDefaultSiteTestCase as LinkTestCase, diff --git a/tests/interwikidata_tests.py b/tests/interwikidata_tests.py index 81c94d1..c823a8a 100644 --- a/tests/interwikidata_tests.py +++ b/tests/interwikidata_tests.py @@ -11,9 +11,10 @@
import pywikibot
-from scripts import interwikidata from pywikibot import Link
+from scripts import interwikidata + from tests.aspects import unittest, SiteAttributeTestCase
diff --git a/tests/oauth_tests.py b/tests/oauth_tests.py index a0bf0e0..d05f33d 100644 --- a/tests/oauth_tests.py +++ b/tests/oauth_tests.py @@ -12,6 +12,7 @@ import os
from pywikibot.login import OauthLoginManager + from tests.aspects import ( unittest, require_modules, diff --git a/tests/page_tests.py b/tests/page_tests.py index cf25ff0..73bb2d3 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -9,6 +9,8 @@
__version__ = '$Id$'
+import pickle + import pywikibot import pywikibot.page
@@ -491,7 +493,6 @@ def testPickleAbility(self): """Test the ability to pickle the page.""" mainpage = self.get_mainpage() - import pickle mainpage_str = pickle.dumps(mainpage, protocol=config.pickle_protocol) mainpage_unpickled = pickle.loads(mainpage_str) self.assertEqual(mainpage, mainpage_unpickled) diff --git a/tests/proofreadpage_tests.py b/tests/proofreadpage_tests.py index b1c5b4c..6e517cd 100644 --- a/tests/proofreadpage_tests.py +++ b/tests/proofreadpage_tests.py @@ -15,8 +15,8 @@
from pywikibot.data import api from pywikibot.proofreadpage import IndexPage, ProofreadPage -from tests.aspects import unittest, require_modules, TestCase
+from tests.aspects import unittest, require_modules, TestCase from tests.basepage_tests import ( BasePageMethodsTestBase, BasePageLoadRevisionsCachingTestBase, diff --git a/tests/pwb/print_env.py b/tests/pwb/print_env.py index 9260f95..e549d38 100644 --- a/tests/pwb/print_env.py +++ b/tests/pwb/print_env.py @@ -5,6 +5,7 @@
import os import sys + from pywikibot.tools import first_upper
_pwb_dir = os.path.abspath(os.path.join( diff --git a/tests/replacebot_tests.py b/tests/replacebot_tests.py index ffebe76..4bbcb74 100644 --- a/tests/replacebot_tests.py +++ b/tests/replacebot_tests.py @@ -16,6 +16,7 @@ from scripts import replace
from tests import join_data_path + from tests.aspects import unittest from tests.bot_tests import TWNBotTestCase
diff --git a/tests/site_tests.py b/tests/site_tests.py index 5fc5cf0..ab547f7 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -11,6 +11,7 @@
import json import os +import pickle import re import sys
@@ -20,6 +21,7 @@ import pywikibot
from pywikibot import config + from pywikibot.comms import http from pywikibot.data import api
@@ -221,7 +223,6 @@ cached = True
def testPickleAbility(self): - import pickle mysite = self.get_site() mysite_str = pickle.dumps(mysite, protocol=config.pickle_protocol) mysite_pickled = pickle.loads(mysite_str) diff --git a/tests/thread_tests.py b/tests/thread_tests.py index 0f640be..5ac4f3d 100644 --- a/tests/thread_tests.py +++ b/tests/thread_tests.py @@ -10,6 +10,7 @@ __version__ = '$Id$'
from tests.aspects import unittest, TestCase + from pywikibot.tools import ThreadedGenerator, intersect_generators
diff --git a/tests/timestripper_tests.py b/tests/timestripper_tests.py index 98d6d35..f3e50c0 100644 --- a/tests/timestripper_tests.py +++ b/tests/timestripper_tests.py @@ -12,6 +12,7 @@ import datetime
from pywikibot.textlib import TimeStripper, tzoneFixedOffset + from tests.aspects import unittest, TestCase
diff --git a/tests/uploadbot_tests.py b/tests/uploadbot_tests.py index 67e95c3..eb9b817 100644 --- a/tests/uploadbot_tests.py +++ b/tests/uploadbot_tests.py @@ -17,6 +17,7 @@ import os
from scripts import upload + from tests import join_images_path from tests.aspects import unittest, TestCase
diff --git a/tests/utils.py b/tests/utils.py index 408c181..ab1f946 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -30,10 +30,11 @@ import pywikibot
from pywikibot import config + from pywikibot.comms import threadedhttp -from pywikibot.site import Namespace from pywikibot.data.api import CachedRequest, APIError from pywikibot.data.api import Request as _original_Request +from pywikibot.site import Namespace from pywikibot.tools import ( PYTHON_VERSION, UnicodeType as unicode, diff --git a/tests/wikibase_edit_tests.py b/tests/wikibase_edit_tests.py index a618b06..9bda4d1 100644 --- a/tests/wikibase_edit_tests.py +++ b/tests/wikibase_edit_tests.py @@ -11,6 +11,7 @@ #
import time + import pywikibot
from tests.aspects import unittest, WikibaseTestCase diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py index a370f6a..e7bc61f 100644 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -12,6 +12,7 @@
import copy import json + from decimal import Decimal
import pywikibot diff --git a/tests/wikidataquery_tests.py b/tests/wikidataquery_tests.py index 0d2c441..ad698ce 100644 --- a/tests/wikidataquery_tests.py +++ b/tests/wikidataquery_tests.py @@ -10,16 +10,17 @@ __version__ = '$Id$' #
- -import pywikibot.data.wikidataquery as query -from tests.aspects import unittest, WikidataTestCase, TestCase - -import pywikibot -from pywikibot.page import ItemPage, PropertyPage, Claim - import os import time
+import pywikibot + +import pywikibot.data.wikidataquery as query + +from pywikibot.page import ItemPage, PropertyPage, Claim + +from tests.aspects import unittest, WikidataTestCase, TestCase +
class TestDryApiFunctions(TestCase):
diff --git a/tox.ini b/tox.ini index 23ab2b2..31fb89f 100644 --- a/tox.ini +++ b/tox.ini @@ -34,6 +34,7 @@ flake8-coding flake8-future-import flake8-string-format + flake8-import-order
[testenv:flake8-py3] commands = @@ -243,7 +244,7 @@ -rdocs/requirements-py3.txt
[flake8] -ignore = E241,E402,E731,D105,D211,FI10,FI12,FI13,FI15,FI5,H101,H201,H202,H236,H301,H306,H404,H405,P102,P103 +ignore = E241,E402,E731,D105,D211,FI10,FI12,FI13,FI15,FI5,H101,H201,H202,H236,H301,H404,H405,I100,I101,P102,P103 exclude = .tox,.git,./*.egg,ez_setup.py,build,externals,user-config.py,./scripts/i18n/* max_line_length = 130 accept-encodings = utf-8
pywikibot-commits@lists.wikimedia.org