pre-commit pylint (#1580)

* "The commit-hook project sounds interesting though. I would definitely merge something that runs flake8 and pylint on the modified files!"
-  pd0wm, https://github.com/commaai/openpilot/pull/1575#issuecomment-634974344

* add pylint to pre-commit and make everything pass

* Remove uncommented stuff

Co-authored-by: J <user@4800.lan>
old-commit-hash: bd06434243
vw-mqb-aeb
Willem Melching 5 years ago committed by GitHub
parent 834f6c383a
commit c0866d9edb
  1. 18
      .pre-commit-config.yaml
  2. 2
      .pylintrc
  3. 4
      Pipfile
  4. 4
      Pipfile.lock
  5. 2
      common/url_file.py
  6. 5
      common/window.py
  7. 3
      scripts/waste.py
  8. 2
      selfdrive/controls/tests/test_clustering.py
  9. 50
      selfdrive/debug/internal/cycle_alerts.py
  10. 2
      selfdrive/debug/internal/sounds/test_sound_stability.py
  11. 2
      selfdrive/debug/internal/test_paramsd.py
  12. 2
      selfdrive/locationd/models/loc_kf.py
  13. 3
      selfdrive/loggerd/ethernetsniffer.py
  14. 5
      selfdrive/test/process_replay/inject_model.py
  15. 4
      selfdrive/test/test_eon_fan.py
  16. 3
      selfdrive/test/test_leeco_alt_fan.py
  17. 3
      selfdrive/test/test_leeco_fan.py
  18. 2
      tools/lib/framereader.py
  19. 21
      tools/lib/kbhit.py
  20. 10
      tools/lib/mkvparse/mkvgen.py
  21. 5
      tools/lib/mkvparse/mkvindex.py
  22. 5
      tools/lib/mkvparse/mkvparse.py
  23. 2
      tools/replay/unlog_segment.py
  24. 2
      tools/replay/unlogger.py
  25. 3
      tools/sim/bridge.py
  26. 3
      tools/sim/lib/can.py
  27. 4
      tools/sim/lib/manual_ctrl.py
  28. 2
      tools/streamer/streamerd.py

@ -0,0 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: master
hooks:
- id: check-ast
- id: check-json
- id: check-xml
- id: check-yaml
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
exclude: '^(pyextra)|(external)/'
args:
- --disable=R,C,W

@ -3,7 +3,7 @@
# A comma-separated list of package or module names from where C extensions may # A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may # be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code # run arbitrary code
extension-pkg-whitelist=scipy extension-pkg-whitelist=scipy cereal.messaging.messaging_pyx
# Add files or directories to the blacklist. They should be base names, not # Add files or directories to the blacklist. They should be base names, not
# paths. # paths.

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:48daf8ab5c86410503faaec54272993937b8dc2fd6793243689e91872f53136f oid sha256:c4ea33acc8b1f639f0719f436989886263a67271decbcf29ab8907208161da03
size 2026 size 2043

4
Pipfile.lock generated

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:6268aff3b5943f5f279e1c0c89f17914309d6245cfe5de3c64c8cd75c3acadda oid sha256:34b9162abbc667c0b14f418f43668422491613c32bfe8a7d8da86b3fc256350f
size 156137 size 165941

@ -1,3 +1,5 @@
# pylint: skip-file
import os import os
import time import time
import tempfile import tempfile

@ -27,10 +27,10 @@ class Window():
def getkey(self): def getkey(self):
while 1: while 1:
event = pygame.event.wait() event = pygame.event.wait()
if event.type == QUIT: if event.type == pygame.QUIT:
pygame.quit() pygame.quit()
sys.exit() sys.exit()
if event.type == KEYDOWN: if event.type == pygame.KEYDOWN:
return event.key return event.key
def getclick(self): def getclick(self):
@ -47,4 +47,3 @@ if __name__ == "__main__":
print("draw") print("draw")
img += 1 img += 1
win.draw(img) win.draw(img)

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from multiprocessing import Process from multiprocessing import Process
from setproctitle import setproctitle from setproctitle import setproctitle # pylint: disable=no-name-in-module
import os import os
import numpy as np import numpy as np
from common.realtime import sec_since_boot from common.realtime import sec_since_boot
@ -32,4 +32,3 @@ def main(gctx=None):
if __name__ == "__main__": if __name__ == "__main__":
main() main()

@ -1,3 +1,5 @@
# pylint: skip-file
import time import time
import unittest import unittest
import numpy as np import numpy as np

@ -1,50 +0,0 @@
# USAGE: python cycle_alerts.py [duration_millis=1000]
# Then start manager
import argparse
import time
import cereal.messaging as messaging
from selfdrive.controls.lib.alerts import ALERTS
def now_millis(): return time.time() * 1000
default_alerts = sorted(ALERTS, key=lambda alert: (alert.alert_size, len(alert.alert_text_2)))
def cycle_alerts(duration_millis, alerts=None):
if alerts is None:
alerts = default_alerts
controls_state = messaging.pub_sock('controlsState')
last_pop_millis = now_millis()
alert = alerts.pop()
while 1:
if (now_millis() - last_pop_millis) > duration_millis:
alerts.insert(0, alert)
alert = alerts.pop()
last_pop_millis = now_millis()
print('sending {}'.format(str(alert)))
dat = messaging.new_message('controlsState')
dat.controlsState.alertType = alert.alert_type
dat.controlsState.alertText1 = alert.alert_text_1
dat.controlsState.alertText2 = alert.alert_text_2
dat.controlsState.alertSize = alert.alert_size
dat.controlsState.alertStatus = alert.alert_status
dat.controlsState.alertSound = alert.audible_alert
controls_state.send(dat.to_bytes())
time.sleep(0.01)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--duration', type=int, default=1000)
parser.add_argument('--alert-types', nargs='+')
args = parser.parse_args()
alerts = None
if args.alert_types:
alerts = [next(a for a in ALERTS if a.alert_type==alert_type) for alert_type in args.alert_types]
cycle_alerts(args.duration, alerts=alerts)

@ -6,7 +6,7 @@ import datetime
import random import random
from common.basedir import BASEDIR from common.basedir import BASEDIR
from selfdrive import messaging import cereal.messaging as messaging
if __name__ == "__main__": if __name__ == "__main__":

@ -1,4 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# pylint: skip-file
import numpy as np import numpy as np
import math import math
from tqdm import tqdm from tqdm import tqdm

@ -443,8 +443,6 @@ class LocKalman():
r = self.predict_and_update_orb_features(data, t, kind) r = self.predict_and_update_orb_features(data, t, kind)
elif kind == ObservationKind.MSCKF_TEST: elif kind == ObservationKind.MSCKF_TEST:
r = self.predict_and_update_msckf_test(data, t, kind) r = self.predict_and_update_msckf_test(data, t, kind)
elif kind == ObservationKind.FEATURE_TRACK_TEST:
r = self.predict_and_update_feature_track_test(data, t, kind)
elif kind == ObservationKind.ODOMETRIC_SPEED: elif kind == ObservationKind.ODOMETRIC_SPEED:
r = self.predict_and_update_odo_speed(data, t, kind) r = self.predict_and_update_odo_speed(data, t, kind)
else: else:

@ -1,4 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# pylint: skip-file
import cereal.messaging as messaging import cereal.messaging as messaging
import pcap import pcap
@ -13,4 +15,3 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()

@ -85,8 +85,3 @@ def inject_model(msgs, segment_name):
assert abs(len(new_msgs) - len(list(msgs))) < 2 assert abs(len(new_msgs) - len(list(msgs))) < 2
return new_msgs return new_msgs
if __name__ == "__main__":
inject_model("0375fdf7b1ce594d|2019-06-13--08-32-25/3")

@ -2,7 +2,7 @@
import sys import sys
import time import time
from selfdrive.thermald import setup_eon_fan, set_eon_fan from selfdrive.thermald.thermald import setup_eon_fan, set_eon_fan
if __name__ == "__main__": if __name__ == "__main__":
val = 0 val = 0
@ -18,5 +18,3 @@ if __name__ == "__main__":
time.sleep(2) time.sleep(2)
val += 1 val += 1
val %= 4 val %= 4

@ -1,4 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# pylint: skip-file
import time import time
from smbus2 import SMBus from smbus2 import SMBus
@ -18,4 +20,3 @@ def setup_leon_fan():
bus.close() bus.close()
setup_leon_fan() setup_leon_fan()

@ -1,4 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# pylint: skip-file
import time import time
from smbus2 import SMBus from smbus2 import SMBus
@ -20,4 +22,3 @@ def setup_leon_fan():
bus.close() bus.close()
setup_leon_fan() setup_leon_fan()

@ -1,3 +1,5 @@
# pylint: skip-file
import os import os
import sys import sys
import json import json

@ -1,12 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python
import os
import sys import sys
import termios import termios
import atexit import atexit
from select import select from select import select
class KBHit:
class KBHit:
def __init__(self): def __init__(self):
'''Creates a KBHit object that you can call to do various keyboard things. '''Creates a KBHit object that you can call to do various keyboard things.
''' '''
@ -30,11 +29,7 @@ class KBHit:
''' Resets to normal terminal. On Windows this is a no-op. ''' Resets to normal terminal. On Windows this is a no-op.
''' '''
if os.name == 'nt': termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
pass
else:
termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)
def getch(self): def getch(self):
@ -53,14 +48,8 @@ class KBHit:
Should not be called in the same program as getch(). Should not be called in the same program as getch().
''' '''
if os.name == 'nt': c = sys.stdin.read(3)[2]
msvcrt.getch() # skip 0xE0 vals = [65, 67, 66, 68]
c = msvcrt.getch()
vals = [72, 77, 80, 75]
else:
c = sys.stdin.read(3)[2]
vals = [65, 67, 66, 68]
return vals.index(ord(c.decode('utf-8'))) return vals.index(ord(c.decode('utf-8')))
@ -88,5 +77,3 @@ if __name__ == "__main__":
print(c) print(c)
kb.set_normal_term() kb.set_normal_term()

