utils: Remove 'check_sources'

There are still a couple of checks here but all of them can be removed
now:

- Check if using valid Python syntax
- Check if line length too long
- Check if using 'x == None/True/False'
- Check if using old HTML 3 tags

The first three are already handled by default by the 'flake8' tool. The
last one isn't replaced by anything, but it really isn't worth worrying
about now because the tags it checks for have been dead for a really
long time and would not be used by anyone writing HTML in the last 10
years. Combined, it means we can remove the entire file.

The 'style-check' target is updated to simply alias 'flake8'. It can be
removed in a future release. This allows us to stop using this target in
the Travis jobs, seeing as we already run flake8.

Signed-off-by: Stephen Finucane <stephen@that.guru>
This commit is contained in:
Stephen Finucane 2017-10-01 16:26:40 +01:00
parent f5c0d64658
commit 160e27e20f
3 changed files with 2 additions and 225 deletions

View File

@ -44,5 +44,5 @@ install:
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then python3.6 -m pip install mypy typed-ast; fi
script:
- flake8
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then make style-check type-check test-async; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then make type-check test-async; fi
- if [[ $TRAVIS_PYTHON_VERSION != '3.6' ]]; then make test; fi

View File

@ -3,42 +3,10 @@ PYTHON ?= python
.PHONY: all style-check type-check clean clean-pyc clean-patchfiles clean-backupfiles \
clean-generated pylint reindent test covertest build
DONT_CHECK = -i .ropeproject \
-i .tox \
-i build \
-i dist \
-i doc/_build \
-i sphinx/pycode/pgen2 \
-i sphinx/search/da.py \
-i sphinx/search/de.py \
-i sphinx/search/en.py \
-i sphinx/search/es.py \
-i sphinx/search/fi.py \
-i sphinx/search/fr.py \
-i sphinx/search/hu.py \
-i sphinx/search/it.py \
-i sphinx/search/ja.py \
-i sphinx/search/nl.py \
-i sphinx/search/no.py \
-i sphinx/search/pt.py \
-i sphinx/search/ro.py \
-i sphinx/search/ru.py \
-i sphinx/search/sv.py \
-i sphinx/search/tr.py \
-i sphinx/style/jquery.js \
-i sphinx/util/smartypants.py \
-i tests/build \
-i tests/path.py \
-i tests/roots/test-directive-code/target.py \
-i tests/roots/test-warnings/undecodable.rst \
-i tests/test_autodoc_py35.py \
-i tests/typing_test_data.py \
-i utils/convert.py
all: clean-pyc clean-backupfiles style-check type-check test
style-check:
@PYTHONWARNINGS=all $(PYTHON) utils/check_sources.py $(DONT_CHECK) .
@flake8
type-check:
mypy sphinx/

View File

