The following issues were found

pyextra/acados_template/generate_c_code_gnsf.py
25 issues
Unable to import 'casadi'
Error

Line: 35 Column: 1

              #

import os
from casadi import *
from .utils import ALLOWED_CASADI_VERSIONS, is_empty, casadi_version_warning

def generate_c_code_gnsf( model, opts ):

    casadi_version = CasadiMeta.version()

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 36 Column: 1

              
import os
from casadi import *
from .utils import ALLOWED_CASADI_VERSIONS, is_empty, casadi_version_warning

def generate_c_code_gnsf( model, opts ):

    casadi_version = CasadiMeta.version()
    casadi_opts = dict(mex=False, casadi_int='int', casadi_real='double')

            

Reported by Pylint.

Undefined variable 'CasadiMeta'
Error

Line: 40 Column: 22

              
def generate_c_code_gnsf( model, opts ):

    casadi_version = CasadiMeta.version()
    casadi_opts = dict(mex=False, casadi_int='int', casadi_real='double')
    if casadi_version not in (ALLOWED_CASADI_VERSIONS):
        casadi_version_warning(casadi_version)

    model_name = model.name

            

Reported by Pylint.

Undefined variable 'casadi'
Error

Line: 77 Column: 22

                  # -> evaluated SX GNSF functions with MX.
    u = model.u

    if isinstance(u, casadi.MX):
        symbol = MX.sym
    else:
        symbol = SX.sym

    y = symbol("y", gnsf_ny, 1)

            

Reported by Pylint.

Undefined variable 'MX'
Error

Line: 78 Column: 18

                  u = model.u

    if isinstance(u, casadi.MX):
        symbol = MX.sym
    else:
        symbol = SX.sym

    y = symbol("y", gnsf_ny, 1)
    uhat = symbol("uhat", gnsf_nuhat, 1)

            

Reported by Pylint.

Undefined variable 'SX'
Error

Line: 80 Column: 18

                  if isinstance(u, casadi.MX):
        symbol = MX.sym
    else:
        symbol = SX.sym

    y = symbol("y", gnsf_ny, 1)
    uhat = symbol("uhat", gnsf_nuhat, 1)
    p = model.p
    x1 = symbol("gnsf_x1", gnsf_nx1, 1)

            

Reported by Pylint.

Undefined variable 'Function'
Error

Line: 93 Column: 16

              
    ## generate C code
    fun_name = model_name + '_gnsf_phi_fun'
    phi_fun_ = Function(fun_name, [y, uhat, p], [phi_fun(y, uhat, p)])
    phi_fun_.generate(fun_name, casadi_opts)

    fun_name = model_name + '_gnsf_phi_fun_jac_y'
    phi_fun_jac_y = model.phi_fun_jac_y
    phi_fun_jac_y_ = Function(fun_name, [y, uhat, p], phi_fun_jac_y(y, uhat, p))

            

Reported by Pylint.

Undefined variable 'Function'
Error

Line: 98 Column: 22

              
    fun_name = model_name + '_gnsf_phi_fun_jac_y'
    phi_fun_jac_y = model.phi_fun_jac_y
    phi_fun_jac_y_ = Function(fun_name, [y, uhat, p], phi_fun_jac_y(y, uhat, p))
    phi_fun_jac_y_.generate(fun_name, casadi_opts)

    fun_name = model_name + '_gnsf_phi_jac_y_uhat'
    phi_jac_y_uhat = model.phi_jac_y_uhat
    phi_jac_y_uhat_ = Function(fun_name, [y, uhat, p], phi_jac_y_uhat(y, uhat, p))

            

Reported by Pylint.

Undefined variable 'Function'
Error

Line: 103 Column: 23

              
    fun_name = model_name + '_gnsf_phi_jac_y_uhat'
    phi_jac_y_uhat = model.phi_jac_y_uhat
    phi_jac_y_uhat_ = Function(fun_name, [y, uhat, p], phi_jac_y_uhat(y, uhat, p))
    phi_jac_y_uhat_.generate(fun_name, casadi_opts)

    fun_name = model_name + '_gnsf_f_lo_fun_jac_x1k1uz'
    f_lo_fun_jac_x1k1uz = model.f_lo_fun_jac_x1k1uz
    f_lo_fun_jac_x1k1uz_eval = f_lo_fun_jac_x1k1uz(x1, x1dot, z1, u, p)

            

Reported by Pylint.

Undefined variable 'Function'
Error

