mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-20 20:13:44 +08:00
lint: check indentation (#38454)
* lint: check indentation * cleanup * happy * that was too much * happy
This commit is contained in:
@@ -6,12 +6,12 @@ sr = 48000
|
||||
max_int16 = 2**15 - 1
|
||||
|
||||
def harmonic_beep(freq, duration_seconds):
|
||||
n_total = int(sr * duration_seconds)
|
||||
n_total = int(sr * duration_seconds)
|
||||
|
||||
signal = np.sin(2 * np.pi * freq * np.arange(n_total) / sr)
|
||||
x = np.arange(n_total)
|
||||
exp_scale = np.exp(-x/5.5e3)
|
||||
return max_int16 * signal * exp_scale
|
||||
signal = np.sin(2 * np.pi * freq * np.arange(n_total) / sr)
|
||||
x = np.arange(n_total)
|
||||
exp_scale = np.exp(-x/5.5e3)
|
||||
return max_int16 * signal * exp_scale
|
||||
|
||||
engage_beep = harmonic_beep(1661.219, 0.5)
|
||||
wavfile.write("engage.wav", sr, engage_beep.astype(np.int16))
|
||||
|
||||
@@ -9,29 +9,29 @@ from openpilot.common.transformations.orientation import rot_from_euler, euler_f
|
||||
|
||||
@cache
|
||||
def fft_next_good_size(n: int) -> int:
|
||||
"""
|
||||
smallest composite of 2, 3, 5, 7, 11 that is >= n
|
||||
inspired by pocketfft
|
||||
"""
|
||||
if n <= 6:
|
||||
return n
|
||||
best, f2 = 2 * n, 1
|
||||
while f2 < best:
|
||||
f23 = f2
|
||||
while f23 < best:
|
||||
f235 = f23
|
||||
while f235 < best:
|
||||
f2357 = f235
|
||||
while f2357 < best:
|
||||
f235711 = f2357
|
||||
while f235711 < best:
|
||||
best = f235711 if f235711 >= n else best
|
||||
f235711 *= 11
|
||||
f2357 *= 7
|
||||
f235 *= 5
|
||||
f23 *= 3
|
||||
f2 *= 2
|
||||
return best
|
||||
"""
|
||||
smallest composite of 2, 3, 5, 7, 11 that is >= n
|
||||
inspired by pocketfft
|
||||
"""
|
||||
if n <= 6:
|
||||
return n
|
||||
best, f2 = 2 * n, 1
|
||||
while f2 < best:
|
||||
f23 = f2
|
||||
while f23 < best:
|
||||
f235 = f23
|
||||
while f235 < best:
|
||||
f2357 = f235
|
||||
while f2357 < best:
|
||||
f235711 = f2357
|
||||
while f235711 < best:
|
||||
best = f235711 if f235711 >= n else best
|
||||
f235711 *= 11
|
||||
f2357 *= 7
|
||||
f235 *= 5
|
||||
f23 *= 3
|
||||
f2 *= 2
|
||||
return best
|
||||
|
||||
|
||||
def parabolic_peak_interp(R, max_index):
|
||||
|
||||
@@ -383,12 +383,12 @@ class CameraView(Widget):
|
||||
self._initialize_textures()
|
||||
|
||||
def _initialize_textures(self):
|
||||
self._clear_textures()
|
||||
if not TICI:
|
||||
self.texture_y = rl.load_texture_from_image(rl.Image(None, int(self.client.stride),
|
||||
int(self.client.height), 1, rl.PixelFormat.PIXELFORMAT_UNCOMPRESSED_GRAYSCALE))
|
||||
self.texture_uv = rl.load_texture_from_image(rl.Image(None, int(self.client.stride // 2),
|
||||
int(self.client.height // 2), 1, rl.PixelFormat.PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA))
|
||||
self._clear_textures()
|
||||
if not TICI:
|
||||
self.texture_y = rl.load_texture_from_image(rl.Image(None, int(self.client.stride),
|
||||
int(self.client.height), 1, rl.PixelFormat.PIXELFORMAT_UNCOMPRESSED_GRAYSCALE))
|
||||
self.texture_uv = rl.load_texture_from_image(rl.Image(None, int(self.client.stride // 2),
|
||||
int(self.client.height // 2), 1, rl.PixelFormat.PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA))
|
||||
|
||||
def _clear_textures(self):
|
||||
if self.texture_y and self.texture_y.id:
|
||||
|
||||
@@ -580,7 +580,7 @@ def startStream(sdp: str, enabled: bool) -> dict:
|
||||
if CP.notCar:
|
||||
bridge_services_in.append("testJoystick")
|
||||
else:
|
||||
raise Exception("failed to get CarParamsPersistent")
|
||||
raise Exception("failed to get CarParamsPersistent")
|
||||
|
||||
if params.get_bool("IsOffroad"):
|
||||
# manager owns camerad/stream_encoderd/webrtcd; flip the param and let it bring them up.
|
||||
|
||||
@@ -49,7 +49,7 @@ def with_upload_handler(func):
|
||||
return wrapper
|
||||
|
||||
def mock_create_connection(mocker):
|
||||
return mocker.patch('openpilot.system.athena.athenad.create_connection')
|
||||
return mocker.patch('openpilot.system.athena.athenad.create_connection')
|
||||
|
||||
def host():
|
||||
with http_server_context(handler=HTTPRequestHandler, setup=seed_athena_server) as (host, port):
|
||||
|
||||
@@ -28,7 +28,7 @@ class LRUCache:
|
||||
def __setitem__(self, key, value):
|
||||
self._cache[key] = value
|
||||
if len(self._cache) > self.capacity:
|
||||
self._cache.popitem(last=False)
|
||||
self._cache.popitem(last=False)
|
||||
|
||||
def __contains__(self, key):
|
||||
return key in self._cache
|
||||
|
||||
@@ -27,9 +27,9 @@ def apply_metadrive_patches(arrive_dest_done=True):
|
||||
# By default, metadrive won't try to use cuda images unless it's used as a sensor for vehicles, so patch that in
|
||||
def add_image_sensor_patched(self, name: str, cls, args):
|
||||
if self.global_config["image_on_cuda"]:# and name == self.global_config["vehicle_config"]["image_source"]:
|
||||
sensor = cls(*args, self, cuda=True)
|
||||
sensor = cls(*args, self, cuda=True)
|
||||
else:
|
||||
sensor = cls(*args, self, cuda=False)
|
||||
sensor = cls(*args, self, cuda=False)
|
||||
assert isinstance(sensor, ImageBuffer), "This API is for adding image sensor"
|
||||
self.sensors[name] = sensor
|
||||
|
||||
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import tokenize
|
||||
|
||||
|
||||
# TODO: remove this once https://github.com/astral-sh/ruff/issues/8705 is closed
|
||||
def check_indentation(filename: str, indent_width: int = 2) -> bool:
|
||||
failed = False
|
||||
indent_stack = [0]
|
||||
|
||||
with tokenize.open(filename) as f:
|
||||
tokens = tokenize.generate_tokens(f.readline)
|
||||
for token in tokens:
|
||||
if token.type == tokenize.INDENT:
|
||||
indentation = token.string
|
||||
width = len(indentation)
|
||||
expected = indent_stack[-1] + indent_width
|
||||
|
||||
if indentation != " " * expected:
|
||||
found = "indentation containing tabs" if "\t" in indentation else f"{width} spaces"
|
||||
print(f"{filename}:{token.start[0]}:1: expected {expected} spaces, found {found}")
|
||||
failed = True
|
||||
indent_stack.append(width)
|
||||
elif token.type == tokenize.DEDENT:
|
||||
indent_stack.pop()
|
||||
|
||||
return failed
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Check Python block indentation.")
|
||||
parser.add_argument("filenames", nargs="+")
|
||||
args = parser.parse_args()
|
||||
|
||||
failed = False
|
||||
for filename in args.filenames:
|
||||
failed |= check_indentation(filename)
|
||||
raise SystemExit(failed)
|
||||
@@ -46,6 +46,7 @@ function run_tests() {
|
||||
PYTHON_FILES=$2
|
||||
|
||||
run "ruff" ruff check openpilot --quiet
|
||||
run "check_indentation" $DIR/check_indentation.py $PYTHON_FILES
|
||||
run "check_added_large_files" $DIR/check_added_large_files.py --maxkb=120 $ALL_FILES
|
||||
run "check_shebang_scripts_are_executable" $DIR/check_shebang_scripts_are_executable.py $ALL_FILES
|
||||
run "check_shebang_format" $DIR/check_shebang_format.sh $ALL_FILES
|
||||
@@ -66,6 +67,7 @@ function help() {
|
||||
echo ""
|
||||
echo -e "${BOLD}${UNDERLINE}Tests:${NC}"
|
||||
echo -e " ${BOLD}ruff${NC}"
|
||||
echo -e " ${BOLD}check_indentation${NC}"
|
||||
echo -e " ${BOLD}ty${NC}"
|
||||
echo -e " ${BOLD}codespell${NC}"
|
||||
echo -e " ${BOLD}check_added_large_files${NC}"
|
||||
|
||||
Reference in New Issue
Block a user