Skip to content

Commit

Permalink
Use pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallaecio committed Oct 22, 2019
1 parent 2f0c46e commit 50f1e1b
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ branches:
- /^\d\.\d+\.\d+(rc\d+|\.dev\d+)?$/
matrix:
include:
- env: TOXENV=pylint
python: 3.7
- env: TOXENV=py27
python: 2.7
- env: TOXENV=py27-pinned
Expand Down
93 changes: 50 additions & 43 deletions docs/utils/linkfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
88 changes: 88 additions & 0 deletions pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
[MASTER]
persistent=no
jobs=1 # >1 hides results

[MESSAGES CONTROL]
disable=abstract-method,
anomalous-backslash-in-string,
arguments-differ,
attribute-defined-outside-init,
bad-classmethod-argument,
bad-continuation,
bad-indentation,
bad-mcs-classmethod-argument,
bad-whitespace,
broad-except,
c-extension-no-member,
catching-non-exception,
cell-var-from-loop,
comparison-with-callable,
consider-using-in,
cyclic-import,
dangerous-default-value,
deprecated-method,
deprecated-module,
duplicate-code, # https://github.com/PyCQA/pylint/issues/214
eval-used,
expression-not-assigned,
fixme,
function-redefined,
global-statement,
import-error,
import-outside-toplevel,
inconsistent-return-statements,
inherit-non-class,
invalid-name,
keyword-arg-before-vararg,
line-too-long,
logging-format-interpolation,
logging-not-lazy,
lost-exception,
method-hidden,
missing-docstring,
missing-final-newline,
multiple-imports,
multiple-statements,
no-else-continue,
no-else-raise,
no-else-return,
no-init,
no-member,
no-method-argument,
no-name-in-module,
no-self-argument,
no-self-use,
pointless-string-statement,
protected-access,
redefined-argument-from-local,
redefined-builtin,
redefined-outer-name,
reimported,
signature-differs,
super-init-not-called,
superfluous-parens,
too-few-public-methods,
too-many-ancestors,
too-many-arguments,
too-many-branches,
too-many-function-args,
too-many-instance-attributes,
too-many-locals,
too-many-return-statements,
trailing-newlines,
trailing-whitespace,
unexpected-special-method-signature,
ungrouped-imports,
unidiomatic-typecheck,
unnecessary-comprehension,
unnecessary-pass,
unsubscriptable-object,
unused-argument,
unused-import,
unused-variable,
unused-wildcard-import,
used-before-assignment,
useless-object-inheritance, # Required for Python 2 support
wildcard-import,
wrong-import-order,
wrong-import-position
14 changes: 14 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ deps = {[testenv:py35]deps}
commands =
py.test {posargs:scrapy tests}

[testenv:pylint]
basepython = python3.7
deps =
{[testenv:py35]deps}
# Optional dependencies
boto
reppy
robotexclusionrulesparser
# Test dependencies
pylint

commands =
pylint scrapy

[docs]
changedir = docs
deps =
Expand Down

0 comments on commit 50f1e1b

Please sign in to comment.