Line: 114 Column: 28

                  if not isinstance(f_lo_fun_jac_x1k1uz_eval, tuple) and is_empty(f_lo_fun_jac_x1k1uz_eval):
        f_lo_fun_jac_x1k1uz_eval = [empty_var]

    f_lo_fun_jac_x1k1uz_ = Function(fun_name, [x1, x1dot, z1, u, p],
                 f_lo_fun_jac_x1k1uz_eval)
    f_lo_fun_jac_x1k1uz_.generate(fun_name, casadi_opts)

    fun_name = model_name + '_gnsf_get_matrices_fun'
    get_matrices_fun_ = Function(fun_name, [dummy], get_matrices_fun(1))

            

Reported by Pylint.

selfdrive/ui/tests/cycle_offroad_alerts.py
24 issues
Unable to import 'common.basedir'
Error

Line: 7 Column: 1

              import time
import json

from common.basedir import BASEDIR
from common.params import Params
from selfdrive.controls.lib.alertmanager import set_offroad_alert

if __name__ == "__main__":
  params = Params()

            

Reported by Pylint.

Unable to import 'common.params'
Error

Line: 8 Column: 1

              import json

from common.basedir import BASEDIR
from common.params import Params
from selfdrive.controls.lib.alertmanager import set_offroad_alert

if __name__ == "__main__":
  params = Params()


            

Reported by Pylint.

Unable to import 'selfdrive.controls.lib.alertmanager'
Error

Line: 9 Column: 1

              
from common.basedir import BASEDIR
from common.params import Params
from selfdrive.controls.lib.alertmanager import set_offroad_alert

if __name__ == "__main__":
  params = Params()

  with open(os.path.join(BASEDIR, "selfdrive/controls/lib/alerts_offroad.json")) as f:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3
import os
import sys
import time
import json

from common.basedir import BASEDIR
from common.params import Params
from selfdrive.controls.lib.alertmanager import set_offroad_alert

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 12 Column: 1

              from selfdrive.controls.lib.alertmanager import set_offroad_alert

if __name__ == "__main__":
  params = Params()

  with open(os.path.join(BASEDIR, "selfdrive/controls/lib/alerts_offroad.json")) as f:
    offroad_alerts = json.load(f)

  t = 10 if len(sys.argv) < 2 else int(sys.argv[1])

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 14 Column: 1

              if __name__ == "__main__":
  params = Params()

  with open(os.path.join(BASEDIR, "selfdrive/controls/lib/alerts_offroad.json")) as f:
    offroad_alerts = json.load(f)

  t = 10 if len(sys.argv) < 2 else int(sys.argv[1])
  while True:
    print("setting alert update")

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 15 Column: 1

                params = Params()

  with open(os.path.join(BASEDIR, "selfdrive/controls/lib/alerts_offroad.json")) as f:
    offroad_alerts = json.load(f)

  t = 10 if len(sys.argv) < 2 else int(sys.argv[1])
  while True:
    print("setting alert update")
    params.put_bool("UpdateAvailable", True)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 17 Column: 1

                with open(os.path.join(BASEDIR, "selfdrive/controls/lib/alerts_offroad.json")) as f:
    offroad_alerts = json.load(f)

  t = 10 if len(sys.argv) < 2 else int(sys.argv[1])
  while True:
    print("setting alert update")
    params.put_bool("UpdateAvailable", True)
    r = open(os.path.join(BASEDIR, "RELEASES.md"), "r").read()
    r = r[:r.find('\n\n')]  # Slice latest release notes

            

Reported by Pylint.

Constant name "t" doesn't conform to UPPER_CASE naming style
Error

Line: 17 Column: 3

                with open(os.path.join(BASEDIR, "selfdrive/controls/lib/alerts_offroad.json")) as f:
    offroad_alerts = json.load(f)

  t = 10 if len(sys.argv) < 2 else int(sys.argv[1])
  while True:
    print("setting alert update")
    params.put_bool("UpdateAvailable", True)
    r = open(os.path.join(BASEDIR, "RELEASES.md"), "r").read()
    r = r[:r.find('\n\n')]  # Slice latest release notes

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 18 Column: 1

                  offroad_alerts = json.load(f)

  t = 10 if len(sys.argv) < 2 else int(sys.argv[1])
  while True:
    print("setting alert update")
    params.put_bool("UpdateAvailable", True)
    r = open(os.path.join(BASEDIR, "RELEASES.md"), "r").read()
    r = r[:r.find('\n\n')]  # Slice latest release notes
    params.put("ReleaseNotes", r + "\n")

            

Reported by Pylint.

tools/webcam/warp_vis.py
22 issues
Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python
import numpy as np

# copied from common.transformations/camera.py
eon_focal_length = 910.0  # pixels
eon_dcam_focal_length = 860.0  # pixels

webcam_focal_length = -908.0/1.5  # pixels


            

Reported by Pylint.

