Enable more flake8 checks (#1602)

* enable some more flake8 checks

* some more quick ones

* bump opendbc

* e401

* e711 e712

* e115 e116

* e222

* e301

* remove that

* e129

* e701 e702

* e125 e131

* e227

* e306

* e262

* W503

* e713

* e704

* e731

* bump opendbc

* fix some e722
old-commit-hash: d9bf9f0a40
commatwo_master
Adeeb 5 years ago committed by GitHub
parent 2ee34128d0
commit 5e857427ba
  1. 3
      .pre-commit-config.yaml
  2. 1
      common/android.py
  3. 1
      common/api/__init__.py
  4. 1
      common/basedir.py
  5. 6
      common/file_helpers.py
  6. 7
      common/logging_extra.py
  7. 5
      common/numpy_fast.py
  8. 3
      common/params.py
  9. 1
      common/profiler.py
  10. 2
      common/stat_live.py
  11. 1
      common/testing.py
  12. 1
      common/timeout.py
  13. 1
      common/transformations/camera.py
  14. 4
      common/url_file.py
  15. 2
      opendbc
  16. 2
      scripts/code_stats.py
  17. 1
      selfdrive/car/__init__.py
  18. 3
      selfdrive/car/gm/carcontroller.py
  19. 1
      selfdrive/car/gm/gmcan.py
  20. 2
      selfdrive/car/gm/radar_interface.py
  21. 1
      selfdrive/car/mazda/__init__.py
  22. 1
      selfdrive/car/mazda/carstate.py
  23. 1
      selfdrive/car/mazda/radar_interface.py
  24. 1
      selfdrive/car/subaru/__init__.py
  25. 6
      selfdrive/car/toyota/carcontroller.py
  26. 1
      selfdrive/car/volkswagen/__init__.py
  27. 1
      selfdrive/config.py
  28. 4
      selfdrive/controls/lib/latcontrol_lqr.py
  29. 1
      selfdrive/controls/lib/vehicle_model.py
  30. 3
      selfdrive/controls/tests/test_events.py
  31. 4
      selfdrive/crash.py
  32. 1
      selfdrive/locationd/calibration_helpers.py
  33. 2
      selfdrive/locationd/test/ephemeris.py
  34. 13
      selfdrive/locationd/test/ublox.py
  35. 6
      selfdrive/locationd/test/ubloxd.py
  36. 1
      selfdrive/loggerd/tools/mark_unuploaded.py
  37. 2
      selfdrive/loggerd/uploader.py
  38. 1
      selfdrive/test/longitudinal_maneuvers/maneuverplots.py
  39. 8
      selfdrive/test/process_replay/compare_logs.py
  40. 6
      selfdrive/test/process_replay/process_replay.py
  41. 2
      selfdrive/test/process_replay/test_processes.py
  42. 2
      tools/carcontrols/joystick_test.py
  43. 12
      tools/lib/route.py
  44. 7
      tools/lib/route_framereader.py
  45. 10
      tools/replay/lib/ui_helpers.py
  46. 8
      tools/replay/unlogger.py
  47. 4
      tools/sim/lib/manual_ctrl.py

@ -17,7 +17,8 @@ repos:
- id: flake8
exclude: '^(pyextra)|(external)|(cereal)|(rednose)|(panda)|(laika)|(laika_repo)|(rednose_repo)/'
args:
- --select=F
- --ignore=E111,E114,E121,E122,E123,E124,E126,E127,E128,E201,E202,E203,E221,E225,E226,E231,E241,E251,E261,E265,E266,E302,E303,E305,E402,E501,E502,E722,E741,W504
- --statistics
- repo: local
hooks:
- id: pylint

@ -132,6 +132,7 @@ def get_network_type():
def get_network_strength(network_type):
network_strength = NetworkStrength.unknown
# from SignalStrength.java
def get_lte_level(rsrp, rssnr):
INT_MAX = 2147483647

@ -39,4 +39,3 @@ def api_get(endpoint, method='GET', timeout=None, access_token=None, **params):
headers['User-Agent'] = "openpilot-" + version
return requests.request(method, backend+endpoint, timeout=timeout, headers = headers, params=params)

@ -8,4 +8,3 @@ if ANDROID:
else:
PERSIST = os.path.join(BASEDIR, "persist")
PARAMS = os.path.join(BASEDIR, "persist", "params")

@ -44,7 +44,8 @@ class AutoMoveTempdir():
def close(self):
os.rename(self._path, self._target_path)
def __enter__(self): return self
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
if type is None:
@ -63,7 +64,8 @@ class NamedTemporaryDir():
def close(self):
shutil.rmtree(self._path)
def __enter__(self): return self
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()

@ -68,8 +68,11 @@ class SwagErrorFilter(logging.Filter):
def filter(self, record):
return record.levelno < logging.ERROR
_tmpfunc = lambda: 0
_srcfile = os.path.normcase(_tmpfunc.__code__.co_filename)
def _tmpfunc():
return 0
def _srcfile():
return os.path.normcase(_tmpfunc.__code__.co_filename)
class SwagLogger(logging.Logger):
def __init__(self):

@ -6,6 +6,7 @@ def clip(x, lo, hi):
def interp(x, xp, fp):
N = len(xp)
def get_interp(xv):
hi = 0
while hi < N and xv > xp[hi]:
@ -14,8 +15,8 @@ def interp(x, xp, fp):
return fp[-1] if hi == N and xv > xp[low] else (
fp[0] if hi == 0 else
(xv - xp[low]) * (fp[hi] - fp[low]) / (xp[hi] - xp[low]) + fp[low])
return [get_interp(v) for v in x] if hasattr(
x, '__iter__') else get_interp(x)
return [get_interp(v) for v in x] if hasattr(x, '__iter__') else get_interp(x)
def mean(x):
return sum(x) / len(x)

@ -195,7 +195,8 @@ class DBReader(DBAccessor):
finally:
lock.release()
def __exit__(self, type, value, traceback): pass
def __exit__(self, type, value, traceback):
pass
class DBWriter(DBAccessor):

@ -43,4 +43,3 @@ class Profiler():
else:
print("%30s: %9.2f percent: %3.0f" % (n, ms*1000.0, ms/self.tot*100))
print("Iter clock: %2.6f TOTAL: %2.2f" % (self.tot/self.iter, self.tot))

@ -32,7 +32,7 @@ class RunningStat():
self.S_last = 0.
else:
self.M = self.M_last + (new_data - self.M_last) / self.n
self.S = self.S_last + (new_data - self.M_last) * (new_data - self.M);
self.S = self.S_last + (new_data - self.M_last) * (new_data - self.M)
self.M_last = self.M
self.S_last = self.S

@ -6,4 +6,3 @@ def phone_only(x):
return x
else:
return nottest(x)

@ -25,4 +25,3 @@ class Timeout:
def __exit__(self, exc_type, exc_val, exc_tb):
signal.alarm(0)

@ -145,4 +145,3 @@ def pretransform_from_calib(calib):
camera_frame_from_road_frame = np.dot(eon_intrinsics, view_frame_from_road_frame)
camera_frame_from_calib_frame = get_camera_frame_from_calib_frame(camera_frame_from_road_frame)
return np.linalg.inv(camera_frame_from_calib_frame)

@ -50,12 +50,16 @@ class URLFile(object):
if self._debug:
print("downloading", self._url)
def header(x):
if b'MISS' in x:
print(x.strip())
c.setopt(pycurl.HEADERFUNCTION, header)
def test(debug_type, debug_msg):
print(" debug(%d): %s" % (debug_type, debug_msg.strip()))
c.setopt(pycurl.VERBOSE, 1)
c.setopt(pycurl.DEBUGFUNCTION, test)
t1 = time.time()

@ -1 +1 @@
Subproject commit 0430bfa5c2b08f9cc6ab32470fe8ac9465e7a876
Subproject commit b15edbc1b5a68fd725ea45ba9442a6c9be875971

@ -20,6 +20,7 @@ class Analyzer(ast.NodeVisitor):
for alias in node.names:
imps.add(alias.name)
self.generic_visit(node)
def visit_ImportFrom(self, node):
imps.add(node.module)
self.generic_visit(node)
@ -38,4 +39,3 @@ for f in sorted(pyf):
print("%d lines of parsed openpilot python" % tlns)
#print(sorted(list(imps)))

@ -128,4 +128,3 @@ def is_ecu_disconnected(fingerprint, fingerprint_list, ecu_fingerprint, car, ecu
def make_can_msg(addr, dat, bus):
return [addr, 0, dat, bus]

@ -161,8 +161,7 @@ class CarController():
lka_active = CS.lkas_status == 1
lka_critical = lka_active and abs(actuators.steer) > 0.9
lka_icon_status = (lka_active, lka_critical)
if frame % P.CAMERA_KEEPALIVE_STEP == 0 \
or lka_icon_status != self.lka_icon_status_last:
if frame % P.CAMERA_KEEPALIVE_STEP == 0 or lka_icon_status != self.lka_icon_status_last:
steer_alert = hud_alert == VisualAlert.steerRequired
can_sends.append(gmcan.create_lka_icon_command(CanBus.SW_GMLAN, lka_active, lka_critical, steer_alert))
self.lka_icon_status_last = lka_icon_status

@ -121,4 +121,3 @@ def create_lka_icon_command(bus, active, critical, steer):
else:
dat = b"\x00\x00\x00"
return make_can_msg(0x104c006c, dat, bus)

@ -103,7 +103,7 @@ class RadarInterface(RadarInterfaceBase):
self.pts[targetId].yvRel = float('nan')
for oldTarget in list(self.pts.keys()):
if not oldTarget in currentTargets:
if oldTarget not in currentTargets:
del self.pts[oldTarget]
ret.points = list(self.pts.values())

@ -182,4 +182,3 @@ class CarState(CarStateBase):
]
return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2)