@ -133,7 +133,7 @@ def example():
def mp3framesgenerator(f): def mp3framesgenerator(f):
debt="" debt=""
while True: while True:
for i in xrange(0,len(debt)+1): for i in range(0,len(debt)+1):
if i >= len(debt)-1: if i >= len(debt)-1:
debt = debt + f.read(8192) debt = debt + f.read(8192)
break break
@ -147,10 +147,10 @@ def example():
mp3 = mp3framesgenerator(mp3file) mp3 = mp3framesgenerator(mp3file)
mp3.next() next(mp3)
for i in xrange(0,530): for i in range(0,530):
framefile = open("img/"+str(i)+".jpg", "rb") framefile = open("img/"+str(i)+".jpg", "rb")
framedata = framefile.read() framedata = framefile.read()
framefile.close() framefile.close()
@ -168,8 +168,8 @@ def example():
+ framedata + framedata
))) )))
for u in xrange(0,4): for u in range(0,4):
mp3f=mp3.next() mp3f=next(mp3)
if random.random()<1: if random.random()<1:
sys.stdout.write(ebml_element(0x1F43B675, "" # Cluster sys.stdout.write(ebml_element(0x1F43B675, "" # Cluster
+ ebml_element(0xE7, ben(i*26*4+u*26)) # TimeCode, uint, milliseconds + ebml_element(0xE7, ben(i*26*4+u*26)) # TimeCode, uint, milliseconds

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
# Copyright (c) 2016, Comma.ai, Inc. # flake8: noqa
import re import re
import binascii import binascii
@ -15,7 +15,7 @@ class MatroskaIndex(mkvparse.MatroskaHandler):
self.frameindex = [] self.frameindex = []
def tracks_available(self): def tracks_available(self):
_, self.config_record = self.tracks[1]['CodecPrivate'] _, self.config_record = self.tracks[1]['CodecPrivate'] # pylint: disable=no-member
def frame(self, track_id, timestamp, pos, length, more_laced_frames, duration, def frame(self, track_id, timestamp, pos, length, more_laced_frames, duration,
keyframe, invisible, discardable): keyframe, invisible, discardable):
@ -62,4 +62,3 @@ def simple_gen(of, config_record, w, h, framedata):
+ ebml_element(0xE7, ben(0)) # TimeCode, uint, milliseconds + ebml_element(0xE7, ben(0)) # TimeCode, uint, milliseconds
# + ebml_element(0xA7, ben(0)) # Position, uint # + ebml_element(0xA7, ben(0)) # Position, uint
+ ''.join(blocks))) + ''.join(blocks)))