Constant name "eon_focal_length" doesn't conform to UPPER_CASE naming style
Error

Line: 5 Column: 1

              import numpy as np

# copied from common.transformations/camera.py
eon_focal_length = 910.0  # pixels
eon_dcam_focal_length = 860.0  # pixels

webcam_focal_length = -908.0/1.5  # pixels

eon_intrinsics = np.array([

            

Reported by Pylint.

Constant name "eon_dcam_focal_length" doesn't conform to UPPER_CASE naming style
Error

Line: 6 Column: 1

              
# copied from common.transformations/camera.py
eon_focal_length = 910.0  # pixels
eon_dcam_focal_length = 860.0  # pixels

webcam_focal_length = -908.0/1.5  # pixels

eon_intrinsics = np.array([
  [eon_focal_length,   0.,   1164/2.],

            

Reported by Pylint.

Constant name "webcam_focal_length" doesn't conform to UPPER_CASE naming style
Error

Line: 8 Column: 1

              eon_focal_length = 910.0  # pixels
eon_dcam_focal_length = 860.0  # pixels

webcam_focal_length = -908.0/1.5  # pixels

eon_intrinsics = np.array([
  [eon_focal_length,   0.,   1164/2.],
  [  0.,  eon_focal_length,  874/2.],
  [  0.,    0.,     1.]])

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 26 Column: 1

                [  0.,    0.,     1.]])

if __name__ == "__main__":
  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)
  print("trans_webcam_to_eon_front:\n", trans_webcam_to_eon_front)


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 27 Column: 1

              
if __name__ == "__main__":
  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)
  print("trans_webcam_to_eon_front:\n", trans_webcam_to_eon_front)

  cap = cv2.VideoCapture(1)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 28 Column: 1

              if __name__ == "__main__":
  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)
  print("trans_webcam_to_eon_front:\n", trans_webcam_to_eon_front)

  cap = cv2.VideoCapture(1)
  cap.set(cv2.CAP_PROP_FRAME_WIDTH, 853)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 29 Column: 1

                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)
  print("trans_webcam_to_eon_front:\n", trans_webcam_to_eon_front)

  cap = cv2.VideoCapture(1)
  cap.set(cv2.CAP_PROP_FRAME_WIDTH, 853)
  cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 30 Column: 1

                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)
  print("trans_webcam_to_eon_front:\n", trans_webcam_to_eon_front)

  cap = cv2.VideoCapture(1)
  cap.set(cv2.CAP_PROP_FRAME_WIDTH, 853)
  cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 32 Column: 1

                print("trans_webcam_to_eon_rear:\n", trans_webcam_to_eon_rear)
  print("trans_webcam_to_eon_front:\n", trans_webcam_to_eon_front)

  cap = cv2.VideoCapture(1)
  cap.set(cv2.CAP_PROP_FRAME_WIDTH, 853)
  cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

  while (True):
    ret, img = cap.read()

            

Reported by Pylint.

tools/webcam/front_mount_helper.py
18 issues
Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python
import numpy as np

# copied from common.transformations/camera.py
eon_dcam_focal_length = 860.0  # pixels
webcam_focal_length = 908.0  # pixels