@ -3,4 +3,3 @@ from selfdrive.car.interfaces import RadarInterfaceBase
class RadarInterface(RadarInterfaceBase):
pass

@ -42,8 +42,10 @@ class CarController():
self.steer_rate_limited = False
self.fake_ecus = set()
if CP.enableCamera: self.fake_ecus.add(Ecu.fwdCamera)
if CP.enableDsu: self.fake_ecus.add(Ecu.dsu)
if CP.enableCamera:
self.fake_ecus.add(Ecu.fwdCamera)
if CP.enableDsu:
self.fake_ecus.add(Ecu.dsu)
self.packer = CANPacker(dbc_name)

@ -27,4 +27,3 @@ class UIParams:
car_front = 2.6924 * lidar_zoom
car_back = 1.8796 * lidar_zoom
car_color = 110

@ -79,8 +79,8 @@ class LatControlLQR():
i = self.i_lqr + self.ki * self.i_rate * error
control = lqr_output + i
if ((error >= 0 and (control <= steers_max or i < 0.0)) or \
(error <= 0 and (control >= -steers_max or i > 0.0))):
if (error >= 0 and (control <= steers_max or i < 0.0)) or \
(error <= 0 and (control >= -steers_max or i > 0.0)):
self.i_lqr = i
self.output_steer = lqr_output + self.i_lqr

