From 284450400e717e81fb6d57a342e8645df2fd73b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Medi=C4=87?= <45833725+belimedo@users.noreply.github.com> Date: Mon, 19 Feb 2024 21:11:56 +0100 Subject: [PATCH] add Cython static analysis (#31491) * Adding pre-commit hook for cython static analysis * Adding changes to cython files to pass static analysis * Revert "Adding changes to cython files to pass static analysis" This reverts commit 9a0eb733199abd9eef1eac3d024ef2760348d67c. * Adding ignore rule for indentation of 4 spaces (E111) * Fixes for cython-lint static analysis * Revert "Fixes for cython-lint static analysis" This reverts commit 972741735b2bdc73460d65a4d7ea167dfc0f4644. * Adding two new rules into ignore list (2 new lines after difinition of class) * Adding fixes for cython static analysis old-commit-hash: 69fb3c2ed5b41858545461466004339325e413a1 --- .pre-commit-config.yaml | 8 ++++++++ common/params_pyx.pyx | 2 +- common/transformations/transformations.pxd | 2 +- common/transformations/transformations.pyx | 7 +++---- selfdrive/modeld/models/commonmodel_pyx.pxd | 2 +- selfdrive/modeld/runners/runmodel_pyx.pyx | 1 - 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 30750d6ab7..f98bca6060 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -74,6 +74,14 @@ repos: # https://google.github.io/styleguide/cppguide.html # relevant rules are whitelisted, see all options with: cpplint --filter= - --filter=-build,-legal,-readability,-runtime,-whitespace,+build/include_subdir,+build/forward_decl,+build/include_what_you_use,+build/deprecated,+whitespace/comma,+whitespace/line_length,+whitespace/empty_if_body,+whitespace/empty_loop_body,+whitespace/empty_conditional_body,+whitespace/forcolon,+whitespace/parens,+whitespace/semicolon,+whitespace/tab,+readability/braces +- repo: https://github.com/MarcoGorelli/cython-lint + rev: v0.16.0 + hooks: + - id: cython-lint + exclude: '^(third_party/)|(cereal/)|(body/)|(rednose/)|(rednose_repo/)|(opendbc/)|(panda/)|(generated/)' + args: + - --max-line-length=240 + - --ignore=E111, E302, E305 - repo: local hooks: - id: test_translations diff --git a/common/params_pyx.pyx b/common/params_pyx.pyx index 47d2075df2..535514e521 100644 --- a/common/params_pyx.pyx +++ b/common/params_pyx.pyx @@ -29,7 +29,7 @@ cdef extern from "common/params.h": def ensure_bytes(v): - return v.encode() if isinstance(v, str) else v; + return v.encode() if isinstance(v, str) else v class UnknownKeyName(Exception): pass diff --git a/common/transformations/transformations.pxd b/common/transformations/transformations.pxd index 7af0098701..964adf06ec 100644 --- a/common/transformations/transformations.pxd +++ b/common/transformations/transformations.pxd @@ -1,4 +1,4 @@ -#cython: language_level=3 +# cython: language_level=3 from libcpp cimport bool cdef extern from "orientation.cc": diff --git a/common/transformations/transformations.pyx b/common/transformations/transformations.pyx index c5cb9e0056..ae045c369d 100644 --- a/common/transformations/transformations.pyx +++ b/common/transformations/transformations.pyx @@ -17,7 +17,6 @@ from openpilot.common.transformations.transformations cimport ecef2geodetic as e from openpilot.common.transformations.transformations cimport LocalCoord_c -import cython import numpy as np cimport numpy as np @@ -34,14 +33,14 @@ cdef Matrix3 numpy2matrix(np.ndarray[double, ndim=2, mode="fortran"] m): return Matrix3(m.data) cdef ECEF list2ecef(ecef): - cdef ECEF e; + cdef ECEF e e.x = ecef[0] e.y = ecef[1] e.z = ecef[2] return e cdef NED list2ned(ned): - cdef NED n; + cdef NED n n.n = ned[0] n.e = ned[1] n.d = ned[2] @@ -61,7 +60,7 @@ def euler2quat_single(euler): def quat2euler_single(quat): cdef Quaternion q = Quaternion(quat[0], quat[1], quat[2], quat[3]) - cdef Vector3 e = quat2euler_c(q); + cdef Vector3 e = quat2euler_c(q) return [e(0), e(1), e(2)] def quat2rot_single(quat): diff --git a/selfdrive/modeld/models/commonmodel_pyx.pxd b/selfdrive/modeld/models/commonmodel_pyx.pxd index 21c0716de4..97e3914588 100644 --- a/selfdrive/modeld/models/commonmodel_pyx.pxd +++ b/selfdrive/modeld/models/commonmodel_pyx.pxd @@ -7,7 +7,7 @@ cdef class CLContext(BaseCLContext): pass cdef class CLMem: - cdef cl_mem * mem; + cdef cl_mem * mem @staticmethod cdef create(void*) diff --git a/selfdrive/modeld/runners/runmodel_pyx.pyx b/selfdrive/modeld/runners/runmodel_pyx.pyx index cdc62a79be..e1b201a6a9 100644 --- a/selfdrive/modeld/runners/runmodel_pyx.pyx +++ b/selfdrive/modeld/runners/runmodel_pyx.pyx @@ -2,7 +2,6 @@ # cython: c_string_encoding=ascii from libcpp.string cimport string -from libc.string cimport memcpy from .runmodel cimport USE_CPU_RUNTIME, USE_GPU_RUNTIME, USE_DSP_RUNTIME from selfdrive.modeld.models.commonmodel_pyx cimport CLMem