@ -1,191 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Checker for file headers
~~~~~~~~~~~~~~~~~~~~~~~~
Make sure each Python file has a correct file header
including copyright and license information.
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from __future__ import print_function
import os
import re
import sys
from optparse import OptionParser
from os.path import join, splitext, abspath
checkers = {}
def checker(*suffixes, **kwds):
only_pkg = kwds.pop('only_pkg', False)
def deco(func):
for suffix in suffixes:
checkers.setdefault(suffix, []).append(func)
func.only_pkg = only_pkg
return func
return deco
# this one is a byte regex since it is applied before decoding
coding_re = re.compile(br'coding[:=]\s*([-\w.]+)')
uni_coding_re = re.compile(r'^#.*coding[:=]\s*([-\w.]+).*')
not_ix_re = re.compile(r'\bnot\s+\S+?\s+i[sn]\s\S+')
is_const_re = re.compile(r'if.*?==\s+(None|False|True)\b')
noqa_re = re.compile(r'#\s+NOQA\s*$', re.I)
misspellings = ["developement", "adress", # ALLOW-MISSPELLING
"verificate", "informations"] # ALLOW-MISSPELLING
def decode_source(fn, lines):
encoding = 'ascii' if fn.endswith('.py') else 'utf-8'
decoded_lines = []
for lno, line in enumerate(lines):
if lno < 2:
co = coding_re.search(line)
if co:
encoding = co.group(1).decode()
try:
decoded_lines.append(line.decode(encoding))
except UnicodeDecodeError as err:
raise UnicodeError("%s:%d: not decodable: %s\n Line: %r" %
(fn, lno + 1, err, line))
except LookupError as err:
raise LookupError("unknown encoding: %s" % encoding)
return decoded_lines
@checker('.py')
def check_syntax(fn, lines):
lines = [uni_coding_re.sub('', line) for line in lines]
try:
compile(''.join(lines), fn, "exec")
except SyntaxError as err:
yield 0, "not compilable: %s" % err
@checker('.py')
def check_style(fn, lines):
for lno, line in enumerate(lines):
if noqa_re.search(line):
continue
if len(line.rstrip('\n')) > 95:
yield lno + 1, "line too long"
if line.strip().startswith('#'):
continue
# m = not_ix_re.search(line)
# if m:
# yield lno+1, '"' + m.group() + '"'
if is_const_re.search(line):
yield lno + 1, 'using == None/True/False'
@checker('.py', '.html', '.rst')
def check_whitespace_and_spelling(fn, lines):
for lno, line in enumerate(lines):
if '\t' in line:
yield lno + 1, "OMG TABS!!!1 "
if line[:-1].rstrip(' \t') != line[:-1]:
yield lno + 1, "trailing whitespace"
for word in misspellings:
if word in line and 'ALLOW-MISSPELLING' not in line:
yield lno + 1, '"%s" used' % word
bad_tags = ['<u>', '<s>', '<strike>', '<center>', '<font']
@checker('.html')
def check_xhtml(fn, lines):
for lno, line in enumerate(lines):
for bad_tag in bad_tags:
if bad_tag in line:
yield lno + 1, "used " + bad_tag
def main(argv=sys.argv[1:]):
parser = OptionParser(usage='Usage: %prog [-v] [-i ignorepath]* [path]')
parser.add_option('-v', '--verbose', dest='verbose', default=False,
action='store_true')
parser.add_option('-i', '--ignore-path', dest='ignored_paths',
default=[], action='append')
options, args = parser.parse_args(argv)
if len(args) == 0:
path = '.'
elif len(args) == 1:
path = args[0]
else:
print(args)
parser.error('No more then one path supported')
verbose = options.verbose
ignored_paths = set(abspath(p) for p in options.ignored_paths)
num = 0
for root, dirs, files in os.walk(path):
for vcs_dir in ['.svn', '.hg', '.git']:
if vcs_dir in dirs:
dirs.remove(vcs_dir)
if abspath(root) in ignored_paths:
del dirs[:]
continue
in_check_pkg = root.startswith('./sphinx')
for fn in files:
fn = join(root, fn)
if fn[:2] == './':
fn = fn[2:]
if abspath(fn) in ignored_paths:
continue
ext = splitext(fn)[1]
checkerlist = checkers.get(ext, None)
if not checkerlist:
continue
if verbose:
print("Checking %s..." % fn)
try:
with open(fn, 'rb') as f:
lines = list(f)
except (IOError, OSError) as err:
print("%s: cannot open: %s" % (fn, err))
num += 1
continue
try:
lines = decode_source(fn, lines)
except Exception as err:
print(err)
num += 1
continue
for checker in checkerlist:
if not in_check_pkg and checker.only_pkg:
continue
for lno, msg in checker(fn, lines):
print("%s:%d: %s" % (fn, lno, msg))
num += 1
if verbose:
print()
if num == 0:
print("No errors found.")
else:
print("%d error%s found." % (num, num > 1 and "s" or ""))
return int(num > 0)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))