Gentoo Archives: gentoo-catalyst

From: Brian Dolbec <dolsen@g.o>
To: gentoo-catalyst@l.g.o
Subject: Re: [gentoo-catalyst] [PATCH] pylint: add a helper for linting code
Date: Tue, 06 Oct 2015 06:48:55
Message-Id: 20151005234802.7e6108d0.dolsen@gentoo.org
In Reply to: [gentoo-catalyst] [PATCH] pylint: add a helper for linting code by Mike Frysinger
1 On Mon, 5 Oct 2015 23:50:41 -0400
2 Mike Frysinger <vapier@g.o> wrote:
3
4 > A bunch of warnings are left disabled because there's too many
5 > violations in the current code base. Hopefully we can get to a point
6 > where everyone uses this though and we can start enabling more and
7 > more.
8 >
9 > The code base is "clean" right now in the sense that running pylint
10 > will not produce any output. But we should start removing violations
11 > one by one and re-enable the warning class as we go.
12 > ---
13 > .pylintrc | 250
14 > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15 > bin/pylint | 31 ++++++++ 2 files changed, 281 insertions(+)
16 > create mode 100644 .pylintrc
17 > create mode 100755 bin/pylint
18 >
19 > diff --git a/.pylintrc b/.pylintrc
20 > new file mode 100644
21 > index 0000000..5fdbb1f
22 > --- /dev/null
23 > +++ b/.pylintrc
24 > @@ -0,0 +1,250 @@
25 > +[MASTER]
26 > +
27 > +# Profiled execution.
28 > +profile=no
29 > +
30 > +# Add files or directories to the blacklist. They should be base
31 > names, not +# paths.
32 > +ignore=
33 > +
34 > +# Pickle collected data for later comparisons.
35 > +persistent=yes
36 > +
37 > +# List of plugins (as comma separated values of python modules
38 > names) to load, +# usually to register additional checkers.
39 > +load-plugins=
40 > +
41 > +
42 > +[MESSAGES CONTROL]
43 > +
44 > +# Enable the message, report, category or checker with the given
45 > id(s). You can +# either give multiple identifier separated by comma
46 > (,) or put this option +# multiple time.
47 > +#enable=
48 > +
49 > +# Disable the message, report, category or checker with the given
50 > id(s). You +# can either give multiple identifier separated by comma
51 > (,) or put this option +# multiple time (only on the command line,
52 > not in the configuration file where +# it should appear only once).
53 > +# We should clean up things so we can enable:
54 > +# missing-docstring -- add lots of docstrings everywhere!
55 > +# bad-whitespace -- fix spacing everywhere
56 > +# bad-continuation -- might be hard with tab indentation policy
57 > +# invalid-name -- need to manage constants better
58 > +# line-too-long -- figure out a length and stick to it
59 > +# pointless-string-statement -- convert to comments
60 > +# unused-wildcard-import -- use local disables if needed
61 > +# unidiomatic-typecheck -- convert to isinstance
62 > +# redefined-outer-name -- clean up code to not do this
63 > +# <all the ones after redefined-outer-name in the list>
64 > +disable=missing-docstring, too-many-lines, locally-enabled,
65 > locally-disabled, too-few-public-methods, too-many-public-methods,
66 > too-many-return-statements, too-many-branches, too-many-arguments,
67 > too-many-function-args, too-many-locals, too-many-statements,
68 > too-many-instance-attributes, fixme, broad-except, bad-whitespace,
69 > bad-continuation, invalid-name, line-too-long,
70 > pointless-string-statement, unused-wildcard-import,
71 > unidiomatic-typecheck, redefined-outer-name,
72 > attribute-defined-outside-init, bad-indentation, bare-except,
73 > global-statement, global-variable-not-assigned, mixed-indentation,
74 > multiple-statements, no-self-use, redefined-builtin, reimported,
75 > relative-import, superfluous-parens, super-init-not-called,
76 > unused-argument, unused-import, unused-variable, wildcard-import,
77 > bad-builtin, no-init, unreachable + + +[REPORTS] + +# Set the output
78 > format. Available formats are text, parseable, colorized, msvs +#
79 > (visual studio) and html +output-format=text + +# Put messages in a
80 > separate file for each module / package specified on the +# command
81 > line instead of printing them on stdout. Reports (if any) will be +#
82 > written in a file name "pylint_global.[txt|html]". +files-output=no +
83 > +# Tells whether to display a full report or only the messages
84 > +reports=no + +# Python expression which should return a note less
85 > than 10 (10 is the highest +# note). You have access to the variables
86 > errors warning, statement which +# respectively contain the number of
87 > errors / warnings messages and the total +# number of statements
88 > analyzed. This is used by the global evaluation report +# (RP0004).
89 > +evaluation=10.0 - ((float(5 * error + warning + refactor +
90 > convention) / statement) * 10) + +# Add a comment according to your
91 > evaluation note. This is used by the global +# evaluation report
92 > (RP0004). +comment=no + +
93 > +[FORMAT]
94 > +
95 > +# Maximum number of characters on a single line.
96 > +max-line-length=80
97 > +
98 > +# Maximum number of lines in a module
99 > +max-module-lines=1000
100 > +
101 > +# String used as indentation unit. This is usually " " (4 spaces) or
102 > "\t" (1 +# tab).
103 > +indent-string='\t'
104 > +
105 > +
106 > +[MISCELLANEOUS]
107 > +
108 > +# List of note tags to take in consideration, separated by a comma.
109 > +notes=FIXME,XXX,TODO
110 > +
111 > +
112 > +[VARIABLES]
113 > +
114 > +# Tells whether we should check for unused import in __init__ files.
115 > +init-import=no
116 > +
117 > +# A regular expression matching the beginning of the name of dummy
118 > variables +# (i.e. not used).
119 > +dummy-variables-rgx=_|dummy
120 > +
121 > +# List of additional names supposed to be defined in builtins.
122 > Remember that +# you should avoid to define new builtins when
123 > possible. +additional-builtins=
124 > +
125 > +
126 > +[TYPECHECK]
127 > +
128 > +# Tells whether missing members accessed in mixin class should be
129 > ignored. A +# mixin class is detected if its name ends with
130 > "mixin" (case insensitive). +ignore-mixin-members=yes
131 > +
132 > +# List of classes names for which member attributes should not be
133 > checked +# (useful for classes with attributes dynamically set).
134 > +ignored-classes=SQLObject,twisted.internet.reactor,hashlib,google.appengine.api.memcache
135 > +
136 > +# When zope mode is activated, add a predefined set of Zope acquired
137 > attributes +# to generated-members.
138 > +zope=no
139 > +
140 > +# List of members which are set dynamically and missed by pylint
141 > inference +# system, and so shouldn't trigger E0201 when accessed.
142 > Python regular +# expressions are accepted.
143 > +generated-members=REQUEST,acl_users,aq_parent,multiprocessing.managers.SyncManager
144 > +
145 > +
146 > +[BASIC]
147 > +
148 > +# Required attributes for module, separated by a comma
149 > +required-attributes=
150 > +
151 > +# List of builtins function names that should not be used, separated
152 > by a comma +bad-functions=map,filter,apply,input
153 > +
154 > +# Regular expression which should only match correct module names
155 > +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
156 > +
157 > +# Regular expression which should only match correct module level
158 > names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
159 > +
160 > +# Regular expression which should only match correct class names
161 > +class-rgx=[A-Z_][a-zA-Z0-9]+$
162 > +
163 > +# Regular expression which should only match correct function names
164 > +function-rgx=[a-z_][a-z0-9_]{2,30}$
165 > +
166 > +# Regular expression which should only match correct method names
167 > +method-rgx=[a-z_][a-z0-9_]{2,30}$
168 > +
169 > +# Regular expression which should only match correct instance
170 > attribute names +attr-rgx=[a-z_][a-z0-9_]{2,30}$
171 > +
172 > +# Regular expression which should only match correct argument names
173 > +argument-rgx=[a-z_][a-z0-9_]{2,30}$
174 > +
175 > +# Regular expression which should only match correct variable names
176 > +variable-rgx=[a-z_][a-z0-9_]{2,30}$
177 > +
178 > +# Regular expression which should only match correct list
179 > comprehension / +# generator expression variable names
180 > +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
181 > +
182 > +# Good variable names which should always be accepted, separated by
183 > a comma +good-names=i,j,k,ex,Run,_
184 > +
185 > +# Bad variable names which should always be refused, separated by a
186 > comma +bad-names=foo,bar,baz,toto,tutu,tata
187 > +
188 > +# Regular expression which should only match functions or classes
189 > name which do +# not require a docstring
190 > +no-docstring-rgx=__.*__
191 > +
192 > +
193 > +[SIMILARITIES]
194 > +
195 > +# Minimum lines number of a similarity.
196 > +min-similarity-lines=20
197 > +
198 > +# Ignore comments when computing similarities.
199 > +ignore-comments=yes
200 > +
201 > +# Ignore docstrings when computing similarities.
202 > +ignore-docstrings=yes
203 > +
204 > +
205 > +[IMPORTS]
206 > +
207 > +# Deprecated modules which should not be used, separated by a comma
208 > +deprecated-modules=regsub,string,TERMIOS,Bastion,rexec
209 > +
210 > +# Create a graph of every (i.e. internal and external) dependencies
211 > in the +# given file (report RP0402 must not be disabled)
212 > +import-graph=
213 > +
214 > +# Create a graph of external dependencies in the given file (report
215 > RP0402 must +# not be disabled)
216 > +ext-import-graph=
217 > +
218 > +# Create a graph of internal dependencies in the given file (report
219 > RP0402 must +# not be disabled)
220 > +int-import-graph=
221 > +
222 > +
223 > +[CLASSES]
224 > +
225 > +# List of interface methods to ignore, separated by a comma. This is
226 > used for +# instance to not check methods defines in Zope's Interface
227 > base class.
228 > +ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
229 > + +# List of method names used to declare (i.e. assign) instance
230 > attributes. +defining-attr-methods=__init__,__new__,setUp
231 > +
232 > +# List of valid names for the first argument in a class method.
233 > +valid-classmethod-first-arg=cls
234 > +
235 > +
236 > +[DESIGN]
237 > +
238 > +# Maximum number of arguments for function / method
239 > +max-args=5
240 > +
241 > +# Argument names that match this expression will be ignored. Default
242 > to name +# with leading underscore
243 > +ignored-argument-names=_.*
244 > +
245 > +# Maximum number of locals for function / method body
246 > +max-locals=15
247 > +
248 > +# Maximum number of return / yield for function / method body
249 > +max-returns=6
250 > +
251 > +# Maximum number of branch for function / method body
252 > +max-branchs=12
253 > +
254 > +# Maximum number of statements in function / method body
255 > +max-statements=50
256 > +
257 > +# Maximum number of parents for a class (see R0901).
258 > +max-parents=7
259 > +
260 > +# Maximum number of attributes for a class (see R0902).
261 > +max-attributes=7
262 > +
263 > +# Minimum number of public methods for a class (see R0903).
264 > +min-public-methods=2
265 > +
266 > +# Maximum number of public methods for a class (see R0904).
267 > +max-public-methods=20
268 > +
269 > +
270 > +[EXCEPTIONS]
271 > +
272 > +# Exceptions that will emit a warning when being caught. Defaults to
273 > +# "Exception"
274 > +overgeneral-exceptions=Exception
275 > diff --git a/bin/pylint b/bin/pylint
276 > new file mode 100755
277 > index 0000000..1a50609
278 > --- /dev/null
279 > +++ b/bin/pylint
280 > @@ -0,0 +1,31 @@
281 > +#!/usr/bin/python
282 > +# Copyright 1999-2015 Gentoo Foundation
283 > +# Distributed under the terms of the GNU General Public License v2
284 > +
285 > +"""Run pylint with the right settings."""
286 > +
287 > +from __future__ import print_function
288 > +
289 > +import os
290 > +import sys
291 > +
292 > +
293 > +def main(argv):
294 > + """The main entry point"""
295 > + source_root =
296 > os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +
297 > + pympath = source_root
298 > + pythonpath = os.environ.get('PYTHONPATH')
299 > + if pythonpath is None:
300 > + pythonpath = pympath
301 > + else:
302 > + pythonpath = pympath + ':' + pythonpath
303 > + os.environ['PYTHONPATH'] = pythonpath
304 > +
305 > + pylintrc = os.path.join(source_root, '.pylintrc')
306 > + cmd = ['pylint', '--rcfile', pylintrc]
307 > + os.execvp(cmd[0], cmd + argv)
308 > +
309 > +
310 > +if __name__ == '__main__':
311 > + main(sys.argv[1:])
312
313 it's fine with me. I had been avoiding trying to run pylint on the
314 code because it was SO BAD. I was waiting till more of it had been
315 gutted.
316
317 --
318 Brian Dolbec <dolsen>