@ -194,4 +194,3 @@ class VehicleModel():
Yaw rate [rad/s]
"""
return self.calc_curvature(sa, u) * u

@ -52,7 +52,8 @@ class TestAlerts(unittest.TestCase):
continue
for i, txt in enumerate([alert.alert_text_1, alert.alert_text_2]):
if i >= len(fonts[alert.alert_size]): break
if i >= len(fonts[alert.alert_size]):
break
font = fonts[alert.alert_size][i]
w, h = draw.textsize(txt, font)

@ -11,10 +11,13 @@ from common.android import ANDROID
if os.getenv("NOLOG") or os.getenv("NOCRASH") or not ANDROID:
def capture_exception(*args, **kwargs):
pass
def bind_user(**kwargs):
pass
def bind_extra(**kwargs):
pass
def install():
pass
else:
@ -38,6 +41,7 @@ else:
def install():
# installs a sys.excepthook
__excepthook__ = sys.excepthook
def handle_exception(*exc_info):
if exc_info[0] not in (KeyboardInterrupt, SystemExit):
capture_exception()

@ -8,4 +8,3 @@ class Calibration:
UNCALIBRATED = 0
CALIBRATED = 1
INVALID = 2

@ -133,5 +133,3 @@ on of this parser
self.ionoAlpha = []
self.ionoBeta = []
self.ionoCoeffsValid = False

@ -12,7 +12,8 @@ for ublox version 8, not all functions may work.
import struct
import time, os
import os
import time
# protocol constants
PREAMBLE1 = 0xb5
@ -291,7 +292,7 @@ class UBloxDescriptor:
fields = self.fields[:]
for f in fields:
(fieldname, alen) = ArrayParse(f)
if not fieldname in msg._fields:
if fieldname not in msg._fields:
break
if alen == -1:
f1.append(msg._fields[fieldname])
@ -327,7 +328,7 @@ class UBloxDescriptor:
ret = self.name + ': '
for f in self.fields:
(fieldname, alen) = ArrayParse(f)
if not fieldname in msg._fields:
if fieldname not in msg._fields:
continue
v = msg._fields[fieldname]
if isinstance(v, list):
@ -591,7 +592,7 @@ class UBloxMessage:
if not self.valid():
raise UBloxError('INVALID MESSAGE')
type = self.msg_type()
if not type in msg_types:
if type not in msg_types:
raise UBloxError('Unknown message %s length=%u' % (str(type), len(self._buf)))
msg_types[type].unpack(self)
return self._fields, self._recs
@ -601,7 +602,7 @@ class UBloxMessage:
if not self.valid():
raise UBloxError('INVALID MESSAGE')
type = self.msg_type()
if not type in msg_types:
if type not in msg_types:
raise UBloxError('Unknown message %s' % str(type))
msg_types[type].pack(self)
@ -610,7 +611,7 @@ class UBloxMessage:
if not self.valid():
raise UBloxError('INVALID MESSAGE')
type = self.msg_type()
if not type in msg_types:
if type not in msg_types:
raise UBloxError('Unknown message %s length=%u' % (str(type), len(self._buf)))
return msg_types[type].name

@ -134,9 +134,9 @@ def gen_solution(msg):
msg_data['day'],
msg_data['hour'],
msg_data['min'],
msg_data['sec'])
- datetime.datetime(1970,1,1)).total_seconds())*1e+03
+ msg_data['nano']*1e-06)
msg_data['sec']) -
datetime.datetime(1970,1,1)).total_seconds())*1e+03 +
msg_data['nano']*1e-06)
gps_fix = {'bearing': msg_data['headMot']*1e-05, # heading of motion in degrees
'altitude': msg_data['height']*1e-03, # altitude above ellipsoid
'latitude': msg_data['lat']*1e-07, # latitude in degrees

@ -6,4 +6,3 @@ from selfdrive.loggerd.uploader import UPLOAD_ATTR_NAME
for fn in sys.argv[1:]:
print("unmarking %s" % fn)
removexattr(fn, UPLOAD_ATTR_NAME)

@ -174,9 +174,11 @@ class Uploader():
if fake_upload:
cloudlog.info("*** WARNING, THIS IS A FAKE UPLOAD TO %s ***" % url)
class FakeResponse():
def __init__(self):
self.status_code = 200
self.last_resp = FakeResponse()
else:
with open(fn, "rb") as f:

@ -140,4 +140,3 @@ class ManeuverPlot():
pylab.savefig("/".join([path, maneuver_name, 'distance.svg']), dpi=1000)
plt.close("all")

@ -6,7 +6,8 @@ import numbers
import dictdiffer
if "CI" in os.environ:
tqdm = lambda x: x
def tqdm(x):
return x
else:
from tqdm import tqdm # type: ignore
@ -32,7 +33,7 @@ def remove_ignored_fields(msg, ignore):
for k in keys[:-1]:
try:
attr = getattr(msg, k)
except:
except AttributeError:
break
else:
v = getattr(attr, keys[-1])
@ -46,8 +47,7 @@ def remove_ignored_fields(msg, ignore):
return msg.as_reader()
def compare_logs(log1, log2, ignore_fields=[], ignore_msgs=[]):
filter_msgs = lambda m: m.which() not in ignore_msgs
log1, log2 = [list(filter(filter_msgs, log)) for log in (log1, log2)]
log1, log2 = [list(filter(lambda m: m.which() not in ignore_msgs, log)) for log in (log1, log2)]
assert len(log1) == len(log2), "logs are not same length: " + str(len(log1)) + " VS " + str(len(log2))
diff = []

@ -1,11 +1,13 @@
#!/usr/bin/env python3
import capnp
import os
import sys
import threading
import importlib
if "CI" in os.environ:
tqdm = lambda x: x
def tqdm(x):
return x
else:
from tqdm import tqdm # type: ignore
@ -110,7 +112,7 @@ class FakePubMaster(messaging.PubMaster):
for s in services:
try:
data = messaging.new_message(s)
except:
except capnp.lib.capnp.KjException:
data = messaging.new_message(s, 0)
self.data[s] = data.as_reader()
self.sock[s] = DumbSocket()

@ -124,7 +124,7 @@ if __name__ == "__main__":
process_replay_dir = os.path.dirname(os.path.abspath(__file__))
try:
ref_commit = open(os.path.join(process_replay_dir, "ref_commit")).read().strip()
except:
except FileNotFoundError:
print("couldn't find reference commit")
sys.exit(1)

@ -51,7 +51,7 @@ pygame.joystick.init()
textPrint = TextPrint()
# -------- Main Program Loop -----------
while done==False:
while not done:
# EVENT PROCESSING STEP
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close

@ -111,10 +111,12 @@ class RouteSegment(object):
self.camera_path = camera_path
@property
def name(self): return str(self._name)
def name(self):
return str(self._name)
@property
def canonical_name(self): return self._name
def canonical_name(self):
return self._name
class RouteSegmentName(object):
def __init__(self, name_str):
@ -123,6 +125,8 @@ class RouteSegmentName(object):
self._num = int(num_str)
@property
def segment_num(self): return self._num
def segment_num(self):
return self._num
def __str__(self): return self._segment_name_str
def __str__(self):
return self._segment_name_str

@ -82,5 +82,8 @@ class RouteFrameReader(object):
for fr in frs:
fr.close()
def __enter__(self): return self
def __exit__(self, type, value, traceback): self.close()
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()

@ -93,7 +93,7 @@ def draw_steer_path(speed_ms, curvature, color, img,
draw_path(path_y, path_x, color, img, calibration, top_down, lid_color)
def draw_lead_car(closest, top_down):
if closest != None:
if closest is not None:
closest_y = int(round(UP.lidar_car_y - closest * UP.lidar_zoom))
if closest_y > 0:
top_down[1][int(round(UP.lidar_car_x - METER_WIDTH * 2)):int(
@ -118,12 +118,10 @@ def init_plots(arr, name_to_arr_idx, plot_xlims, plot_ylims, plot_names, plot_co
"p": (0,1,1),
"m": (1,0,1) }
if bigplots == True:
if bigplots:
fig = plt.figure(figsize=(6.4, 7.0))
elif bigplots == False:
fig = plt.figure()
else:
fig = plt.figure(figsize=bigplots)
fig = plt.figure()
fig.set_facecolor((0.2,0.2,0.2))
@ -135,7 +133,7 @@ def init_plots(arr, name_to_arr_idx, plot_xlims, plot_ylims, plot_names, plot_co
ax.patch.set_facecolor((0.4, 0.4, 0.4))
axs.append(ax)
plots = [] ;idxs = [] ;plot_select = []
plots, idxs, plot_select = [], [], []
for i, pl_list in enumerate(plot_names):
for j, item in enumerate(pl_list):
plot, = axs[i].plot(arr[:, name_to_arr_idx[item]],

@ -345,11 +345,15 @@ def get_arg_parser():
parser.add_argument("--no-loop", action="store_true", help="Stop at the end of the replay.")
key_value_pair = lambda x: x.split("=")
def key_value_pair(x):
return x.split("=")
parser.add_argument("address_mapping", nargs="*", type=key_value_pair,
help="Pairs <service>=<zmq_addr> to publish <service> on <zmq_addr>.")
comma_list = lambda x: x.split(",")
def comma_list(x):
return x.split(",")
to_mock_group = parser.add_mutually_exclusive_group()
to_mock_group.add_argument("--min", action="store_true", default=os.getenv("MIN"))
to_mock_group.add_argument("--enabled", default=os.getenv("ENABLED"), type=comma_list)

@ -1,6 +1,8 @@
#!/usr/bin/env python3
# set up wheel
import os, struct, array
import array
import os
import struct
from fcntl import ioctl
# Iterate over the joystick devices.

Loading…
Cancel
Save