diff --git a/docs/utils/linkfix.py b/docs/utils/linkfix.py index 6290adbe2b5..9acfc3b23c7 100755 --- a/docs/utils/linkfix.py +++ b/docs/utils/linkfix.py @@ -14,50 +14,57 @@ import re -# Used for remembering the file (and its contents) -# so we don't have to open the same file again. -_filename = None -_contents = None - -# A regex that matches standard linkcheck output lines -line_re = re.compile(u'(.*)\:\d+\:\s\[(.*)\]\s(?:(.*)\sto\s(.*)|(.*))') - -# Read lines from the linkcheck output file -try: - with open("build/linkcheck/output.txt") as out: - output_lines = out.readlines() -except IOError: - print("linkcheck output not found; please run linkcheck first.") - exit(1) - -# For every line, fix the respective file -for line in output_lines: - match = re.match(line_re, line) - - if match: - newfilename = match.group(1) - errortype = match.group(2) - - # Broken links can't be fixed and - # I am not sure what do with the local ones. - if errortype.lower() in ["broken", "local"]: - print("Not Fixed: " + line) - else: - # If this is a new file - if newfilename != _filename: - # Update the previous file - if _filename: - with open(_filename, "w") as _file: - _file.write(_contents) +def main(): + + # Used for remembering the file (and its contents) + # so we don't have to open the same file again. + _filename = None + _contents = None + + # A regex that matches standard linkcheck output lines + line_re = re.compile(u'(.*)\:\d+\:\s\[(.*)\]\s(?:(.*)\sto\s(.*)|(.*))') + + # Read lines from the linkcheck output file + try: + with open("build/linkcheck/output.txt") as out: + output_lines = out.readlines() + except IOError: + print("linkcheck output not found; please run linkcheck first.") + exit(1) + + # For every line, fix the respective file + for line in output_lines: + match = re.match(line_re, line) + + if match: + newfilename = match.group(1) + errortype = match.group(2) - _filename = newfilename + # Broken links can't be fixed and + # I am not sure what do with the local ones. + if errortype.lower() in ["broken", "local"]: + print("Not Fixed: " + line) + else: + # If this is a new file + if newfilename != _filename: + + # Update the previous file + if _filename: + with open(_filename, "w") as _file: + _file.write(_contents) + + _filename = newfilename + + # Read the new file to memory + with open(_filename) as _file: + _contents = _file.read() + + _contents = _contents.replace(match.group(3), match.group(4)) + else: + # We don't understand what the current line means! + print("Not Understood: " + line) - # Read the new file to memory - with open(_filename) as _file: - _contents = _file.read() - _contents = _contents.replace(match.group(3), match.group(4)) - else: - # We don't understand what the current line means! - print("Not Understood: " + line) +if __name__ == '__main__': + main() diff --git a/pylintrc b/pylintrc new file mode 100644 index 00000000000..f1fe13f4020 --- /dev/null +++ b/pylintrc @@ -0,0 +1,58 @@ +[MASTER] +ignore=docs,tests + +[MESSAGES CONTROL] +disable=abstract-method, + anomalous-backslash-in-string, + arguments-differ, + attribute-defined-outside-init, + bad-indentation, + bare-except, + broad-except, + catching-non-exception, + cell-var-from-loop, + comparison-with-callable, + consider-using-set-comprehension, + dangerous-default-value, + deprecated-method, + deprecated-module, + expression-not-assigned, + eval-used, + fixme, + function-redefined, + global-statement, + import-error, + inherit-non-class, + invalid-name, + keyword-arg-before-vararg, + logging-format-interpolation, + logging-not-lazy, + lost-exception, + method-hidden, + missing-docstring, + no-init, + no-member, + no-method-argument, + no-name-in-module, + no-self-argument, + no-value-for-parameter, + pointless-string-statement, + protected-access, + redefined-builtin, + redefined-outer-name, + reimported, + relative-import, # https://github.com/PyCQA/pylint/issues/2180 + signature-differs, + super-init-not-called, + too-many-ancestors, + too-many-function-args, + unexpected-special-method-signature, + unnecessary-pass, + unsubscriptable-object, + unused-argument, + unused-import, + unused-variable, + unused-wildcard-import, + used-before-assignment, + wildcard-import, + R,C diff --git a/pytest.ini b/pytest.ini index 73d169601de..235f04f1020 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,5 +2,5 @@ usefixtures = chdir python_files=test_*.py __init__.py python_classes= -addopts = --doctest-modules --assert=plain +addopts = --pylint --doctest-modules --assert=plain twisted = 1 diff --git a/tests/requirements-py2.txt b/tests/requirements-py2.txt index 790f29d34da..60807a6a9d0 100644 --- a/tests/requirements-py2.txt +++ b/tests/requirements-py2.txt @@ -2,9 +2,10 @@ mock mitmproxy==0.10.1 netlib==0.10.1 -pytest==2.9.2 +pytest +pytest-cov +pytest-pylint pytest-twisted -pytest-cov==2.2.1 jmespath brotlipy testfixtures diff --git a/tests/requirements-py3.txt b/tests/requirements-py3.txt index 7c1aacd812c..739011efd6a 100644 --- a/tests/requirements-py3.txt +++ b/tests/requirements-py3.txt @@ -1,6 +1,7 @@ -pytest==3.6.3 +pytest +pytest-cov +pytest-pylint pytest-twisted -pytest-cov==2.5.1 testfixtures jmespath leveldb; sys_platform != "win32"