@ -7,6 +7,7 @@
# No proper EOF handling unfortunately # No proper EOF handling unfortunately
# See "mkvuser.py" for the example # See "mkvuser.py" for the example
# pylint: skip-file
import traceback import traceback
from struct import unpack from struct import unpack
@ -15,7 +16,7 @@ import sys
import datetime import datetime
if sys.version < '3': if sys.version < '3':
range=xrange range=xrange # pylint disable=undefined-variable
else: else:
#identity=lambda x:x #identity=lambda x:x
def ord(something): def ord(something):
@ -510,7 +511,7 @@ def read_ebml_element_tree(f, total_size):
while(total_size>0): while(total_size>0):
(id_, size, hsize) = read_ebml_element_header(f) (id_, size, hsize) = read_ebml_element_header(f)
if size == -1: if size == -1:
sys.stderr.write("mkvparse: Element %x without size? Damaged data? Skipping %d bytes\n" % (id_, size, total_size)) sys.stderr.write("mkvparse: Element %x without size? Damaged data? Skipping %d bytes\n" % (id_, size, total_size)) # pylint disable=too-many-format-args
f.read(total_size); f.read(total_size);
break; break;
if size>total_size: if size>total_size:

@ -1,4 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# pylint: skip-file
import argparse import argparse
import bisect import bisect
import select import select

