Skip to content

Commit 2f0b7f9

Browse files
authored
pylint a few python scripts and lint in lint.sh (flutter#33675)
1 parent 6e180c9 commit 2f0b7f9

16 files changed

+632
-360
lines changed

.pylintrc

+254
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
[MASTER]
2+
3+
# Specify a configuration file.
4+
#rcfile=
5+
6+
# Python code to execute, usually for sys.path manipulation such as
7+
# pygtk.require().
8+
#init-hook=
9+
10+
# Add files or directories to the blocklist. They should be base names, not
11+
# paths.
12+
ignore=CVS,.git,out
13+
14+
# Pickle collected data for later comparisons.
15+
persistent=yes
16+
17+
# List of plugins (as comma separated values of python modules names) to load,
18+
# usually to register additional checkers.
19+
load-plugins=
20+
pylint_quotes
21+
22+
23+
# Configure quote preferences.
24+
string-quote = single-avoid-escape
25+
triple-quote = double
26+
docstring-quote = double
27+
28+
29+
[MESSAGES CONTROL]
30+
31+
# Enable the message, report, category or checker with the given id(s). You can
32+
# either give multiple identifier separated by comma (,) or put this option
33+
# multiple time.
34+
#enable=
35+
36+
# Disable the message, report, category or checker with the given id(s). You
37+
# can either give multiple identifier separated by comma (,) or put this option
38+
# multiple time (only on the command line, not in the configuration file where
39+
# it should appear only once).
40+
disable=
41+
exec-used,
42+
fixme,
43+
missing-class-docstring,
44+
missing-function-docstring,
45+
missing-module-docstring,
46+
too-few-public-methods,
47+
too-many-branches,
48+
too-many-lines,
49+
too-many-return-statements,
50+
too-many-statements,
51+
52+
53+
[REPORTS]
54+
55+
# Set the output format. Available formats are text, parseable, colorized, msvs
56+
# (visual studio) and html
57+
output-format=text
58+
59+
# Put messages in a separate file for each module / package specified on the
60+
# command line instead of printing them on stdout. Reports (if any) will be
61+
# written in a file name "pylint_global.[txt|html]".
62+
files-output=no
63+
64+
# Tells whether to display a full report or only the messages
65+
# CHANGED:
66+
reports=no
67+
68+
# Activate the evaluation score.
69+
score=no
70+
71+
# Python expression which should return a note less than 10 (10 is the highest
72+
# note). You have access to the variables errors warning, statement which
73+
# respectively contain the number of errors / warnings messages and the total
74+
# number of statements analyzed. This is used by the global evaluation report
75+
# (RP0004).
76+
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
77+
78+
79+
[VARIABLES]
80+
81+
# Tells whether we should check for unused import in __init__ files.
82+
init-import=no
83+
84+
# A regular expression matching the beginning of the name of dummy variables
85+
# (i.e. not used).
86+
dummy-variables-rgx=_|dummy
87+
88+
# List of additional names supposed to be defined in builtins. Remember that
89+
# you should avoid to define new builtins when possible.
90+
additional-builtins=
91+
92+
93+
[TYPECHECK]
94+
95+
# Tells whether missing members accessed in mixin class should be ignored. A
96+
# mixin class is detected if its name ends with "mixin" (case insensitive).
97+
ignore-mixin-members=yes
98+
99+
# List of classes names for which member attributes should not be checked
100+
# (useful for classes with attributes dynamically set).
101+
ignored-classes=SQLObject,twisted.internet.reactor,hashlib,google.appengine.api.memcache
102+
103+
# List of members which are set dynamically and missed by pylint inference
104+
# system, and so shouldn't trigger E0201 when accessed. Python regular
105+
# expressions are accepted.
106+
generated-members=REQUEST,acl_users,aq_parent,multiprocessing.managers.SyncManager
107+
108+
109+
[MISCELLANEOUS]
110+
111+
# List of note tags to take in consideration, separated by a comma.
112+
notes=FIXME,XXX,TODO
113+
114+
115+
[SIMILARITIES]
116+
117+
# Minimum lines number of a similarity.
118+
min-similarity-lines=10
119+
120+
# Ignore comments when computing similarities.
121+
ignore-comments=yes
122+
123+
# Ignore docstrings when computing similarities.
124+
ignore-docstrings=yes
125+
126+
127+
[FORMAT]
128+
129+
# Maximum number of characters on a single line.
130+
# yapf is configured (in .style.yapf) to format to a line length of 80, but
131+
# sometimes it is not successful if a comment or string literal isn't already
132+
# well-formatted. Therefore, we use pylint to put a hard limit somewhere
133+
# further out at a point where manual formatting should be done.
134+
max-line-length=100
135+
136+
# Maximum number of lines in a module
137+
max-module-lines=1000
138+
139+
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
140+
# tab).
141+
# CHANGED:
142+
indent-string=' '
143+
144+
145+
[BASIC]
146+
147+
# List of builtins function names that should not be used, separated by a comma
148+
bad-functions=map,filter,apply,input
149+
150+
# Regular expression which should only match correct module names
151+
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
152+
153+
# Regular expression which should only match correct module level names
154+
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
155+
156+
# Regular expression which should only match correct class names
157+
class-rgx=[A-Z_][a-zA-Z0-9]+$
158+
159+
# Regular expression which should only match correct function names
160+
function-rgx=[a-z_][a-z0-9_]{2,30}$
161+
162+
# Regular expression which should only match correct method names
163+
method-rgx=[a-z_][a-z0-9_]{2,30}$
164+
165+
# Regular expression which should only match correct instance attribute names
166+
attr-rgx=[a-z_][a-z0-9_]{2,30}$
167+
168+
# Regular expression which should only match correct argument names
169+
argument-rgx=[a-z_][a-z0-9_]{2,30}$
170+
171+
# Regular expression which should only match correct variable names
172+
variable-rgx=[a-z_][a-z0-9_]{2,30}$
173+
174+
# Regular expression which should only match correct list comprehension /
175+
# generator expression variable names
176+
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
177+
178+
# Good variable names which should always be accepted, separated by a comma
179+
good-names=i,j,k,ex,Run,_
180+
181+
# Bad variable names which should always be refused, separated by a comma
182+
bad-names=foo,bar,baz,toto,tutu,tata
183+
184+
# Regular expression which should only match functions or classes name which do
185+
# not require a docstring
186+
no-docstring-rgx=__.*__
187+
188+
189+
[DESIGN]
190+
191+
# Maximum number of arguments for function / method
192+
max-args=5
193+
194+
# Argument names that match this expression will be ignored. Default to name
195+
# with leading underscore
196+
ignored-argument-names=_.*
197+
198+
# Maximum number of locals for function / method body
199+
max-locals=25
200+
201+
# Maximum number of return / yield for function / method body
202+
max-returns=6
203+
204+
# Maximum number of branch for function / method body
205+
max-branchs=12
206+
207+
# Maximum number of statements in function / method body
208+
max-statements=50
209+
210+
# Maximum number of parents for a class (see R0901).
211+
max-parents=7
212+
213+
# Maximum number of attributes for a class (see R0902).
214+
max-attributes=7
215+
216+
# Minimum number of public methods for a class (see R0903).
217+
min-public-methods=2
218+
219+
# Maximum number of public methods for a class (see R0904).
220+
max-public-methods=20
221+
222+
223+
[CLASSES]
224+
225+
# List of method names used to declare (i.e. assign) instance attributes.
226+
defining-attr-methods=__init__,__new__,setUp
227+
228+
# List of valid names for the first argument in a class method.
229+
valid-classmethod-first-arg=cls
230+
231+
232+
[IMPORTS]
233+
234+
# Deprecated modules which should not be used, separated by a comma
235+
deprecated-modules=regsub,string,TERMIOS,Bastion,rexec
236+
237+
# Create a graph of every (i.e. internal and external) dependencies in the
238+
# given file (report RP0402 must not be disabled)
239+
import-graph=
240+
241+
# Create a graph of external dependencies in the given file (report RP0402 must
242+
# not be disabled)
243+
ext-import-graph=
244+
245+
# Create a graph of internal dependencies in the given file (report RP0402 must
246+
# not be disabled)
247+
int-import-graph=
248+
249+
250+
[EXCEPTIONS]
251+
252+
# Exceptions that will emit a warning when being caught. Defaults to
253+
# "Exception"
254+
overgeneral-exceptions=Exception

build/copy_info_plist.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,34 @@
1010
1111
Precondition: $CWD/../../flutter is the path to the flutter engine repo.
1212
13-
usage: copy_info_plist.py --source <src_path> --destination <dest_path> --bitcode --minversion=<deployment_target>
13+
usage: copy_info_plist.py --source <src_path> --destination <dest_path>
14+
--bitcode --minversion=<deployment_target>
1415
"""
1516

17+
import argparse
18+
import os
1619
import subprocess
1720

18-
import argparse
19-
import sys
2021
import git_revision
21-
import os
2222

2323

24-
def GetClangVersion(bitcode):
24+
def get_clang_version(bitcode):
2525
clang_executable = str(
2626
os.path.join(
27-
"..", "..", "buildtools", "mac-x64", "clang", "bin", "clang++"
27+
'..', '..', 'buildtools', 'mac-x64', 'clang', 'bin', 'clang++'
2828
)
2929
)
3030
if bitcode:
31-
clang_executable = "clang++"
32-
version = subprocess.check_output([clang_executable, "--version"])
31+
clang_executable = 'clang++'
32+
version = subprocess.check_output([clang_executable, '--version'])
3333
return version.splitlines()[0]
3434

3535

3636
def main():
3737

3838
parser = argparse.ArgumentParser(
39-
description='Copies the Info.plist and adds extra fields to it like the git hash of the engine'
39+
description='Copies the Info.plist and adds extra fields to it like the '
40+
'git hash of the engine'
4041
)
4142

4243
parser.add_argument(
@@ -61,19 +62,19 @@ def main():
6162
args = parser.parse_args()
6263

6364
text = open(args.source).read()
64-
engine_path = os.path.join(os.getcwd(), "..", "..", "flutter")
65-
revision = git_revision.GetRepositoryVersion(engine_path)
65+
engine_path = os.path.join(os.getcwd(), '..', '..', 'flutter')
66+
revision = git_revision.get_repository_version(engine_path)
6667
bitcode = args.bitcode is not None
67-
clang_version = GetClangVersion(bitcode)
68+
clang_version = get_clang_version(bitcode)
6869
text = text.format(
6970
revision=revision,
7071
clang_version=clang_version,
7172
min_version=args.minversion
7273
)
7374

74-
with open(args.destination, "w") as outfile:
75+
with open(args.destination, 'w') as outfile:
7576
outfile.write(text)
7677

7778

78-
if __name__ == "__main__":
79+
if __name__ == '__main__':
7980
main()

build/dart/tools/dart_package_name.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@
77
"""This script outputs the package name specified in the pubspec.yaml"""
88

99
import argparse
10-
import os
1110
import sys
1211

1312

1413
# TODO(johnmccutchan): Use the yaml package to parse.
15-
def PackageName(line):
16-
assert line.startswith("name:")
17-
return line.split(":")[1].strip()
14+
def package_name(line):
15+
assert line.startswith('name:')
16+
return line.split(':')[1].strip()
1817

1918

2019
def main(pubspec_file):
21-
source_file = open(pubspec_file, "r")
20+
source_file = open(pubspec_file, 'r')
2221
for line in source_file:
23-
if line.startswith("name:"):
24-
print(PackageName(line))
22+
if line.startswith('name:'):
23+
print(package_name(line))
2524
return 0
2625
source_file.close()
2726
# Couldn't find it.
@@ -30,16 +29,16 @@ def main(pubspec_file):
3029

3130
if __name__ == '__main__':
3231
parser = argparse.ArgumentParser(
33-
description="This script outputs the package name specified in the"
34-
"pubspec.yaml"
32+
description='This script outputs the package name specified in the '
33+
'pubspec.yaml'
3534
)
3635
parser.add_argument(
37-
"--pubspec",
38-
dest="pubspec_file",
39-
metavar="<pubspec-file>",
36+
'--pubspec',
37+
dest='pubspec_file',
38+
metavar='<pubspec-file>',
4039
type=str,
4140
required=True,
42-
help="Path to pubspec file"
41+
help='Path to pubspec file'
4342
)
4443
args = parser.parse_args()
4544
sys.exit(main(args.pubspec_file))

0 commit comments

Comments
 (0)