diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 43c90dc97a..57821c9c6f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,7 +37,7 @@ jobs: # need these so docker copy won't fail cp Pipfile Pipfile.lock flake8_openpilot.sh pylint_openpilot.sh .pylintrc \ - cppcheck_openpilot.sh .coveragerc-app $TEST_DIR + cppcheck_openpilot.sh .coveragerc-app .pre-commit-config.yaml $TEST_DIR cd $TEST_DIR mkdir pyextra laika laika_repo tools release - name: Build Docker image @@ -77,6 +77,8 @@ jobs: run: $RUN "cd /tmp/openpilot/ && ./flake8_openpilot.sh" - name: pylint run: $RUN "cd /tmp/openpilot/ && ./pylint_openpilot.sh" + - name: pre-commit + run: $RUN "cd /tmp/openpilot/ && git init && git add -A && pre-commit run --all" - name: cppcheck run: $PERSIST "cd /tmp/openpilot/ && ./cppcheck_openpilot.sh 2> cppcheck_report.txt" - name: Print cppcheck report diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 71f442a536..a347c57bf2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: rev: master hooks: - id: flake8 - exclude: '^(pyextra)|(external)/' + exclude: '^(pyextra)|(external)|(cereal)|(rednose)|(panda)|(laika)|(laika_repo)|(rednose_repo)/' args: - --select=F - repo: local @@ -25,6 +25,6 @@ repos: entry: pylint language: system types: [python] - exclude: '^(pyextra)|(external)/' + exclude: '^(pyextra)|(external)|(cereal)|(rednose)|(panda)|(laika)|(laika_repo)|(rednose_repo)/' args: - --disable=R,C,W diff --git a/Dockerfile.openpilot b/Dockerfile.openpilot index 205e5f198c..0ef6912418 100644 --- a/Dockerfile.openpilot +++ b/Dockerfile.openpilot @@ -71,7 +71,8 @@ RUN pyenv install 3.8.2 && \ azure-storage-common==2.1.0 \ azure-storage-nspkg==3.1.0 \ pycurl==7.43.0.3 \ - coverage==5.1 + coverage==5.1 \ + pre-commit==2.4.0 RUN mkdir -p /tmp/openpilot @@ -80,6 +81,7 @@ COPY SConstruct \ flake8_openpilot.sh \ pylint_openpilot.sh \ .pylintrc \ + .pre-commit-config.yaml \ .coveragerc-app \ /tmp/openpilot/ diff --git a/common/window.py b/common/window.py index 7454a86207..8c36fa5432 100644 --- a/common/window.py +++ b/common/window.py @@ -1,6 +1,6 @@ import sys -import pygame -import cv2 +import pygame # pylint: disable=import-error +import cv2 # pylint: disable=import-error class Window(): def __init__(self, w, h, caption="window", double=False): diff --git a/release/remote_build.py b/release/remote_build.py index f80843cef9..d9785e0b6f 100755 --- a/release/remote_build.py +++ b/release/remote_build.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -import paramiko +import paramiko # pylint: disable=import-error import os import sys import re diff --git a/selfdrive/camerad/test/yuv_bench/cnv.py b/selfdrive/camerad/test/yuv_bench/cnv.py index 86fd0c9982..24fde0875a 100644 --- a/selfdrive/camerad/test/yuv_bench/cnv.py +++ b/selfdrive/camerad/test/yuv_bench/cnv.py @@ -1,5 +1,5 @@ import numpy as np -import cv2 +import cv2 # pylint: disable=import-error # img_bgr = np.zeros((874, 1164, 3), dtype=np.uint8) # for y in range(874): diff --git a/selfdrive/debug/internal/design_lqr.py b/selfdrive/debug/internal/design_lqr.py index 0304df5aa1..fcc2524f2c 100755 --- a/selfdrive/debug/internal/design_lqr.py +++ b/selfdrive/debug/internal/design_lqr.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 import numpy as np -import control +import control # pylint: disable=import-error dt = 0.01 A = np.array([[ 0. , 1. ], [-0.78823806, 1.78060701]]) diff --git a/selfdrive/modeld/runners/keras_runner.py b/selfdrive/modeld/runners/keras_runner.py index 4dfd197673..5ed0e6d79c 100755 --- a/selfdrive/modeld/runners/keras_runner.py +++ b/selfdrive/modeld/runners/keras_runner.py @@ -2,13 +2,13 @@ # TODO: why are the keras models saved with python 2? from __future__ import print_function -import tensorflow as tf +import tensorflow as tf # pylint: disable=import-error import os import sys -import tensorflow.keras as keras +import tensorflow.keras as keras # pylint: disable=import-error import numpy as np -from tensorflow.keras.models import Model -from tensorflow.keras.models import load_model +from tensorflow.keras.models import Model # pylint: disable=import-error +from tensorflow.keras.models import load_model # pylint: disable=import-error def read(sz): dd = [] @@ -55,4 +55,3 @@ if __name__ == "__main__": no = keras.layers.Concatenate()(m(tii)) m = Model(inputs=ri, outputs=[no]) run_loop(m) - diff --git a/selfdrive/modeld/test/tf_test/pb_loader.py b/selfdrive/modeld/test/tf_test/pb_loader.py index d4db20eb66..78fd33aef2 100755 --- a/selfdrive/modeld/test/tf_test/pb_loader.py +++ b/selfdrive/modeld/test/tf_test/pb_loader.py @@ -1,9 +1,8 @@ #!/usr/bin/env python3 import sys -import tensorflow as tf +import tensorflow as tf # pylint: disable=import-error with open(sys.argv[1], "rb") as f: graph_def = tf.compat.v1.GraphDef() graph_def.ParseFromString(f.read()) #tf.io.write_graph(graph_def, '', sys.argv[1]+".try") - diff --git a/selfdrive/test/profiling/controlsd.py b/selfdrive/test/profiling/controlsd.py index 38ce860d35..329e6a8d93 100755 --- a/selfdrive/test/profiling/controlsd.py +++ b/selfdrive/test/profiling/controlsd.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 import os -import cProfile -import pprofile -import pyprof2calltree +import cProfile # pylint: disable=import-error +import pprofile # pylint: disable=import-error +import pyprof2calltree # pylint: disable=import-error from tools.lib.logreader import LogReader from selfdrive.controls.controlsd import main as controlsd_thread diff --git a/tools/carcontrols/joystick_test.py b/tools/carcontrols/joystick_test.py index e031fb506f..1a41d4729c 100755 --- a/tools/carcontrols/joystick_test.py +++ b/tools/carcontrols/joystick_test.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -import pygame +import pygame # pylint: disable=import-error # Define some colors BLACK = ( 0, 0, 0) @@ -17,21 +17,21 @@ class TextPrint: textBitmap = self.font.render(textString, True, BLACK) screen.blit(textBitmap, [self.x, self.y]) self.y += self.line_height - + def reset(self): self.x = 10 self.y = 10 self.line_height = 15 - + def indent(self): self.x += 10 - + def unindent(self): self.x -= 10 - + pygame.init() - + # Set the width and height of the screen [width,height] size = [500, 700] screen = pygame.display.set_mode(size) @@ -46,7 +46,7 @@ clock = pygame.time.Clock() # Initialize the joysticks pygame.joystick.init() - + # Get ready to print textPrint = TextPrint() @@ -56,14 +56,14 @@ while done==False: for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close done=True # Flag that we are done so we exit this loop - + # Possible joystick actions: JOYAXISMOTION JOYBALLMOTION JOYBUTTONDOWN JOYBUTTONUP JOYHATMOTION if event.type == pygame.JOYBUTTONDOWN: print("Joystick button pressed.") if event.type == pygame.JOYBUTTONUP: print("Joystick button released.") - - + + # DRAWING STEP # First, clear the screen to white. Don't put other drawing commands # above this, or they will be erased with this command. @@ -75,29 +75,29 @@ while done==False: textPrint.printf(screen, "Number of joysticks: {}".format(joystick_count) ) textPrint.indent() - + # For each joystick: joystick = pygame.joystick.Joystick(0) joystick.init() - + textPrint.printf(screen, "Joystick {}".format(0) ) textPrint.indent() - + # Get the name from the OS for the controller/joystick name = joystick.get_name() textPrint.printf(screen, "Joystick name: {}".format(name) ) - + # Usually axis run in pairs, up/down for one, and left/right for # the other. axes = joystick.get_numaxes() textPrint.printf(screen, "Number of axes: {}".format(axes) ) textPrint.indent() - + for i in range( axes ): axis = joystick.get_axis( i ) textPrint.printf(screen, "Axis {} value: {:>6.3f}".format(i, axis) ) textPrint.unindent() - + buttons = joystick.get_numbuttons() textPrint.printf(screen, "Number of buttons: {}".format(buttons) ) textPrint.indent() @@ -110,15 +110,15 @@ while done==False: textPrint.unindent() - + # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT - + # Go ahead and update the screen with what we've drawn. pygame.display.flip() # Limit to 20 frames per second clock.tick(20) - + # Close the window and quit. # If you forget this line, the program will 'hang' # on exit if running from IDLE. diff --git a/tools/carcontrols/joystickd.py b/tools/carcontrols/joystickd.py index b262694e6f..a441763709 100755 --- a/tools/carcontrols/joystickd.py +++ b/tools/carcontrols/joystickd.py @@ -6,7 +6,7 @@ ### this process needs pygame and can't run on the EON ### -import pygame +import pygame # pylint: disable=import-error import cereal.messaging as messaging def joystick_thread(): diff --git a/tools/livedm/helpers.py b/tools/livedm/helpers.py index 47a79a67cb..df392bfd9b 100644 --- a/tools/livedm/helpers.py +++ b/tools/livedm/helpers.py @@ -1,5 +1,5 @@ import numpy as np -import cv2 +import cv2 # pylint: disable=import-error def rot_matrix(roll, pitch, yaw): cr, sr = np.cos(roll), np.sin(roll) @@ -27,4 +27,3 @@ def draw_pose(img, pose, loc, W=160, H=320, xyoffset=(0,0), faceprob=0): else: color = (64,64,64) cv2.circle(img, tr, 7, color=color) - \ No newline at end of file diff --git a/tools/livedm/livedm.py b/tools/livedm/livedm.py index 60361d9207..360aaee602 100644 --- a/tools/livedm/livedm.py +++ b/tools/livedm/livedm.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 import os import argparse -import pygame +import pygame # pylint: disable=import-error import numpy as np -import cv2 +import cv2 # pylint: disable=import-error from cereal import log import cereal.messaging as messaging diff --git a/tools/replay/camera.py b/tools/replay/camera.py index c312f52737..9860f7521b 100755 --- a/tools/replay/camera.py +++ b/tools/replay/camera.py @@ -6,9 +6,9 @@ os.environ['BASEDIR'] = BASEDIR SCALE = float(os.getenv("SCALE", 1.0)) import argparse -import pygame +import pygame # pylint: disable=import-error import numpy as np -import cv2 +import cv2 # pylint: disable=import-error import sys import cereal.messaging as messaging diff --git a/tools/replay/lib/ui_helpers.py b/tools/replay/lib/ui_helpers.py index 4debec40e2..78cbefddf5 100644 --- a/tools/replay/lib/ui_helpers.py +++ b/tools/replay/lib/ui_helpers.py @@ -4,7 +4,7 @@ from typing import Any, Dict, Tuple import matplotlib import matplotlib.pyplot as plt import numpy as np -import pygame +import pygame # pylint: disable=import-error from selfdrive.config import RADAR_TO_CAMERA from selfdrive.config import UIParams as UP diff --git a/tools/replay/sensorium.py b/tools/replay/sensorium.py index b85d6ef8c0..a7d9ee6819 100755 --- a/tools/replay/sensorium.py +++ b/tools/replay/sensorium.py @@ -3,7 +3,7 @@ # Question: Can a human drive from this data? import os -import cv2 +import cv2 # pylint: disable=import-error import numpy as np import cereal.messaging as messaging from common.window import Window @@ -49,5 +49,3 @@ if __name__ == "__main__": flags=cv2.WARP_INVERSE_MAP | cv2.INTER_CUBIC) win.draw(imgw) - - diff --git a/tools/replay/ui.py b/tools/replay/ui.py index ee07a28137..9d30c38522 100755 --- a/tools/replay/ui.py +++ b/tools/replay/ui.py @@ -5,9 +5,9 @@ import sys os.environ["OMP_NUM_THREADS"] = "1" -import cv2 +import cv2 # pylint: disable=import-error import numpy as np -import pygame +import pygame # pylint: disable=import-error from common.basedir import BASEDIR from common.transformations.camera import FULL_FRAME_SIZE, eon_intrinsics diff --git a/tools/sim/lib/can.py b/tools/sim/lib/can.py index a446d38cd5..9fbb2006f1 100755 --- a/tools/sim/lib/can.py +++ b/tools/sim/lib/can.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import cereal.messaging as messaging from opendbc.can.packer import CANPacker -from selfdrive.boardd.boardd_api_impl import can_list_to_can_capnp # pylint: disable=no-name-in-module +from selfdrive.boardd.boardd_api_impl import can_list_to_can_capnp # pylint: disable=no-name-in-module,import-error from selfdrive.car.honda.values import FINGERPRINTS, CAR from selfdrive.car import crc8_pedal import math diff --git a/tools/webcam/front_mount_helper.py b/tools/webcam/front_mount_helper.py index 1fdca3225a..78b707950e 100755 --- a/tools/webcam/front_mount_helper.py +++ b/tools/webcam/front_mount_helper.py @@ -18,7 +18,7 @@ webcam_intrinsics = np.array([ cam_id = 2 if __name__ == "__main__": - import cv2 + import cv2 # pylint: disable=import-error trans_webcam_to_eon_front = np.dot(eon_dcam_intrinsics,np.linalg.inv(webcam_intrinsics)) @@ -32,4 +32,4 @@ if __name__ == "__main__": img = cv2.warpPerspective(img, trans_webcam_to_eon_front, (1152,864), borderMode=cv2.BORDER_CONSTANT, borderValue=0) img = img[:,-864//2:,:] cv2.imshow('preview', img) - cv2.waitKey(10) \ No newline at end of file + cv2.waitKey(10) diff --git a/tools/webcam/warp_vis.py b/tools/webcam/warp_vis.py index 547f1be99a..a1cb3e7e45 100755 --- a/tools/webcam/warp_vis.py +++ b/tools/webcam/warp_vis.py @@ -23,7 +23,7 @@ webcam_intrinsics = np.array([ [ 0., 0., 1.]]) if __name__ == "__main__": - import cv2 + import cv2 # pylint: disable=import-error trans_webcam_to_eon_rear = np.dot(eon_intrinsics,np.linalg.inv(webcam_intrinsics)) trans_webcam_to_eon_front = np.dot(eon_dcam_intrinsics,np.linalg.inv(webcam_intrinsics)) print("trans_webcam_to_eon_rear:\n", trans_webcam_to_eon_rear) @@ -41,5 +41,3 @@ if __name__ == "__main__": print(img.shape, end='\r') cv2.imshow('preview', img) cv2.waitKey(10) - -