@ -421,7 +421,7 @@ def main(argv):
if not p.is_alive(): if not p.is_alive():
[p.terminate() for p in subprocesses.values()] [p.terminate() for p in subprocesses.values()]
exit() exit()
signal.signal(signal.SIGCHLD, signal.SIGIGN) signal.signal(signal.SIGCHLD, signal.SIG_IGN)
signal.signal(signal.SIGCHLD, exit_if_children_dead) signal.signal(signal.SIGCHLD, exit_if_children_dead)
if args.interactive: if args.interactive:

@ -79,7 +79,7 @@ def go(q):
threading.Thread(target=health_function).start() threading.Thread(target=health_function).start()
threading.Thread(target=fake_driver_monitoring).start() threading.Thread(target=fake_driver_monitoring).start()
import carla import carla # pylint: disable=import-error
client = carla.Client("127.0.0.1", 2000) client = carla.Client("127.0.0.1", 2000)
client.set_timeout(5.0) client.set_timeout(5.0)
world = client.load_world('Town04') world = client.load_world('Town04')
@ -246,4 +246,3 @@ if __name__ == "__main__":
# start input poll for keyboard # start input poll for keyboard
from lib.keyboard_ctrl import keyboard_poll_thread from lib.keyboard_ctrl import keyboard_poll_thread
keyboard_poll_thread(q) keyboard_poll_thread(q)

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import cereal.messaging as messaging import cereal.messaging as messaging
from opendbc.can.packer import CANPacker from opendbc.can.packer import CANPacker
from selfdrive.boardd.boardd_api_impl import can_list_to_can_capnp from selfdrive.boardd.boardd_api_impl import can_list_to_can_capnp # pylint: disable=no-name-in-module
from selfdrive.car.honda.values import FINGERPRINTS, CAR from selfdrive.car.honda.values import FINGERPRINTS, CAR
from selfdrive.car import crc8_pedal from selfdrive.car import crc8_pedal
import math import math
@ -88,4 +88,3 @@ def sendcan_function(sendcan):
steer_torque = 0.0 steer_torque = 0.0
return (gas, brake, steer_torque) return (gas, brake, steer_torque)

@ -132,8 +132,8 @@ def wheel_poll_thread(q):
print('%d buttons found: %s' % (num_buttons, ', '.join(button_map))) print('%d buttons found: %s' % (num_buttons, ', '.join(button_map)))
# Enable FF # Enable FF
import evdev import evdev # pylint: disable=import-error
from evdev import ecodes, InputDevice, ff from evdev import ecodes, InputDevice, ff # pylint: disable=import-error
device = evdev.list_devices()[0] device = evdev.list_devices()[0]
evtdev = InputDevice(device) evtdev = InputDevice(device)
val = 24000 val = 24000

@ -1,4 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
# pylint: skip-file
import os import os
import sys import sys
import zmq import zmq

Loading…
Cancel
Save