Browse Source

module: add pylint and fix accordingly

cn 8 months ago
parent
commit
5466a3ff2d
4 changed files with 564 additions and 16 deletions
  1. 546
    0
      .pylintrc
  2. 1
    0
      .travis.yml
  3. 2
    2
      veml6070/__init__.py
  4. 15
    14
      veml6070/veml6070.py

+ 546
- 0
.pylintrc View File

@@ -0,0 +1,546 @@
1
+[MASTER]
2
+
3
+# A comma-separated list of package or module names from where C extensions may
4
+# be loaded. Extensions are loading into the active Python interpreter and may
5
+# run arbitrary code
6
+extension-pkg-whitelist=
7
+
8
+# Add files or directories to the blacklist. They should be base names, not
9
+# paths.
10
+ignore=CVS
11
+
12
+# Add files or directories matching the regex patterns to the blacklist. The
13
+# regex matches against base names, not paths.
14
+ignore-patterns=
15
+
16
+# Python code to execute, usually for sys.path manipulation such as
17
+# pygtk.require().
18
+#init-hook=
19
+
20
+# Use multiple processes to speed up Pylint.
21
+jobs=1
22
+
23
+# List of plugins (as comma separated values of python modules names) to load,
24
+# usually to register additional checkers.
25
+load-plugins=
26
+
27
+# Pickle collected data for later comparisons.
28
+persistent=no
29
+
30
+# Specify a configuration file.
31
+#rcfile=
32
+
33
+# When enabled, pylint would attempt to guess common misconfiguration and emit
34
+# user-friendly hints instead of false-positive error messages
35
+suggestion-mode=yes
36
+
37
+# Allow loading of arbitrary C extensions. Extensions are imported into the
38
+# active Python interpreter and may run arbitrary code.
39
+unsafe-load-any-extension=no
40
+
41
+
42
+[MESSAGES CONTROL]
43
+
44
+# Only show warnings with the listed confidence levels. Leave empty to show
45
+# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED
46
+confidence=
47
+
48
+# Disable the message, report, category or checker with the given id(s). You
49
+# can either give multiple identifiers separated by comma (,) or put this
50
+# option multiple times (only on the command line, not in the configuration
51
+# file where it should appear only once).You can also use "--disable=all" to
52
+# disable everything first and then reenable specific checks. For example, if
53
+# you want to run only the similarities checker, you can use "--disable=all
54
+# --enable=similarities". If you want to run only the classes checker, but have
55
+# no Warning level messages displayed, use"--disable=all --enable=classes
56
+# --disable=W"
57
+disable=print-statement,
58
+        parameter-unpacking,
59
+        unpacking-in-except,
60
+        old-raise-syntax,
61
+        backtick,
62
+        long-suffix,
63
+        old-ne-operator,
64
+        old-octal-literal,
65
+        import-star-module-level,
66
+        non-ascii-bytes-literal,
67
+        raw-checker-failed,
68
+        bad-inline-option,
69
+        locally-disabled,
70
+        locally-enabled,
71
+        file-ignored,
72
+        suppressed-message,
73
+        useless-suppression,
74
+        deprecated-pragma,
75
+        apply-builtin,
76
+        basestring-builtin,
77
+        buffer-builtin,
78
+        cmp-builtin,
79
+        coerce-builtin,
80
+        execfile-builtin,
81
+        file-builtin,
82
+        long-builtin,
83
+        raw_input-builtin,
84
+        reduce-builtin,
85
+        standarderror-builtin,
86
+        unicode-builtin,
87
+        xrange-builtin,
88
+        coerce-method,
89
+        delslice-method,
90
+        getslice-method,
91
+        setslice-method,
92
+        no-absolute-import,
93
+        old-division,
94
+        dict-iter-method,
95
+        dict-view-method,
96
+        next-method-called,
97
+        metaclass-assignment,
98
+        indexing-exception,
99
+        raising-string,
100
+        reload-builtin,
101
+        oct-method,
102
+        hex-method,
103
+        nonzero-method,
104
+        cmp-method,
105
+        input-builtin,
106
+        round-builtin,
107
+        intern-builtin,
108
+        unichr-builtin,
109
+        map-builtin-not-iterating,
110
+        zip-builtin-not-iterating,
111
+        range-builtin-not-iterating,
112
+        filter-builtin-not-iterating,
113
+        using-cmp-argument,
114
+        eq-without-hash,
115
+        div-method,
116
+        idiv-method,
117
+        rdiv-method,
118
+        exception-message-attribute,
119
+        invalid-str-codec,
120
+        sys-max-int,
121
+        bad-python3-import,
122
+        deprecated-string-function,
123
+        deprecated-str-translate-call,
124
+        deprecated-itertools-function,
125
+        deprecated-types-field,
126
+        next-method-defined,
127
+        dict-items-not-iterating,
128
+        dict-keys-not-iterating,
129
+        dict-values-not-iterating,
130
+        missing-docstring,
131
+        line-too-long,
132
+        c-extension-no-member
133
+
134
+# Enable the message, report, category or checker with the given id(s). You can
135
+# either give multiple identifier separated by comma (,) or put this option
136
+# multiple time (only on the command line, not in the configuration file where
137
+# it should appear only once). See also the "--disable" option for examples.
138
+enable=
139
+
140
+
141
+[REPORTS]
142
+
143
+# Python expression which should return a note less than 10 (10 is the highest
144
+# note). You have access to the variables errors warning, statement which
145
+# respectively contain the number of errors / warnings messages and the total
146
+# number of statements analyzed. This is used by the global evaluation report
147
+# (RP0004).
148
+evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
149
+
150
+# Template used to display messages. This is a python new-style format string
151
+# used to format the message information. See doc for all details
152
+#msg-template=
153
+
154
+# Set the output format. Available formats are text, parseable, colorized, json
155
+# and msvs (visual studio).You can also give a reporter class, eg
156
+# mypackage.mymodule.MyReporterClass.
157
+output-format=colorized
158
+
159
+# Tells whether to display a full report or only the messages
160
+reports=no
161
+
162
+# Activate the evaluation score.
163
+score=yes
164
+
165
+
166
+[REFACTORING]
167
+
168
+# Maximum number of nested blocks for function / method body
169
+max-nested-blocks=5
170
+
171
+# Complete name of functions that never returns. When checking for
172
+# inconsistent-return-statements if a never returning function is called then
173
+# it will be considered as an explicit return statement and no message will be
174
+# printed.
175
+never-returning-functions=optparse.Values,sys.exit
176
+
177
+
178
+[BASIC]
179
+
180
+# Naming style matching correct argument names
181
+argument-naming-style=snake_case
182
+
183
+# Regular expression matching correct argument names. Overrides argument-
184
+# naming-style
185
+#argument-rgx=
186
+
187
+# Naming style matching correct attribute names
188
+attr-naming-style=snake_case
189
+
190
+# Regular expression matching correct attribute names. Overrides attr-naming-
191
+# style
192
+#attr-rgx=
193
+
194
+# Bad variable names which should always be refused, separated by a comma
195
+bad-names=foo,
196
+          bar,
197
+          baz,
198
+          toto,
199
+          tutu,
200
+          tata
201
+
202
+# Naming style matching correct class attribute names
203
+class-attribute-naming-style=any
204
+
205
+# Regular expression matching correct class attribute names. Overrides class-
206
+# attribute-naming-style
207
+#class-attribute-rgx=
208
+
209
+# Naming style matching correct class names
210
+class-naming-style=PascalCase
211
+
212
+# Regular expression matching correct class names. Overrides class-naming-style
213
+#class-rgx=
214
+
215
+# Naming style matching correct constant names
216
+const-naming-style=UPPER_CASE
217
+
218
+# Regular expression matching correct constant names. Overrides const-naming-
219
+# style
220
+#const-rgx=
221
+
222
+# Minimum line length for functions/classes that require docstrings, shorter
223
+# ones are exempt.
224
+docstring-min-length=-1
225
+
226
+# Naming style matching correct function names
227
+function-naming-style=snake_case
228
+
229
+# Regular expression matching correct function names. Overrides function-
230
+# naming-style
231
+#function-rgx=
232
+
233
+# Good variable names which should always be accepted, separated by a comma
234
+good-names=i,
235
+           j,
236
+           k,
237
+           ex,
238
+           Run,
239
+           _,
240
+           uv
241
+
242
+# Include a hint for the correct naming format with invalid-name
243
+include-naming-hint=no
244
+
245
+# Naming style matching correct inline iteration names
246
+inlinevar-naming-style=any
247
+
248
+# Regular expression matching correct inline iteration names. Overrides
249
+# inlinevar-naming-style
250
+#inlinevar-rgx=
251
+
252
+# Naming style matching correct method names
253
+method-naming-style=snake_case
254
+
255
+# Regular expression matching correct method names. Overrides method-naming-
256
+# style
257
+#method-rgx=
258
+
259
+# Naming style matching correct module names
260
+module-naming-style=snake_case
261
+
262
+# Regular expression matching correct module names. Overrides module-naming-
263
+# style
264
+#module-rgx=
265
+
266
+# Colon-delimited sets of names that determine each other's naming style when
267
+# the name regexes allow several styles.
268
+name-group=
269
+
270
+# Regular expression which should only match function or class names that do
271
+# not require a docstring.
272
+no-docstring-rgx=^_
273
+
274
+# List of decorators that produce properties, such as abc.abstractproperty. Add
275
+# to this list to register other decorators that produce valid properties.
276
+property-classes=abc.abstractproperty
277
+
278
+# Naming style matching correct variable names
279
+variable-naming-style=snake_case
280
+
281
+# Regular expression matching correct variable names. Overrides variable-
282
+# naming-style
283
+#variable-rgx=
284
+
285
+
286
+[FORMAT]
287
+
288
+# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
289
+expected-line-ending-format=
290
+
291
+# Regexp for a line that is allowed to be longer than the limit.
292
+ignore-long-lines=^\s*(# )?<?https?://\S+>?$
293
+
294
+# Number of spaces of indent required inside a hanging  or continued line.
295
+indent-after-paren=4
296
+
297
+# String used as indentation unit. This is usually "    " (4 spaces) or "\t" (1
298
+# tab).
299
+indent-string='    '
300
+
301
+# Maximum number of characters on a single line.
302
+max-line-length=100
303
+
304
+# Maximum number of lines in a module
305
+max-module-lines=1000
306
+
307
+# List of optional constructs for which whitespace checking is disabled. `dict-
308
+# separator` is used to allow tabulation in dicts, etc.: {1  : 1,\n222: 2}.
309
+# `trailing-comma` allows a space between comma and closing bracket: (a, ).
310
+# `empty-line` allows space-only lines.
311
+no-space-check=trailing-comma,
312
+               dict-separator
313
+
314
+# Allow the body of a class to be on the same line as the declaration if body
315
+# contains single statement.
316
+single-line-class-stmt=no
317
+
318
+# Allow the body of an if to be on the same line as the test if there is no
319
+# else.
320
+single-line-if-stmt=no
321
+
322
+
323
+[MISCELLANEOUS]
324
+
325
+# List of note tags to take in consideration, separated by a comma.
326
+notes=FIXME,
327
+      XXX,
328
+      TODO
329
+
330
+
331
+[LOGGING]
332
+
333
+# Logging modules to check that the string format arguments are in logging
334
+# function parameter format
335
+logging-modules=logging
336
+
337
+
338
+[SIMILARITIES]
339
+
340
+# Ignore comments when computing similarities.
341
+ignore-comments=yes
342
+
343
+# Ignore docstrings when computing similarities.
344
+ignore-docstrings=yes
345
+
346
+# Ignore imports when computing similarities.
347
+ignore-imports=no
348
+
349
+# Minimum lines number of a similarity.
350
+min-similarity-lines=4
351
+
352
+
353
+[SPELLING]
354
+
355
+# Limits count of emitted suggestions for spelling mistakes
356
+max-spelling-suggestions=4
357
+
358
+# Spelling dictionary name. Available dictionaries: none. To make it working
359
+# install python-enchant package.
360
+spelling-dict=
361
+
362
+# List of comma separated words that should not be checked.
363
+spelling-ignore-words=
364
+
365
+# A path to a file that contains private dictionary; one word per line.
366
+spelling-private-dict-file=
367
+
368
+# Tells whether to store unknown words to indicated private dictionary in
369
+# --spelling-private-dict-file option instead of raising a message.
370
+spelling-store-unknown-words=no
371
+
372
+
373
+[TYPECHECK]
374
+
375
+# List of decorators that produce context managers, such as
376
+# contextlib.contextmanager. Add to this list to register other decorators that
377
+# produce valid context managers.
378
+contextmanager-decorators=contextlib.contextmanager
379
+
380
+# List of members which are set dynamically and missed by pylint inference
381
+# system, and so shouldn't trigger E1101 when accessed. Python regular
382
+# expressions are accepted.
383
+generated-members=
384
+
385
+# Tells whether missing members accessed in mixin class should be ignored. A
386
+# mixin class is detected if its name ends with "mixin" (case insensitive).
387
+ignore-mixin-members=yes
388
+
389
+# This flag controls whether pylint should warn about no-member and similar
390
+# checks whenever an opaque object is returned when inferring. The inference
391
+# can return multiple potential results while evaluating a Python object, but
392
+# some branches might not be evaluated, which results in partial inference. In
393
+# that case, it might be useful to still emit no-member and other checks for
394
+# the rest of the inferred objects.
395
+ignore-on-opaque-inference=yes
396
+
397
+# List of class names for which member attributes should not be checked (useful
398
+# for classes with dynamically set attributes). This supports the use of
399
+# qualified names.
400
+ignored-classes=optparse.Values,thread._local,_thread._local
401
+
402
+# List of module names for which member attributes should not be checked
403
+# (useful for modules/projects where namespaces are manipulated during runtime
404
+# and thus existing member attributes cannot be deduced by static analysis. It
405
+# supports qualified module names, as well as Unix pattern matching.
406
+ignored-modules=
407
+
408
+# Show a hint with possible names when a member name was not found. The aspect
409
+# of finding the hint is based on edit distance.
410
+missing-member-hint=yes
411
+
412
+# The minimum edit distance a name should have in order to be considered a
413
+# similar match for a missing member name.
414
+missing-member-hint-distance=1
415
+
416
+# The total number of similar names that should be taken in consideration when
417
+# showing a hint for a missing member.
418
+missing-member-max-choices=1
419
+
420
+
421
+[VARIABLES]
422
+
423
+# List of additional names supposed to be defined in builtins. Remember that
424
+# you should avoid to define new builtins when possible.
425
+additional-builtins=
426
+
427
+# Tells whether unused global variables should be treated as a violation.
428
+allow-global-unused-variables=yes
429
+
430
+# List of strings which can identify a callback function by name. A callback
431
+# name must start or end with one of those strings.
432
+callbacks=cb_,
433
+          _cb
434
+
435
+# A regular expression matching the name of dummy variables (i.e. expectedly
436
+# not used).
437
+dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
438
+
439
+# Argument names that match this expression will be ignored. Default to name
440
+# with leading underscore
441
+ignored-argument-names=_.*|^ignored_|^unused_
442
+
443
+# Tells whether we should check for unused import in __init__ files.
444
+init-import=no
445
+
446
+# List of qualified module names which can have objects that can redefine
447
+# builtins.
448
+redefining-builtins-modules=six.moves,past.builtins,future.builtins
449
+
450
+
451
+[IMPORTS]
452
+
453
+# Allow wildcard imports from modules that define __all__.
454
+allow-wildcard-with-all=no
455
+
456
+# Analyse import fallback blocks. This can be used to support both Python 2 and
457
+# 3 compatible code, which means that the block might have code that exists
458
+# only in one or another interpreter, leading to false positives when analysed.
459
+analyse-fallback-blocks=no
460
+
461
+# Deprecated modules which should not be used, separated by a comma
462
+deprecated-modules=regsub,
463
+                   TERMIOS,
464
+                   Bastion,
465
+                   rexec
466
+
467
+# Create a graph of external dependencies in the given file (report RP0402 must
468
+# not be disabled)
469
+ext-import-graph=
470
+
471
+# Create a graph of every (i.e. internal and external) dependencies in the
472
+# given file (report RP0402 must not be disabled)
473
+import-graph=
474
+
475
+# Create a graph of internal dependencies in the given file (report RP0402 must
476
+# not be disabled)
477
+int-import-graph=
478
+
479
+# Force import order to recognize a module as part of the standard
480
+# compatibility libraries.
481
+known-standard-library=
482
+
483
+# Force import order to recognize a module as part of a third party library.
484
+known-third-party=enchant
485
+
486
+
487
+[CLASSES]
488
+
489
+# List of method names used to declare (i.e. assign) instance attributes.
490
+defining-attr-methods=__init__,
491
+                      __new__,
492
+                      setUp
493
+
494
+# List of member names, which should be excluded from the protected access
495
+# warning.
496
+exclude-protected=_asdict,
497
+                  _fields,
498
+                  _replace,
499
+                  _source,
500
+                  _make
501
+
502
+# List of valid names for the first argument in a class method.
503
+valid-classmethod-first-arg=cls
504
+
505
+# List of valid names for the first argument in a metaclass class method.
506
+valid-metaclass-classmethod-first-arg=mcs
507
+
508
+
509
+[DESIGN]
510
+
511
+# Maximum number of arguments for function / method
512
+max-args=5
513
+
514
+# Maximum number of attributes for a class (see R0902).
515
+max-attributes=7
516
+
517
+# Maximum number of boolean expressions in a if statement
518
+max-bool-expr=5
519
+
520
+# Maximum number of branch for function / method body
521
+max-branches=12
522
+
523
+# Maximum number of locals for function / method body
524
+max-locals=15
525
+
526
+# Maximum number of parents for a class (see R0901).
527
+max-parents=7
528
+
529
+# Maximum number of public methods for a class (see R0904).
530
+max-public-methods=20
531
+
532
+# Maximum number of return / yield for function / method body
533
+max-returns=6
534
+
535
+# Maximum number of statements in function / method body
536
+max-statements=50
537
+
538
+# Minimum number of public methods for a class (see R0903).
539
+min-public-methods=2
540
+
541
+
542
+[EXCEPTIONS]
543
+
544
+# Exceptions that will emit a warning when being caught. Defaults to
545
+# "Exception"
546
+overgeneral-exceptions=Exception

+ 1
- 0
.travis.yml View File

@@ -5,4 +5,5 @@ python:
5 5
   - "2.7"
6 6
 
7 7
 script:
8
+  - pylint veml6070
8 9
   - pytest

+ 2
- 2
veml6070/__init__.py View File

@@ -1,3 +1,3 @@
1 1
 
2
-from veml6070 import Veml6070
3
-from veml6070 import INTEGRATIONTIME_1_2T, INTEGRATIONTIME_1T, INTEGRATIONTIME_2T, INTEGRATIONTIME_4T, RSET_240K, RSET_270K, RSET_300K, RSET_600K
2
+from .veml6070 import Veml6070
3
+from .veml6070 import INTEGRATIONTIME_1_2T, INTEGRATIONTIME_1T, INTEGRATIONTIME_2T, INTEGRATIONTIME_4T, RSET_240K, RSET_270K, RSET_300K, RSET_600K

+ 15
- 14
veml6070/veml6070.py View File

@@ -1,24 +1,25 @@
1 1
 
2
-import smbus
3 2
 import time
4 3
 
5
-ADDR_L=0x38 # 7bit address of the VEML6070 (write, read)
6
-ADDR_H=0x39 # 7bit address of the VEML6070 (read)
4
+import smbus # pylint: disable=import-error
7 5
 
8
-RSET_240K=240000
9
-RSET_270K=270000
10
-RSET_300K=300000
11
-RSET_600K=600000
6
+ADDR_L = 0x38 # 7bit address of the VEML6070 (write, read)
7
+ADDR_H = 0x39 # 7bit address of the VEML6070 (read)
12 8
 
13
-SHUTDOWN_DISABLE=0x00
14
-SHUTDOWN_ENABLE=0x01
9
+RSET_240K = 240000
10
+RSET_270K = 270000
11
+RSET_300K = 300000
12
+RSET_600K = 600000
15 13
 
16
-INTEGRATIONTIME_1_2T=0x00
17
-INTEGRATIONTIME_1T=0x01
18
-INTEGRATIONTIME_2T=0x02
19
-INTEGRATIONTIME_4T=0x03
14
+SHUTDOWN_DISABLE = 0x00
15
+SHUTDOWN_ENABLE = 0x01
20 16
 
21
-class Veml6070:
17
+INTEGRATIONTIME_1_2T = 0x00
18
+INTEGRATIONTIME_1T = 0x01
19
+INTEGRATIONTIME_2T = 0x02
20
+INTEGRATIONTIME_4T = 0x03
21
+
22
+class Veml6070(object):
22 23
 
23 24
     def __init__(self, i2c_bus=1, sensor_address=ADDR_L, rset=RSET_270K, integration_time=INTEGRATIONTIME_1T):
24 25
         self.bus = smbus.SMBus(i2c_bus)