jenkins-bot has submitted this change and it was merged.

Change subject: Tox pyflakes task
......................................................................


Tox pyflakes task

Replace flake8 disable=xxx with alternative workarounds for pyflakes.

For Tox/Jenkins, use pyflakes directly on various Python
implementations/versions, adding checking PyPy by Jenkins,
and an unused testenv for developer checking of Python 2.6.

The tox flake8 task now only runs on Python 2.7, as typically
flake8 plugins & errors are not version specific.

Bug: T101592
Change-Id: I076a5300ae6ff1c30365be106a8ceca2d48de7e4
---
M pwb.py
M pywikibot/bot.py
M pywikibot/page.py
M pywikibot/tools/__init__.py
M pywikibot/userinterfaces/terminal_interface_base.py
M scripts/maintenance/cache.py
M setup.py
M tox.ini
8 files changed, 109 insertions(+), 33 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pwb.py b/pwb.py
index 7290738..88e40ee 100755
--- a/pwb.py
+++ b/pwb.py
@@ -72,7 +72,7 @@
     """
     global pwb
     try:
-        import pywikibot  # flake8: disable=F811
+        import pywikibot
         pwb = pywikibot
     except RuntimeError:
         remove_modules()
@@ -184,7 +184,8 @@
     if sys.platform == 'win32' and sys.version_info[0] < 3:
         _pwb_dir = str(_pwb_dir)
     os.environ[str('PYWIKIBOT2_DIR_PWB')] = _pwb_dir
-    import pywikibot  # flake8: disable=F401
+    import pywikibot
+    pwb = pywikibot
 except RuntimeError as err:
     # user-config.py to be created
     print("NOTE: 'user-config.py' was not found!")
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 2788b86..7dbb8ef 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -84,12 +84,12 @@
 from pywikibot import config
 from pywikibot import daemonize
 from pywikibot import version
-from pywikibot.bot_choice import (  # flake8: disable=F401 (unused imports)
+from pywikibot.bot_choice import (
     Option, StandardOption, NestedOption, IntegerOption, ContextOption,
     ListOption, OutputProxyOption, HighlightContextOption,
     ChoiceException, QuitKeyboardInterrupt,
 )
-from pywikibot.logging import (  # flake8: disable=F401
+from pywikibot.logging import (
     CRITICAL, ERROR, INFO, WARNING,
 )
 from pywikibot.logging import DEBUG, INPUT, STDOUT, VERBOSE
@@ -97,7 +97,7 @@
     add_init_routine,
     debug, error, exception, log, output, stdout, warning,
 )
-from pywikibot.logging import critical  # flake8: disable=F401
+from pywikibot.logging import critical
 from pywikibot.tools import deprecated, deprecated_args, PY2, PYTHON_VERSION
 from pywikibot.tools._logging import (
     LoggingFormatter as _LoggingFormatter,
@@ -105,6 +105,27 @@
 )
 from pywikibot.tools.formatter import color_format
 
+__all__ = (
+    'CRITICAL', 'ERROR', 'INFO', 'WARNING', 'DEBUG', 'INPUT', 'STDOUT',
+    'VERBOSE', 'critical', 'debug', 'error', 'exception', 'log', 'warning',
+    'output', 'stdout', 'LoggingFormatter', 'RotatingFileHandler',
+    'init_handlers', 'writelogheader',
+    'input', 'input_choice', 'input_yn', 'inputChoice', 'input_list_choice',
+    'Option', 'StandardOption', 'NestedOption', 'IntegerOption',
+    'ContextOption', 'ListOption', 'OutputProxyOption',
+    'HighlightContextOption', 'ChoiceException', 'UnhandledAnswer',
+    'Choice', 'AlwaysChoice',
+    'QuitKeyboardInterrupt',
+    'InteractiveReplace',
+    'calledModuleName', 'handle_args', 'handleArgs', 'showHelp', 
'suggest_help',
+    'writeToCommandLogFile', 'open_webbrowser',
+    'BaseBot', 'Bot', 'SingleSiteBot', 'MultipleSitesBot',
+    'CurrentPageBot', 'AutomaticTWSummaryBot',
+    'ExistingPageBot', 'FollowRedirectPageBot', 'CreatingPageBot',
+    'RedirectPageBot', 'NoRedirectPageBot',
+    'WikidataBot',
+)
+
 if not PY2:
     unicode = str
 
diff --git a/pywikibot/page.py b/pywikibot/page.py
index c3ee4de..901d3dd 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -34,13 +34,19 @@
 from collections import defaultdict, namedtuple
 from warnings import warn
 
-if sys.version_info[0] > 2:
+from pywikibot.tools import PY2
+
+if not PY2:
     unicode = basestring = str
     long = int
     from html import entities as htmlentitydefs
     from urllib.parse import quote_from_bytes, unquote_to_bytes
 else:
-    chr = unichr  # flake8 F821 (undefined name) disabled by tox.ini
+    if __debug__ and not PY2:
+        unichr = NotImplemented  # pyflakes workaround
+
+    chr = unichr
+
     import htmlentitydefs
     from urllib import quote as quote_from_bytes, unquote as unquote_to_bytes
 
@@ -60,16 +66,36 @@
 from pywikibot.family import Family
 from pywikibot.site import Namespace
 from pywikibot.tools import (
-    PYTHON_VERSION, PY2,
+    PYTHON_VERSION,
     MediaWikiVersion, UnicodeMixin, ComparableMixin, DotReadableDict,
     deprecated, deprecate_arg, deprecated_args, issue_deprecation_warning,
     ModuleDeprecationWrapper as _ModuleDeprecationWrapper,
     first_upper, remove_last_args, _NotImplementedWarning,
     OrderedDict, Counter,
 )
-from pywikibot.tools.ip import ip_regexp  # flake8: disable=F401 (unused 
import)
+from pywikibot.tools.ip import ip_regexp
 from pywikibot.tools.ip import is_IP
 
+__all__ = (
+    'BasePage',
+    'Page',
+    'FilePage',
+    'Category',
+    'User',
+    'WikibasePage',
+    'ItemPage',
+    'Property',
+    'PropertyPage',
+    'Claim',
+    'Revision',
+    'FileInfo',
+    'Link',
+    'html2unicode',
+    'UnicodeToAsciiHtml',
+    'unicode2html',
+    'url2unicode',
+    'ip_regexp',  # unused & deprecated
+)
 
 logger = logging.getLogger("pywiki.wiki.page")
 
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 7a629e1..ff94c70 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -147,9 +147,9 @@
 
 
 else:
-    from collections import Counter  # flake8: disable=F401 (unused import)
-    from collections import OrderedDict
-    from itertools import count  # flake8: disable=F401 (unused import)
+    Counter = collections.Counter
+    OrderedDict = collections.OrderedDict
+    count = itertools.count
 
 
 def empty_iterator():
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py 
b/pywikibot/userinterfaces/terminal_interface_base.py
index dbae726..3cda2cf 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -53,6 +53,9 @@
 
 colorTagR = re.compile('\03{(?P<name>%s|previous)}' % '|'.join(colors))
 
+if __debug__ and not PY2:
+    raw_input = NotImplemented  # pyflakes workaround
+
 
 class UI(object):
 
diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py
index 7fe3d12..299497d 100755
--- a/scripts/maintenance/cache.py
+++ b/scripts/maintenance/cache.py
@@ -77,8 +77,17 @@
 from pywikibot.data import api
 
 # The follow attributes are used by eval()
-from pywikibot.page import User  # flake8: disable=F401 (unused import)
-from pywikibot.site import APISite, DataSite, LoginStatus  # flake8: 
disable=F401
+from pywikibot.page import User
+from pywikibot.site import APISite, DataSite, LoginStatus
+
+__all__ = (
+    'User', 'APISite', 'DataSite', 'LoginStatus',
+    'ParseError', 'CacheEntry', 'process_entries', 'main',
+    'has_password', 'is_logout', 'empty_response', 'not_accessed',
+    'incorrect_hash',
+    'older_than', 'newer_than', 'older_than_one_day', 'recent',
+    'uniquedesc', 'parameters',
+)
 
 
 class ParseError(Exception):
diff --git a/setup.py b/setup.py
index fa1da3a..c880ec4 100644
--- a/setup.py
+++ b/setup.py
@@ -14,9 +14,12 @@
 try:
     # Work around a traceback on Python < 2.7.4 and < 3.3.1
     # http://bugs.python.org/issue15881#msg170215
-    import multiprocessing  # flake8: disable=F401 (unused import)
+    import multiprocessing
 except ImportError:
     pass
+
+# pyflakes workaround
+__unused__ = (multiprocessing, )
 
 PYTHON_VERSION = sys.version_info[:3]
 PY2 = (PYTHON_VERSION[0] == 2)
@@ -108,7 +111,8 @@
 if PYTHON_VERSION < (2, 7, 3):
     # work around distutils hardcoded unittest dependency
     # work around T106512
-    import unittest  # flake8: disable=F401 (unused import)
+    import unittest
+    __unused__ += (unittest, )
     if 'test' in sys.argv:
         import unittest2
         sys.modules['unittest'] = unittest2
@@ -142,7 +146,8 @@
     script_deps['data_ingestion.py'] = extra_deps['csv']
 
 try:
-    import bz2  # flake8: disable=F401 (unused import)
+    import bz2
+    __unused__ += (bz2, )
 except ImportError:
     # Use bz2file if the python is not compiled with bz2 support.
     dependencies.append('bz2file')
diff --git a/tox.ini b/tox.ini
index ea79390..e44df2b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,12 +1,15 @@
 [tox]
-minversion = 1.6
+# minversion = 1.7.2 needed for skip_missing_interpreters
+minversion = 1.7.2
 skipsdist = True
-envlist = flake8,flake8-py3,doctest-{py27,py34},py26,py27,py34
+skip_missing_interpreters = True
+envlist = flake8,pyflakes-{py26,py3,pypy},doctest-{py27,py34},py26,py27,py34
 
 [tox:jenkins]
 # Override default for WM Jenkins
 # Others are run in their own individual jobs on WM Jenkins
-envlist = flake8,flake8-py3
+# Wikimedia Jenkins does not have Python 2.6
+envlist = flake8,pyflakes-{py3,pypy}
 
 [params]
 doctest_skip = --ignore-files=(gui\.py|botirc\.py|rcstream\.py)
@@ -21,6 +24,27 @@
 
 [testenv:py26]
 deps = unittest2
+
+[testenv:pyflakes-py26]
+commands = ffind --ignore-vcs . '(?<!user-config).py$' --module=pyflakes
+basepython = python2.6
+deps =
+    pyflakes
+    ffind>=1.0.2
+
+[testenv:pyflakes-py3]
+commands = ffind --ignore-vcs . '(?<!user-config).py$' --module=pyflakes
+basepython = python3
+deps =
+    pyflakes
+    ffind>=1.0.2
+
+[testenv:pyflakes-pypy]
+commands = ffind --ignore-vcs . '(?<!user-config).py$' --module=pyflakes
+basepython = pypy
+deps =
+    pyflakes
+    ffind>=1.0.2
 
 [testenv:flake8]
 commands =
@@ -39,16 +63,6 @@
        flake8-tuple>=0.2.8
        flake8-print>=2.0.1
        flake8-mock
-
-[testenv:flake8-py3]
-commands =
-    flake8 --version
-    flake8 --doctests {posargs}
-basepython = python3
-deps = flake8
-       pyflakes >= 1.1
-       flake8-docstrings>=0.2.6
-       flake8-putty>=0.3.2
 
 [testenv:nose]
 commands =
@@ -135,9 +149,6 @@
     scripts/makecat.py : +D103
     scripts/interwiki.py,/""/ : +P102
     pywikibot/__init__.py,/link_regex/ : +P103
-    # undefined names on Python 3:
-    pywikibot/page.py , /chr = unichr/ , python_version >= '3' : +F821
-    pywikibot/userinterfaces/terminal_interface_base.py , /raw_input\(\)/ , 
python_version >= '3' : +F821
     # invalidly detected as {} format string:
     tests/textlib_tests.py,/self.assert.*{{/ : +P103
     # __dict__ used in a discouraged manner

-- 
To view, visit https://gerrit.wikimedia.org/r/260909
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I076a5300ae6ff1c30365be106a8ceca2d48de7e4
Gerrit-PatchSet: 24
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: Hashar <has...@free.fr>
Gerrit-Reviewer: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: Xqt <i...@gno.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to