eon_dcam_intrinsics = np.array([
  [eon_dcam_focal_length,   0,   1152/2.],

            

Reported by Pylint.

Constant name "eon_dcam_focal_length" doesn't conform to UPPER_CASE naming style
Error

Line: 5 Column: 1

              import numpy as np

# copied from common.transformations/camera.py
eon_dcam_focal_length = 860.0  # pixels
webcam_focal_length = 908.0  # pixels

eon_dcam_intrinsics = np.array([
  [eon_dcam_focal_length,   0,   1152/2.],
  [  0,  eon_dcam_focal_length,  864/2.],

            

Reported by Pylint.

Constant name "webcam_focal_length" doesn't conform to UPPER_CASE naming style
Error

Line: 6 Column: 1

              
# copied from common.transformations/camera.py
eon_dcam_focal_length = 860.0  # pixels
webcam_focal_length = 908.0  # pixels

eon_dcam_intrinsics = np.array([
  [eon_dcam_focal_length,   0,   1152/2.],
  [  0,  eon_dcam_focal_length,  864/2.],
  [  0,    0,     1]])

            

Reported by Pylint.

Constant name "cam_id" doesn't conform to UPPER_CASE naming style
Error

Line: 18 Column: 1

                [  0.,  webcam_focal_length,  720/2.],
  [  0.,    0.,     1.]])

cam_id = 2

if __name__ == "__main__":
  import cv2  # pylint: disable=import-error

  trans_webcam_to_eon_front = np.dot(eon_dcam_intrinsics, np.linalg.inv(webcam_intrinsics))

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 21 Column: 1

              cam_id = 2

if __name__ == "__main__":
  import cv2  # pylint: disable=import-error

  trans_webcam_to_eon_front = np.dot(eon_dcam_intrinsics, np.linalg.inv(webcam_intrinsics))

  cap = cv2.VideoCapture(cam_id)
  cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 23 Column: 1

              if __name__ == "__main__":
  import cv2  # pylint: disable=import-error

  trans_webcam_to_eon_front = np.dot(eon_dcam_intrinsics, np.linalg.inv(webcam_intrinsics))

  cap = cv2.VideoCapture(cam_id)
  cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
  cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 25 Column: 1

              
  trans_webcam_to_eon_front = np.dot(eon_dcam_intrinsics, np.linalg.inv(webcam_intrinsics))

  cap = cv2.VideoCapture(cam_id)
  cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
  cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

  while (True):
    ret, img = cap.read()

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 26 Column: 1

                trans_webcam_to_eon_front = np.dot(eon_dcam_intrinsics, np.linalg.inv(webcam_intrinsics))

  cap = cv2.VideoCapture(cam_id)
  cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
  cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

  while (True):
    ret, img = cap.read()
    if ret:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 27 Column: 1

              
  cap = cv2.VideoCapture(cam_id)
  cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
  cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

  while (True):
    ret, img = cap.read()
    if ret:
      img = cv2.warpPerspective(img, trans_webcam_to_eon_front, (1152, 864), borderMode=cv2.BORDER_CONSTANT, borderValue=0)

            

Reported by Pylint.

Unnecessary parens after 'while' keyword
Error

Line: 29 Column: 1

                cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
  cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

  while (True):
    ret, img = cap.read()
    if ret:
      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)

            

Reported by Pylint.

selfdrive/camerad/test/check_skips.py
18 issues
Unable to import 'cereal.messaging'
Error

Line: 3 Column: 1

              #!/usr/bin/env python3
# type: ignore
import cereal.messaging as messaging

all_sockets = ['roadCameraState', 'driverCameraState', 'wideRoadCameraState']
prev_id = [None,None,None]
this_id = [None,None,None]
dt = [None,None,None]
num_skipped = [0,0,0]

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3
# type: ignore
import cereal.messaging as messaging

all_sockets = ['roadCameraState', 'driverCameraState', 'wideRoadCameraState']
prev_id = [None,None,None]
this_id = [None,None,None]
dt = [None,None,None]
num_skipped = [0,0,0]

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 12 Column: 1

              num_skipped = [0,0,0]

if __name__ == "__main__":
  sm = messaging.SubMaster(all_sockets)
  while True:
    sm.update()

    for i in range(len(all_sockets)):
      if not sm.updated[all_sockets[i]]:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 13 Column: 1

              
if __name__ == "__main__":
  sm = messaging.SubMaster(all_sockets)
  while True:
    sm.update()

    for i in range(len(all_sockets)):
      if not sm.updated[all_sockets[i]]:
        continue

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 14 Column: 1

              if __name__ == "__main__":
  sm = messaging.SubMaster(all_sockets)
  while True:
    sm.update()

    for i in range(len(all_sockets)):
      if not sm.updated[all_sockets[i]]:
        continue
      this_id[i] = sm[all_sockets[i]].frameId

            

Reported by Pylint.

Consider using enumerate instead of iterating with range and len
Error

Line: 16 Column: 5

                while True:
    sm.update()

    for i in range(len(all_sockets)):
      if not sm.updated[all_sockets[i]]:
        continue
      this_id[i] = sm[all_sockets[i]].frameId
      if prev_id[i] is None:
        prev_id[i] = this_id[i]

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 16 Column: 1

                while True:
    sm.update()

    for i in range(len(all_sockets)):
      if not sm.updated[all_sockets[i]]:
        continue
      this_id[i] = sm[all_sockets[i]].frameId
      if prev_id[i] is None:
        prev_id[i] = this_id[i]

            

Reported by Pylint.

Bad indentation. Found 6 spaces, expected 12
Style

Line: 17 Column: 1

                  sm.update()

    for i in range(len(all_sockets)):
      if not sm.updated[all_sockets[i]]:
        continue
      this_id[i] = sm[all_sockets[i]].frameId
      if prev_id[i] is None:
        prev_id[i] = this_id[i]
        continue

            

Reported by Pylint.

Bad indentation. Found 8 spaces, expected 16
Style

Line: 18 Column: 1

              
    for i in range(len(all_sockets)):
      if not sm.updated[all_sockets[i]]:
        continue
      this_id[i] = sm[all_sockets[i]].frameId
      if prev_id[i] is None:
        prev_id[i] = this_id[i]
        continue
      dt[i] = this_id[i] - prev_id[i]

            

Reported by Pylint.

Bad indentation. Found 6 spaces, expected 12
Style

Line: 19 Column: 1

                  for i in range(len(all_sockets)):
      if not sm.updated[all_sockets[i]]:
        continue
      this_id[i] = sm[all_sockets[i]].frameId
      if prev_id[i] is None:
        prev_id[i] = this_id[i]
        continue
      dt[i] = this_id[i] - prev_id[i]
      if dt[i] != 1:

            

Reported by Pylint.

common/tests/test_params.py
18 issues
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 22
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
  def test_params_put_and_get(self):
    self.params.put("DongleId", "cb38263377b873ee")
    assert self.params.get("DongleId") == b"cb38263377b873ee"

  def test_persist_params_put_and_get(self):
    p = Params(persistent_params=True)
    p.put("DongleId", "cb38263377b873ee")
    assert p.get("DongleId") == b"cb38263377b873ee"

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 27
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                def test_persist_params_put_and_get(self):
    p = Params(persistent_params=True)
    p.put("DongleId", "cb38263377b873ee")
    assert p.get("DongleId") == b"cb38263377b873ee"

  def test_params_non_ascii(self):
    st = b"\xe1\x90\xff"
    self.params.put("CarParams", st)
    assert self.params.get("CarParams") == st

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 32
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                def test_params_non_ascii(self):
    st = b"\xe1\x90\xff"
    self.params.put("CarParams", st)
    assert self.params.get("CarParams") == st

  def test_params_get_cleared_panda_disconnect(self):
    self.params.put("CarParams", "test")
    self.params.put("DongleId", "cb38263377b873ee")
    assert self.params.get("CarParams") == b"test"

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 37
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                def test_params_get_cleared_panda_disconnect(self):
    self.params.put("CarParams", "test")
    self.params.put("DongleId", "cb38263377b873ee")
    assert self.params.get("CarParams") == b"test"
    self.params.clear_all(ParamKeyType.CLEAR_ON_PANDA_DISCONNECT)
    assert self.params.get("CarParams") is None
    assert self.params.get("DongleId") is not None

  def test_params_get_cleared_manager_start(self):

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 39
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  self.params.put("DongleId", "cb38263377b873ee")
    assert self.params.get("CarParams") == b"test"
    self.params.clear_all(ParamKeyType.CLEAR_ON_PANDA_DISCONNECT)
    assert self.params.get("CarParams") is None
    assert self.params.get("DongleId") is not None

  def test_params_get_cleared_manager_start(self):
    self.params.put("CarParams", "test")
    self.params.put("DongleId", "cb38263377b873ee")

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 40
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  assert self.params.get("CarParams") == b"test"
    self.params.clear_all(ParamKeyType.CLEAR_ON_PANDA_DISCONNECT)
    assert self.params.get("CarParams") is None
    assert self.params.get("DongleId") is not None

  def test_params_get_cleared_manager_start(self):
    self.params.put("CarParams", "test")
    self.params.put("DongleId", "cb38263377b873ee")
    assert self.params.get("CarParams") == b"test"

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 45
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                def test_params_get_cleared_manager_start(self):
    self.params.put("CarParams", "test")
    self.params.put("DongleId", "cb38263377b873ee")
    assert self.params.get("CarParams") == b"test"
    self.params.clear_all(ParamKeyType.CLEAR_ON_MANAGER_START)
    assert self.params.get("CarParams") is None
    assert self.params.get("DongleId") is not None

  def test_params_two_things(self):

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 47
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  self.params.put("DongleId", "cb38263377b873ee")
    assert self.params.get("CarParams") == b"test"
    self.params.clear_all(ParamKeyType.CLEAR_ON_MANAGER_START)
    assert self.params.get("CarParams") is None
    assert self.params.get("DongleId") is not None

  def test_params_two_things(self):
    self.params.put("DongleId", "bob")
    self.params.put("AthenadPid", "123")

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 48
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  assert self.params.get("CarParams") == b"test"
    self.params.clear_all(ParamKeyType.CLEAR_ON_MANAGER_START)
    assert self.params.get("CarParams") is None
    assert self.params.get("DongleId") is not None

  def test_params_two_things(self):
    self.params.put("DongleId", "bob")
    self.params.put("AthenadPid", "123")
    assert self.params.get("DongleId") == b"bob"

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 53
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                def test_params_two_things(self):
    self.params.put("DongleId", "bob")
    self.params.put("AthenadPid", "123")
    assert self.params.get("DongleId") == b"bob"
    assert self.params.get("AthenadPid") == b"123"

  def test_params_get_block(self):
    def _delayed_writer():
      time.sleep(0.1)

            

Reported by Bandit.

selfdrive/athena/tests/test_athenad_old.py
17 issues
Consider possible security implications associated with subprocess module.
Security blacklist

Line: 5
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess

              import json
import os
import signal
import subprocess
import time

import requests

from selfdrive.manager.process_config import managed_processes

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 25
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
  params = Params()
  manage_athenad_pid = params.get("AthenadPid")
  assert manage_athenad_pid is not None
  try:
    os.kill(int(manage_athenad_pid), 0)
    # process is running
  except OSError:
    assert False, "manage_athenad is dead"

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 30
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  os.kill(int(manage_athenad_pid), 0)
    # process is running
  except OSError:
    assert False, "manage_athenad is dead"

  def expect_athena_starts(timeout=30):
    now = time.time()
    athenad_pid = None
    while athenad_pid is None:

            

Reported by Bandit.

Starting a process with a partial executable path
Security injection

Line: 37
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b607_start_process_with_partial_path.html

                  athenad_pid = None
    while athenad_pid is None:
      try:
        athenad_pid = subprocess.check_output(["pgrep", "-P", manage_athenad_pid], encoding="utf-8").strip()
        return athenad_pid
      except subprocess.CalledProcessError:
        if time.time() - now > timeout:
          assert False, f"Athena did not start within {timeout} seconds"
        time.sleep(0.5)

            

Reported by Bandit.

subprocess call - check for execution of untrusted input.
Security injection

Line: 37
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html

                  athenad_pid = None
    while athenad_pid is None:
      try:
        athenad_pid = subprocess.check_output(["pgrep", "-P", manage_athenad_pid], encoding="utf-8").strip()
        return athenad_pid
      except subprocess.CalledProcessError:
        if time.time() - now > timeout:
          assert False, f"Athena did not start within {timeout} seconds"
        time.sleep(0.5)

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 41
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      return athenad_pid
      except subprocess.CalledProcessError:
        if time.time() - now > timeout:
          assert False, f"Athena did not start within {timeout} seconds"
        time.sleep(0.5)

  def athena_post(payload, max_retries=5, wait=5):
    tries = 0
    while 1:

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 76
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                    "id": 0,
      "jsonrpc": "2.0"
    }, max_retries=12, wait=5)
    assert resp.get('result') == "hello", f'Athena failed to register ({resp})'

    last_pingtime = params.get("LastAthenaPingTime", encoding='utf8')
    assert last_pingtime, last_pingtime
    assert ((int(last_pingtime)/1e9) - test_t0) < (sec_since_boot() - test_t0)


            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 79
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  assert resp.get('result') == "hello", f'Athena failed to register ({resp})'

    last_pingtime = params.get("LastAthenaPingTime", encoding='utf8')
    assert last_pingtime, last_pingtime
    assert ((int(last_pingtime)/1e9) - test_t0) < (sec_since_boot() - test_t0)

  try:
    athenad_pid = expect_athena_starts()
    # kill athenad and ensure it is restarted (check_output will throw if it is not)

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 80
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
    last_pingtime = params.get("LastAthenaPingTime", encoding='utf8')
    assert last_pingtime, last_pingtime
    assert ((int(last_pingtime)/1e9) - test_t0) < (sec_since_boot() - test_t0)

  try:
    athenad_pid = expect_athena_starts()
    # kill athenad and ensure it is restarted (check_output will throw if it is not)
    os.kill(int(athenad_pid), signal.SIGINT)

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 100
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                    "id": 0,
      "jsonrpc": "2.0"
    })
    assert resp.get('result'), resp
    assert 'sim_id' in resp['result'], resp['result']

    print("ATHENA: takeSnapshot")
    resp = athena_post({
      "method": "takeSnapshot",

            

Reported by Bandit.

selfdrive/hardware/eon/hardware.py
15 issues
No name 'log' in module 'cereal'
Error

Line: 10 Column: 1

              import subprocess
from typing import List, Union

from cereal import log
from selfdrive.hardware.base import HardwareBase, ThermalConfig

NetworkType = log.DeviceState.NetworkType
NetworkStrength = log.DeviceState.NetworkStrength


            

Reported by Pylint.

Consider possible security implications associated with subprocess module.
Security blacklist

Line: 7
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess

              import re
import serial
import struct
import subprocess
from typing import List, Union

from cereal import log
from selfdrive.hardware.base import HardwareBase, ThermalConfig


            

Reported by Bandit.

Starting a process with a partial executable path
Security injection

Line: 20
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b607_start_process_with_partial_path.html

              
def service_call(call: List[str]) -> Union[bytes, None]:
  try:
    ret = subprocess.check_output(["service", "call", *call], encoding='utf8').strip()
    if 'Parcel' not in ret:
      return None
    return parse_service_call_bytes(ret)
  except subprocess.CalledProcessError:
    return None

            

Reported by Bandit.

subprocess call - check for execution of untrusted input.
Security injection

Line: 20
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html

              
def service_call(call: List[str]) -> Union[bytes, None]:
  try:
    ret = subprocess.check_output(["service", "call", *call], encoding='utf8').strip()
    if 'Parcel' not in ret:
      return None
    return parse_service_call_bytes(ret)
  except subprocess.CalledProcessError:
    return None

            

Reported by Bandit.

Starting a process with a partial executable path
Security injection

Line: 62
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b607_start_process_with_partial_path.html

              
def getprop(key: str) -> Union[str, None]:
  try:
    return subprocess.check_output(["getprop", key], encoding='utf8').strip()
  except subprocess.CalledProcessError:
    return None


class Android(HardwareBase):

            

Reported by Bandit.

subprocess call - check for execution of untrusted input.
Security injection

Line: 62
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html

              
def getprop(key: str) -> Union[str, None]:
  try:
    return subprocess.check_output(["getprop", key], encoding='utf8').strip()
  except subprocess.CalledProcessError:
    return None


class Android(HardwareBase):

            

Reported by Bandit.

subprocess call - check for execution of untrusted input.
Security injection

Line: 105
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html

                  else:
      reason_args = ["s16", reason]

    subprocess.check_output([
      "service", "call", "power", "16",  # IPowerManager.reboot
      "i32", "0",  # no confirmation,
      *reason_args,
      "i32", "1"  # wait
    ])

            

Reported by Bandit.

Starting a process with a partial executable path
Security injection

Line: 105
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b607_start_process_with_partial_path.html

                  else:
      reason_args = ["s16", reason]

    subprocess.check_output([
      "service", "call", "power", "16",  # IPowerManager.reboot
      "i32", "0",  # no confirmation,
      *reason_args,
      "i32", "1"  # wait
    ])

            

Reported by Bandit.

Try, Except, Pass detected.
Security

Line: 150
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b110_try_except_pass.html

              
      rsrp = msg.extra.split("$QCRSRP: ")[1].split("\r")[0].split(",")
      msg.channel = int(rsrp[1])
    except Exception:
      pass

    return msg

  def get_network_type(self):

            

Reported by Bandit.

Starting a process with a partial executable path
Security injection

Line: 288
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b607_start_process_with_partial_path.html

                  if network_type == NetworkType.none:
      return network_strength
    if network_type == NetworkType.wifi:
      out = subprocess.check_output('dumpsys connectivity', shell=True).decode('utf-8')
      network_strength = NetworkStrength.unknown
      for line in out.split('\n'):
        signal_str = "SignalStrength: "
        if signal_str in line:
          lvl_idx_start = line.find(signal_str) + len(signal_str)

            

Reported by Bandit.

tools/scripts/fetch_image_from_route.py
15 issues
Unable to import 'tools.lib.auth_config'
Error

Line: 11 Column: 1

              
import requests
from PIL import Image
from tools.lib.auth_config import get_token
from tools.lib.framereader import FrameReader

jwt = get_token()

route = sys.argv[1]

            

Reported by Pylint.

Unable to import 'tools.lib.framereader'
Error

Line: 12 Column: 1

              import requests
from PIL import Image
from tools.lib.auth_config import get_token
from tools.lib.framereader import FrameReader

jwt = get_token()

route = sys.argv[1]
segment = int(sys.argv[2])

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3
import sys

if len(sys.argv) < 4:
  print("%s <route> <segment> <frame number>" % sys.argv[0])
  print('example: ./fetch_image_from_route.py "02c45f73a2e5c6e9|2020-06-01--18-03-08" 3 500')
  exit(0)

import requests

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 5 Column: 1

              import sys

if len(sys.argv) < 4:
  print("%s <route> <segment> <frame number>" % sys.argv[0])
  print('example: ./fetch_image_from_route.py "02c45f73a2e5c6e9|2020-06-01--18-03-08" 3 500')
  exit(0)

import requests
from PIL import Image

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 6 Column: 1

              
if len(sys.argv) < 4:
  print("%s <route> <segment> <frame number>" % sys.argv[0])
  print('example: ./fetch_image_from_route.py "02c45f73a2e5c6e9|2020-06-01--18-03-08" 3 500')
  exit(0)

import requests
from PIL import Image
from tools.lib.auth_config import get_token

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 7 Column: 1

              if len(sys.argv) < 4:
  print("%s <route> <segment> <frame number>" % sys.argv[0])
  print('example: ./fetch_image_from_route.py "02c45f73a2e5c6e9|2020-06-01--18-03-08" 3 500')
  exit(0)

import requests
from PIL import Image
from tools.lib.auth_config import get_token
from tools.lib.framereader import FrameReader

            

Reported by Pylint.

Consider using sys.exit()
Error

Line: 7 Column: 3

              if len(sys.argv) < 4:
  print("%s <route> <segment> <frame number>" % sys.argv[0])
  print('example: ./fetch_image_from_route.py "02c45f73a2e5c6e9|2020-06-01--18-03-08" 3 500')
  exit(0)

import requests
from PIL import Image
from tools.lib.auth_config import get_token
from tools.lib.framereader import FrameReader

            

Reported by Pylint.

Import "import requests" should be placed at the top of the module
Error

Line: 9 Column: 1

                print('example: ./fetch_image_from_route.py "02c45f73a2e5c6e9|2020-06-01--18-03-08" 3 500')
  exit(0)

import requests
from PIL import Image
from tools.lib.auth_config import get_token
from tools.lib.framereader import FrameReader

jwt = get_token()

            

Reported by Pylint.

Import "from PIL import Image" should be placed at the top of the module
Error

Line: 10 Column: 1

                exit(0)

import requests
from PIL import Image
from tools.lib.auth_config import get_token
from tools.lib.framereader import FrameReader

jwt = get_token()


            

Reported by Pylint.

Import "from tools.lib.auth_config import get_token" should be placed at the top of the module
Error

Line: 11 Column: 1

              
import requests
from PIL import Image
from tools.lib.auth_config import get_token
from tools.lib.framereader import FrameReader

jwt = get_token()

route = sys.argv[1]

            

Reported by Pylint.

tools/scripts/setup_ssh_keys.py
15 issues
Unable to import 'common.params'
Error

Line: 4 Column: 1

              #!/usr/bin/env python3

import requests
from common.params import Params
import sys


if __name__ == "__main__":
  if len(sys.argv) < 2:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3

import requests
from common.params import Params
import sys


if __name__ == "__main__":
  if len(sys.argv) < 2:

            

Reported by Pylint.

standard import "import sys" should be placed before "import requests"
Error

Line: 5 Column: 1

              
import requests
from common.params import Params
import sys


if __name__ == "__main__":
  if len(sys.argv) < 2:
    print("%s <github username>" % sys.argv[0])

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 9 Column: 1

              

if __name__ == "__main__":
  if len(sys.argv) < 2:
    print("%s <github username>" % sys.argv[0])
    exit(1)

  username = sys.argv[1]
  keys = requests.get(f"https://github.com/{username}.keys")

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 10 Column: 1

              
if __name__ == "__main__":
  if len(sys.argv) < 2:
    print("%s <github username>" % sys.argv[0])
    exit(1)

  username = sys.argv[1]
  keys = requests.get(f"https://github.com/{username}.keys")


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 11 Column: 1

              if __name__ == "__main__":
  if len(sys.argv) < 2:
    print("%s <github username>" % sys.argv[0])
    exit(1)

  username = sys.argv[1]
  keys = requests.get(f"https://github.com/{username}.keys")

  if keys.status_code == 200:

            

Reported by Pylint.

Consider using sys.exit()
Error

Line: 11 Column: 5

              if __name__ == "__main__":
  if len(sys.argv) < 2:
    print("%s <github username>" % sys.argv[0])
    exit(1)

  username = sys.argv[1]
  keys = requests.get(f"https://github.com/{username}.keys")

  if keys.status_code == 200:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 13 Column: 1

                  print("%s <github username>" % sys.argv[0])
    exit(1)

  username = sys.argv[1]
  keys = requests.get(f"https://github.com/{username}.keys")

  if keys.status_code == 200:
    Params().put("GithubSshKeys", keys.text)
    Params().put("GithubUsername", username)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 14 Column: 1

                  exit(1)

  username = sys.argv[1]
  keys = requests.get(f"https://github.com/{username}.keys")

  if keys.status_code == 200:
    Params().put("GithubSshKeys", keys.text)
    Params().put("GithubUsername", username)
    print("Setup ssh keys successfully")

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 16 Column: 1

                username = sys.argv[1]
  keys = requests.get(f"https://github.com/{username}.keys")

  if keys.status_code == 200:
    Params().put("GithubSshKeys", keys.text)
    Params().put("GithubUsername", username)
    print("Setup ssh keys successfully")
  else:
    print("Error getting public keys from github")

            

Reported by Pylint.