Skip to content

Commit

Permalink
pre-commit pylint (#1580)
Browse files Browse the repository at this point in the history
* "The commit-hook project sounds interesting though. I would definitely merge something that runs flake8 and pylint on the modified files!"
-  pd0wm, #1575 (comment)

* add pylint to pre-commit and make everything pass

* Remove uncommented stuff

Co-authored-by: J <user@4800.lan>
  • Loading branch information
pd0wm and J committed May 28, 2020
1 parent c188648 commit bd06434
Show file tree
Hide file tree
Showing 28 changed files with 350 additions and 249 deletions.
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
@@ -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
2 changes: 1 addition & 1 deletion .pylintrc
Expand Up @@ -3,7 +3,7 @@
# 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
# 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
# paths.
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Expand Up @@ -72,6 +72,7 @@ scikit-image = "*"
pygame = "==2.0.0.dev8"
pprofile = "*"
pyprof2calltree = "*"
pre-commit = "*"

[packages]
atomicwrites = "*"
Expand Down
369 changes: 256 additions & 113 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions common/url_file.py
@@ -1,3 +1,5 @@
# pylint: skip-file

import os
import time
import tempfile
Expand Down
5 changes: 2 additions & 3 deletions common/window.py
Expand Up @@ -27,10 +27,10 @@ def draw(self, out):
def getkey(self):
while 1:
event = pygame.event.wait()
if event.type == QUIT:
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.type == pygame.KEYDOWN:
return event.key

def getclick(self):
Expand All @@ -47,4 +47,3 @@ def getclick(self):
print("draw")
img += 1
win.draw(img)

3 changes: 1 addition & 2 deletions scripts/waste.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
from multiprocessing import Process
from setproctitle import setproctitle
from setproctitle import setproctitle # pylint: disable=no-name-in-module
import os
import numpy as np
from common.realtime import sec_since_boot
Expand Down Expand Up @@ -32,4 +32,3 @@ def main(gctx=None):

if __name__ == "__main__":
main()

2 changes: 2 additions & 0 deletions selfdrive/controls/tests/test_clustering.py
@@ -1,3 +1,5 @@
# pylint: skip-file

import time
import unittest
import numpy as np
Expand Down
50 changes: 0 additions & 50 deletions selfdrive/debug/internal/cycle_alerts.py

This file was deleted.

2 changes: 1 addition & 1 deletion selfdrive/debug/internal/sounds/test_sound_stability.py
Expand Up @@ -6,7 +6,7 @@
import random

from common.basedir import BASEDIR
from selfdrive import messaging
import cereal.messaging as messaging

if __name__ == "__main__":

Expand Down
2 changes: 2 additions & 0 deletions selfdrive/debug/internal/test_paramsd.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
# pylint: skip-file

import numpy as np
import math
from tqdm import tqdm
Expand Down
2 changes: 0 additions & 2 deletions selfdrive/locationd/models/loc_kf.py
Expand Up @@ -443,8 +443,6 @@ def predict_and_observe(self, t, kind, data):
r = self.predict_and_update_orb_features(data, t, kind)
elif kind == ObservationKind.MSCKF_TEST:
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:
r = self.predict_and_update_odo_speed(data, t, kind)
else:
Expand Down
3 changes: 2 additions & 1 deletion selfdrive/loggerd/ethernetsniffer.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
# pylint: skip-file

import cereal.messaging as messaging
import pcap

Expand All @@ -13,4 +15,3 @@ def main():

if __name__ == "__main__":
main()

5 changes: 0 additions & 5 deletions selfdrive/test/process_replay/inject_model.py
Expand Up @@ -85,8 +85,3 @@ def inject_model(msgs, segment_name):
assert abs(len(new_msgs) - len(list(msgs))) < 2

return new_msgs



if __name__ == "__main__":
inject_model("0375fdf7b1ce594d|2019-06-13--08-32-25/3")
4 changes: 1 addition & 3 deletions selfdrive/test/test_eon_fan.py
Expand Up @@ -2,7 +2,7 @@

import sys
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__":
val = 0
Expand All @@ -18,5 +18,3 @@
time.sleep(2)
val += 1
val %= 4


3 changes: 2 additions & 1 deletion selfdrive/test/test_leeco_alt_fan.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
# pylint: skip-file

import time
from smbus2 import SMBus

Expand All @@ -18,4 +20,3 @@ def setup_leon_fan():
bus.close()

setup_leon_fan()

3 changes: 2 additions & 1 deletion selfdrive/test/test_leeco_fan.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
# pylint: skip-file

import time
from smbus2 import SMBus

Expand All @@ -20,4 +22,3 @@ def setup_leon_fan():
bus.close()

setup_leon_fan()

2 changes: 2 additions & 0 deletions tools/lib/framereader.py
@@ -1,3 +1,5 @@
# pylint: skip-file

import os
import sys
import json
Expand Down
47 changes: 17 additions & 30 deletions tools/lib/kbhit.py
@@ -1,18 +1,17 @@
#!/usr/bin/env python
import os
import sys
import termios
import atexit
from select import select


class KBHit:

def __init__(self):
'''Creates a KBHit object that you can call to do various keyboard things.
'''

self.set_kbhit_terminal()
self.set_kbhit_terminal()

def set_kbhit_terminal(self):
# Save the terminal settings
self.fd = sys.stdin.fileno()
Expand All @@ -29,20 +28,16 @@ def set_kbhit_terminal(self):
def set_normal_term(self):
''' Resets to normal terminal. On Windows this is a no-op.
'''

if os.name == 'nt':
pass

else:
termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)

termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term)


def getch(self):
''' Returns a keyboard character after kbhit() has been called.
Should not be called in the same program as getarrow().
'''
return sys.stdin.read(1)


def getarrow(self):
''' Returns an arrow-key code after kbhit() has been called. Codes are
Expand All @@ -52,29 +47,23 @@ def getarrow(self):
3 : left
Should not be called in the same program as getch().
'''

if os.name == 'nt':
msvcrt.getch() # skip 0xE0
c = msvcrt.getch()
vals = [72, 77, 80, 75]

else:
c = sys.stdin.read(3)[2]
vals = [65, 67, 66, 68]


c = sys.stdin.read(3)[2]
vals = [65, 67, 66, 68]

return vals.index(ord(c.decode('utf-8')))


def kbhit(self):
''' Returns True if keyboard character was hit, False otherwise.
'''
'''
dr,dw,de = select([sys.stdin], [], [], 0)
return dr != []
# Test


# Test
if __name__ == "__main__":

kb = KBHit()

print('Hit any key, or ESC to exit')
Expand All @@ -86,7 +75,5 @@ def kbhit(self):
if ord(c) == 27: # ESC
break
print(c)

kb.set_normal_term()


kb.set_normal_term()
16 changes: 8 additions & 8 deletions tools/lib/mkvparse/mkvgen.py
Expand Up @@ -4,7 +4,7 @@
import math

# Simple hacky Matroska generator
# Reads mp3 file "q.mp3" and jpeg images from img/0.jpg, img/1.jpg and so on and
# Reads mp3 file "q.mp3" and jpeg images from img/0.jpg, img/1.jpg and so on and
# writes Matroska file with mjpeg and mp3 to stdout

# License=MIT
Expand Down Expand Up @@ -71,7 +71,7 @@ def random_uid():
def rint():
return int(random.random()*(0x100**4))
return ben(rint()) + ben(rint()) + ben(rint()) + ben(rint())


def example():
write_ebml_header(sys.stdout, "matroska", 2, 2)
Expand Down Expand Up @@ -133,7 +133,7 @@ def example():
def mp3framesgenerator(f):
debt=""
while True:
for i in xrange(0,len(debt)+1):
for i in range(0,len(debt)+1):
if i >= len(debt)-1:
debt = debt + f.read(8192)
break
Expand All @@ -144,13 +144,13 @@ def mp3framesgenerator(f):
# sys.stderr.write("len="+str(i)+"\n")
debt = debt[i:]
break


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")
framedata = framefile.read()
framefile.close()
Expand All @@ -168,8 +168,8 @@ def mp3framesgenerator(f):
+ framedata
)))

for u in xrange(0,4):
mp3f=mp3.next()
for u in range(0,4):
mp3f=next(mp3)
if random.random()<1:
sys.stdout.write(ebml_element(0x1F43B675, "" # Cluster
+ ebml_element(0xE7, ben(i*26*4+u*26)) # TimeCode, uint, milliseconds
Expand Down
5 changes: 2 additions & 3 deletions tools/lib/mkvparse/mkvindex.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (c) 2016, Comma.ai, Inc.
# flake8: noqa

import re
import binascii
Expand All @@ -15,7 +15,7 @@ def __init__(self):
self.frameindex = []

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,
keyframe, invisible, discardable):
Expand Down Expand Up @@ -62,4 +62,3 @@ def simple_gen(of, config_record, w, h, framedata):
+ ebml_element(0xE7, ben(0)) # TimeCode, uint, milliseconds
# + ebml_element(0xA7, ben(0)) # Position, uint
+ ''.join(blocks)))

0 comments on commit bd06434

Please sign in to comment.