diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 990e2781..96ba5e5e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,6 +6,13 @@ repos: - id: check-json - id: check-xml - id: check-yaml +- repo: https://gitlab.com/PyCQA/flake8 + rev: master + hooks: + - id: flake8 + exclude: '^(pyextra)|(external)/' + args: + - --select=F - repo: local hooks: - id: pylint diff --git a/common/tests/test_numpy_fast.py b/common/tests/test_numpy_fast.py index bf34de2e..2fb8a1ce 100644 --- a/common/tests/test_numpy_fast.py +++ b/common/tests/test_numpy_fast.py @@ -1,6 +1,5 @@ import numpy as np import unittest -import timeit from common.numpy_fast import interp diff --git a/selfdrive/camerad/test/frame_test.py b/selfdrive/camerad/test/frame_test.py index 2518e803..d7b677c2 100755 --- a/selfdrive/camerad/test/frame_test.py +++ b/selfdrive/camerad/test/frame_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import time import numpy as np import cereal.messaging as messaging from PIL import ImageFont, ImageDraw, Image @@ -36,4 +35,3 @@ if __name__ == "__main__": idx += 1 rk.keep_time() #time.sleep(1.0) - diff --git a/selfdrive/locationd/liblocationd_py.py b/selfdrive/locationd/liblocationd_py.py index d9f71b8c..09d2bb75 100644 --- a/selfdrive/locationd/liblocationd_py.py +++ b/selfdrive/locationd/liblocationd_py.py @@ -1,5 +1,4 @@ import os -from common.basedir import BASEDIR from cffi import FFI diff --git a/selfdrive/locationd/models/loc_kf.py b/selfdrive/locationd/models/loc_kf.py index fbb6b1b5..06e16045 100755 --- a/selfdrive/locationd/models/loc_kf.py +++ b/selfdrive/locationd/models/loc_kf.py @@ -340,7 +340,7 @@ class LocKalman(): for n in range(N): idx = dim_main + n * dim_augment - err_idx = dim_main_err + n * dim_augment_err # FIXME: Why is this not used? + # err_idx = dim_main_err + n * dim_augment_err # FIXME: Why is this not used? x, y, z = state[idx:idx + 3] q = state[idx + 3:idx + 7] quat_rot = quat_rotate(*q) diff --git a/selfdrive/test/eon_testing_slave.py b/selfdrive/test/eon_testing_slave.py index 008b8c63..e4b8ae1c 100755 --- a/selfdrive/test/eon_testing_slave.py +++ b/selfdrive/test/eon_testing_slave.py @@ -36,11 +36,11 @@ def get_workdir(): def heartbeat(): work_dir = get_workdir() - env = { - "LD_LIBRARY_PATH": "", - "ANDROID_DATA": "/data", - "ANDROID_ROOT": "/system", - } + # env = { + # "LD_LIBRARY_PATH": "", + # "ANDROID_DATA": "/data", + # "ANDROID_ROOT": "/system", + # } while True: try: @@ -53,7 +53,7 @@ def heartbeat(): try: tmux = os.popen('tail -n 100 /tmp/tmux_out').read() - except: + except Exception: pass params = Params() diff --git a/selfdrive/test/process_replay/inject_model.py b/selfdrive/test/process_replay/inject_model.py index 38647b45..98a6794d 100755 --- a/selfdrive/test/process_replay/inject_model.py +++ b/selfdrive/test/process_replay/inject_model.py @@ -1,14 +1,12 @@ #!/usr/bin/env python3 -import os import time - from tqdm import tqdm + +import selfdrive.manager as manager from cereal.messaging import PubMaster, recv_one, sub_sock from tools.lib.framereader import FrameReader -import subprocess -import selfdrive.manager as manager def rreplace(s, old, new, occurrence): @@ -22,7 +20,6 @@ def regen_model(msgs, pm, frame_reader, model_sock): if msg.which() == 'liveCalibration': pm.send('liveCalibration', msg.as_builder()) - out_msgs = [] fidx = 0 for msg in tqdm(msgs): diff --git a/selfdrive/test/profiling/controlsd.py b/selfdrive/test/profiling/controlsd.py index 6ea31144..38ce860d 100755 --- a/selfdrive/test/profiling/controlsd.py +++ b/selfdrive/test/profiling/controlsd.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import os -import time import cProfile import pprofile import pyprof2calltree diff --git a/selfdrive/test/test_leeco_alt_fan.py b/selfdrive/test/test_leeco_alt_fan.py index c10ede34..c14d943e 100755 --- a/selfdrive/test/test_leeco_alt_fan.py +++ b/selfdrive/test/test_leeco_alt_fan.py @@ -11,10 +11,10 @@ def setup_leon_fan(): for i in [0,1,2,3]: print("FAN SPEED", i) if i == 0: - ret = bus.write_i2c_block_data(0x67, 0xa, [0]) + bus.write_i2c_block_data(0x67, 0xa, [0]) else: - ret = bus.write_i2c_block_data(0x67, 0xa, [0x20]) - ret = bus.write_i2c_block_data(0x67, 0x8, [(i-1)<<6]) + bus.write_i2c_block_data(0x67, 0xa, [0x20]) + bus.write_i2c_block_data(0x67, 0x8, [(i-1)<<6]) time.sleep(1) bus.close() diff --git a/selfdrive/test/update_ci_routes.py b/selfdrive/test/update_ci_routes.py index 09b8d170..77db2929 100755 --- a/selfdrive/test/update_ci_routes.py +++ b/selfdrive/test/update_ci_routes.py @@ -1,6 +1,4 @@ #!/usr/bin/env python3 -import tempfile -import shutil import subprocess from common.basedir import BASEDIR from azure.storage.blob import BlockBlobService @@ -8,8 +6,7 @@ from azure.storage.blob import BlockBlobService from selfdrive.test.test_car_models import routes as test_car_models_routes from selfdrive.test.process_replay.test_processes import segments as replay_segments from xx.chffr.lib import azureutil -from xx.chffr.lib.storage import upload_dir_serial, download_dir_tpe -from xx.chffr.lib.storage import _DATA_ACCOUNT_PRODUCTION, _DATA_ACCOUNT_CI, _DATA_BUCKET_PRODUCTION, _DATA_BUCKET_CI +from xx.chffr.lib.storage import _DATA_ACCOUNT_PRODUCTION, _DATA_ACCOUNT_CI, _DATA_BUCKET_PRODUCTION SOURCES = [ (_DATA_ACCOUNT_PRODUCTION, _DATA_BUCKET_PRODUCTION), diff --git a/tools/lib/framereader.py b/tools/lib/framereader.py index 741f51da..695be4ab 100644 --- a/tools/lib/framereader.py +++ b/tools/lib/framereader.py @@ -8,6 +8,7 @@ import tempfile import threading import xml.etree.ElementTree as ET import numpy as np +import _io if sys.version_info >= (3,0): import queue import pickle @@ -83,7 +84,7 @@ def ffprobe(fn, fmt=None): try: ffprobe_output = subprocess.check_output(cmd) - except subprocess.CalledProcessError as e: + except subprocess.CalledProcessError: raise DataUnreadableError(fn) return json.loads(ffprobe_output) @@ -99,7 +100,7 @@ def vidindex(fn, typ): tempfile.NamedTemporaryFile() as index_f: try: subprocess.check_call([vidindex, typ, fn, prefix_f.name, index_f.name]) - except subprocess.CalledProcessError as e: + except subprocess.CalledProcessError: raise DataUnreadableError("vidindex failed on file %s" % fn) with open(index_f.name, "rb") as f: index = f.read() @@ -388,8 +389,6 @@ def index_pstream(fns, typ, cache_prefix=None): assert frame_b >= 0 assert index[frame_b, 0] == H264_SLICE_I - end_len = len(index)-frame_b - with FileReader(fns[i]) as vid: vid.seek(index[frame_b, 1]) end_data = vid.read() @@ -433,7 +432,7 @@ def _set_pdeathsig(sig=signal.SIGTERM): def vidindex_mp4(fn): try: xmls = subprocess.check_output(["MP4Box", fn, "-diso", "-out", "/dev/stdout"]) - except subprocess.CalledProcessError as e: + except subprocess.CalledProcessError: raise DataUnreadableError(fn) tree = ET.fromstring(xmls) diff --git a/tools/lib/mkvparse/mkvgen.py b/tools/lib/mkvparse/mkvgen.py index df178127..a98fa299 100755 --- a/tools/lib/mkvparse/mkvgen.py +++ b/tools/lib/mkvparse/mkvgen.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import sys import random -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 diff --git a/tools/lib/mkvparse/mkvparse.py b/tools/lib/mkvparse/mkvparse.py index ea4b7e01..8e981634 100644 --- a/tools/lib/mkvparse/mkvparse.py +++ b/tools/lib/mkvparse/mkvparse.py @@ -8,6 +8,7 @@ # See "mkvuser.py" for the example # pylint: skip-file +# flake8: noqa import traceback from struct import unpack diff --git a/tools/replay/ui.py b/tools/replay/ui.py index 2a91c1b5..ee07a281 100755 --- a/tools/replay/ui.py +++ b/tools/replay/ui.py @@ -63,7 +63,6 @@ def ui_thread(addr, frame_address): camera_surface = pygame.surface.Surface((640, 480), 0, 24).convert() cameraw_surface = pygame.surface.Surface(MODEL_INPUT_SIZE, 0, 24).convert() - cameraw_test_surface = pygame.surface.Surface(MODEL_INPUT_SIZE, 0, 24) top_down_surface = pygame.surface.Surface((UP.lidar_x, UP.lidar_y),0,8) frame = messaging.sub_sock('frame', addr=addr, conflate=True) diff --git a/tools/sim/bridge.py b/tools/sim/bridge.py index f2949239..b3857683 100755 --- a/tools/sim/bridge.py +++ b/tools/sim/bridge.py @@ -79,7 +79,6 @@ def go(q): threading.Thread(target=health_function).start() threading.Thread(target=fake_driver_monitoring).start() - import carla # pylint: disable=import-error client = carla.Client("127.0.0.1", 2000) client.set_timeout(5.0) world = client.load_world('Town04') diff --git a/tools/sim/lib/keyboard_ctrl.py b/tools/sim/lib/keyboard_ctrl.py index 8be3ca0d..84436d53 100644 --- a/tools/sim/lib/keyboard_ctrl.py +++ b/tools/sim/lib/keyboard_ctrl.py @@ -1,7 +1,8 @@ -import time import sys import termios -from termios import * +import time +from termios import (BRKINT, VMIN, CS8, CSIZE, ECHO, ICANON, ICRNL, IEXTEN, + INPCK, ISIG, ISTRIP, IXON, PARENB, VTIME) # Indexes for termios list. IFLAG = 0 @@ -58,4 +59,3 @@ if __name__ == '__main__': p.start() keyboard_poll_thread(q) - diff --git a/tools/sim/lib/manual_ctrl.py b/tools/sim/lib/manual_ctrl.py index 4c94c13f..6e7fe6e6 100755 --- a/tools/sim/lib/manual_ctrl.py +++ b/tools/sim/lib/manual_ctrl.py @@ -133,7 +133,7 @@ def wheel_poll_thread(q): # Enable FF import evdev # pylint: disable=import-error - from evdev import ecodes, InputDevice, ff # pylint: disable=import-error + from evdev import ecodes, InputDevice # pylint: disable=import-error device = evdev.list_devices()[0] evtdev = InputDevice(device) val = 24000 diff --git a/tools/streamer/streamerd.py b/tools/streamer/streamerd.py index 81b20fa2..9cbb2f06 100755 --- a/tools/streamer/streamerd.py +++ b/tools/streamer/streamerd.py @@ -40,12 +40,12 @@ def receiver_thread(): ctx = av.codec.codec.Codec('hevc', 'r').create() ctx.decode(av.packet.Packet(start.decode("hex"))) - import time + # import time while 1: - t1 = time.time() + # t1 = time.time() ts, raw = s.recv_multipart() ts = struct.unpack('q', ts)[0] * 1000 - t1, t2 = time.time(), t1 + # t1, t2 = time.time(), t1 #print 'ms to get frame:', (t1-t2)*1000 pkt = av.packet.Packet(raw) @@ -53,14 +53,14 @@ def receiver_thread(): if not f: continue f = f[0] - t1, t2 = time.time(), t1 + # t1, t2 = time.time(), t1 #print 'ms to decode:', (t1-t2)*1000 y_plane = np.frombuffer(f.planes[0], np.uint8).reshape((874, 1216))[:, 0:1164] u_plane = np.frombuffer(f.planes[1], np.uint8).reshape((437, 608))[:, 0:582] v_plane = np.frombuffer(f.planes[2], np.uint8).reshape((437, 608))[:, 0:582] yuv_img = y_plane.tobytes() + u_plane.tobytes() + v_plane.tobytes() - t1, t2 = time.time(), t1 + # t1, t2 = time.time(), t1 #print 'ms to make yuv:', (t1-t2)*1000 #print 'tsEof:', ts