mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-27 17:42:04 +08:00
Ruff: enable flake8-builtins (#29315)
* enable flake8-builtins * replace any with contains * fix typo in pack * fix type * format is from the parent module, has to be enabled * item_id * fix item_id * disable for id since that's what the remote server returns old-commit-hash: 8793cbff40662a92bff16d75b51479c80517305a
This commit is contained in:
@@ -65,7 +65,7 @@ class SwagFormatter(logging.Formatter):
|
||||
|
||||
return record_dict
|
||||
|
||||
def format(self, record):
|
||||
def format(self, record): # noqa: A003
|
||||
if self.swaglogger is None:
|
||||
raise Exception("must set swaglogger before calling format()")
|
||||
return json_robust_dumps(self.format_dict(record))
|
||||
@@ -95,7 +95,7 @@ class SwagLogFileFormatter(SwagFormatter):
|
||||
k += "$a"
|
||||
return k, v
|
||||
|
||||
def format(self, record):
|
||||
def format(self, record): # noqa: A003
|
||||
if isinstance(record, str):
|
||||
v = json.loads(record)
|
||||
else:
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ VERSION = get_version()
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'openpilot docs'
|
||||
copyright = '2021, comma.ai'
|
||||
copyright = '2021, comma.ai' # noqa: A001
|
||||
author = 'comma.ai'
|
||||
version = VERSION
|
||||
release = VERSION
|
||||
|
||||
+1
-1
@@ -197,7 +197,7 @@ build-backend = "poetry.core.masonry.api"
|
||||
|
||||
# https://beta.ruff.rs/docs/configuration/#using-pyprojecttoml
|
||||
[tool.ruff]
|
||||
select = ["E", "F", "W", "PIE", "C4", "ISC", "RUF100"]
|
||||
select = ["E", "F", "W", "PIE", "C4", "ISC", "RUF100", "A"]
|
||||
ignore = ["W292", "E741", "E402", "C408", "ISC003"]
|
||||
line-length = 160
|
||||
target-version="py311"
|
||||
|
||||
@@ -85,7 +85,7 @@ class UploadItem:
|
||||
url: str
|
||||
headers: Dict[str, str]
|
||||
created_at: int
|
||||
id: Optional[str]
|
||||
id: Optional[str] # noqa: A003 (to match the response from the remote server)
|
||||
retry_count: int = 0
|
||||
current: bool = False
|
||||
progress: float = 0
|
||||
|
||||
@@ -50,7 +50,7 @@ class BasePart:
|
||||
|
||||
class EnumBase(Enum):
|
||||
@property
|
||||
def type(self):
|
||||
def part_type(self):
|
||||
return PartType(self.__class__)
|
||||
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class TestCarDocs(unittest.TestCase):
|
||||
if car.name == "comma body":
|
||||
raise unittest.SkipTest
|
||||
|
||||
car_part_type = [p.type for p in car.car_parts.all_parts()]
|
||||
car_part_type = [p.part_type for p in car.car_parts.all_parts()]
|
||||
car_parts = list(car.car_parts.all_parts())
|
||||
self.assertTrue(len(car_parts) > 0, f"Need to specify car parts: {car.name}")
|
||||
self.assertTrue(car_part_type.count(PartType.connector) == 1, f"Need to specify one harness connector: {car.name}")
|
||||
|
||||
@@ -351,7 +351,7 @@ class Controls:
|
||||
|
||||
# generic catch-all. ideally, a more specific event should be added above instead
|
||||
can_rcv_timeout = self.can_rcv_timeout_counter >= 5
|
||||
has_disable_events = self.events.any(ET.NO_ENTRY) and (self.events.any(ET.SOFT_DISABLE) or self.events.any(ET.IMMEDIATE_DISABLE))
|
||||
has_disable_events = self.events.contains(ET.NO_ENTRY) and (self.events.contains(ET.SOFT_DISABLE) or self.events.contains(ET.IMMEDIATE_DISABLE))
|
||||
no_system_errors = (not has_disable_events) or (len(self.events) == num_events)
|
||||
if (not self.sm.all_checks() or can_rcv_timeout) and no_system_errors:
|
||||
if not self.sm.all_alive():
|
||||
@@ -487,29 +487,29 @@ class Controls:
|
||||
# ENABLED, SOFT DISABLING, PRE ENABLING, OVERRIDING
|
||||
if self.state != State.disabled:
|
||||
# user and immediate disable always have priority in a non-disabled state
|
||||
if self.events.any(ET.USER_DISABLE):
|
||||
if self.events.contains(ET.USER_DISABLE):
|
||||
self.state = State.disabled
|
||||
self.current_alert_types.append(ET.USER_DISABLE)
|
||||
|
||||
elif self.events.any(ET.IMMEDIATE_DISABLE):
|
||||
elif self.events.contains(ET.IMMEDIATE_DISABLE):
|
||||
self.state = State.disabled
|
||||
self.current_alert_types.append(ET.IMMEDIATE_DISABLE)
|
||||
|
||||
else:
|
||||
# ENABLED
|
||||
if self.state == State.enabled:
|
||||
if self.events.any(ET.SOFT_DISABLE):
|
||||
if self.events.contains(ET.SOFT_DISABLE):
|
||||
self.state = State.softDisabling
|
||||
self.soft_disable_timer = int(SOFT_DISABLE_TIME / DT_CTRL)
|
||||
self.current_alert_types.append(ET.SOFT_DISABLE)
|
||||
|
||||
elif self.events.any(ET.OVERRIDE_LATERAL) or self.events.any(ET.OVERRIDE_LONGITUDINAL):
|
||||
elif self.events.contains(ET.OVERRIDE_LATERAL) or self.events.contains(ET.OVERRIDE_LONGITUDINAL):
|
||||
self.state = State.overriding
|
||||
self.current_alert_types += [ET.OVERRIDE_LATERAL, ET.OVERRIDE_LONGITUDINAL]
|
||||
|
||||
# SOFT DISABLING
|
||||
elif self.state == State.softDisabling:
|
||||
if not self.events.any(ET.SOFT_DISABLE):
|
||||
if not self.events.contains(ET.SOFT_DISABLE):
|
||||
# no more soft disabling condition, so go back to ENABLED
|
||||
self.state = State.enabled
|
||||
|
||||
@@ -521,32 +521,32 @@ class Controls:
|
||||
|
||||
# PRE ENABLING
|
||||
elif self.state == State.preEnabled:
|
||||
if not self.events.any(ET.PRE_ENABLE):
|
||||
if not self.events.contains(ET.PRE_ENABLE):
|
||||
self.state = State.enabled
|
||||
else:
|
||||
self.current_alert_types.append(ET.PRE_ENABLE)
|
||||
|
||||
# OVERRIDING
|
||||
elif self.state == State.overriding:
|
||||
if self.events.any(ET.SOFT_DISABLE):
|
||||
if self.events.contains(ET.SOFT_DISABLE):
|
||||
self.state = State.softDisabling
|
||||
self.soft_disable_timer = int(SOFT_DISABLE_TIME / DT_CTRL)
|
||||
self.current_alert_types.append(ET.SOFT_DISABLE)
|
||||
elif not (self.events.any(ET.OVERRIDE_LATERAL) or self.events.any(ET.OVERRIDE_LONGITUDINAL)):
|
||||
elif not (self.events.contains(ET.OVERRIDE_LATERAL) or self.events.contains(ET.OVERRIDE_LONGITUDINAL)):
|
||||
self.state = State.enabled
|
||||
else:
|
||||
self.current_alert_types += [ET.OVERRIDE_LATERAL, ET.OVERRIDE_LONGITUDINAL]
|
||||
|
||||
# DISABLED
|
||||
elif self.state == State.disabled:
|
||||
if self.events.any(ET.ENABLE):
|
||||
if self.events.any(ET.NO_ENTRY):
|
||||
if self.events.contains(ET.ENABLE):
|
||||
if self.events.contains(ET.NO_ENTRY):
|
||||
self.current_alert_types.append(ET.NO_ENTRY)
|
||||
|
||||
else:
|
||||
if self.events.any(ET.PRE_ENABLE):
|
||||
if self.events.contains(ET.PRE_ENABLE):
|
||||
self.state = State.preEnabled
|
||||
elif self.events.any(ET.OVERRIDE_LATERAL) or self.events.any(ET.OVERRIDE_LONGITUDINAL):
|
||||
elif self.events.contains(ET.OVERRIDE_LATERAL) or self.events.contains(ET.OVERRIDE_LONGITUDINAL):
|
||||
self.state = State.overriding
|
||||
else:
|
||||
self.state = State.enabled
|
||||
@@ -585,7 +585,7 @@ class Controls:
|
||||
standstill = CS.vEgo <= max(self.CP.minSteerSpeed, MIN_LATERAL_CONTROL_SPEED) or CS.standstill
|
||||
CC.latActive = self.active and not CS.steerFaultTemporary and not CS.steerFaultPermanent and \
|
||||
(not standstill or self.joystick_mode)
|
||||
CC.longActive = self.enabled and not self.events.any(ET.OVERRIDE_LONGITUDINAL) and self.CP.openpilotLongitudinalControl
|
||||
CC.longActive = self.enabled and not self.events.contains(ET.OVERRIDE_LONGITUDINAL) and self.CP.openpilotLongitudinalControl
|
||||
|
||||
actuators = CC.actuators
|
||||
actuators.longControlState = self.LoC.long_control_state
|
||||
@@ -783,7 +783,7 @@ class Controls:
|
||||
controlsState.desiredCurvature = self.desired_curvature
|
||||
controlsState.desiredCurvatureRate = self.desired_curvature_rate
|
||||
controlsState.state = self.state
|
||||
controlsState.engageable = not self.events.any(ET.NO_ENTRY)
|
||||
controlsState.engageable = not self.events.contains(ET.NO_ENTRY)
|
||||
controlsState.longControlState = self.LoC.long_control_state
|
||||
controlsState.vPid = float(self.LoC.v_pid)
|
||||
controlsState.vCruise = float(self.v_cruise_helper.v_cruise_kph)
|
||||
|
||||
@@ -67,7 +67,7 @@ class Events:
|
||||
self.events_prev = {k: (v + 1 if k in self.events else 0) for k, v in self.events_prev.items()}
|
||||
self.events = self.static_events.copy()
|
||||
|
||||
def any(self, event_type: str) -> bool:
|
||||
def contains(self, event_type: str) -> bool:
|
||||
return any(event_type in EVENTS.get(e, {}) for e in self.events)
|
||||
|
||||
def create_alerts(self, event_types: List[str], callback_args=None):
|
||||
|
||||
@@ -54,14 +54,14 @@ class ReplayContext:
|
||||
assert(len(self.pubs) != 0 or self.main_pub is not None)
|
||||
|
||||
def __enter__(self):
|
||||
self.open()
|
||||
self.open_context()
|
||||
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_obj, exc_tb):
|
||||
self.close()
|
||||
self.close_context()
|
||||
|
||||
def open(self):
|
||||
def open_context(self):
|
||||
messaging.toggle_fake_events(True)
|
||||
messaging.set_fake_prefix(self.proc_name)
|
||||
|
||||
@@ -73,7 +73,7 @@ class ReplayContext:
|
||||
else:
|
||||
self.events = {self.main_pub: messaging.fake_event_handle(self.main_pub, enable=True)}
|
||||
|
||||
def close(self):
|
||||
def close_context(self):
|
||||
del self.events
|
||||
|
||||
messaging.toggle_fake_events(False)
|
||||
@@ -211,7 +211,7 @@ class ProcessContainer:
|
||||
self.cfg.config_callback(params, self.cfg, all_msgs)
|
||||
|
||||
self.rc = ReplayContext(self.cfg)
|
||||
self.rc.open()
|
||||
self.rc.open_context()
|
||||
|
||||
self.pm = messaging.PubMaster(self.cfg.pubs)
|
||||
self.sockets = [messaging.sub_sock(s, timeout=100) for s in self.cfg.subs]
|
||||
@@ -237,7 +237,7 @@ class ProcessContainer:
|
||||
with self.prefix:
|
||||
self.process.signal(signal.SIGKILL)
|
||||
self.process.stop()
|
||||
self.rc.close()
|
||||
self.rc.close_context()
|
||||
self.prefix.clean_dirs()
|
||||
|
||||
def run_step(self, msg: capnp._DynamicStructReader, frs: Optional[Dict[str, Any]]) -> List[capnp._DynamicStructReader]:
|
||||
|
||||
@@ -324,7 +324,7 @@ class UBloxDescriptor:
|
||||
msg._buf += struct.pack(self.format2, *tuple(f2))
|
||||
msg._buf += struct.pack('<BB', *msg.checksum(data=msg._buf[2:]))
|
||||
|
||||
def format(self, msg):
|
||||
def format_json(self, msg):
|
||||
'''return a formatted string for a message'''
|
||||
if not msg._unpacked:
|
||||
self.unpack(msg)
|
||||
@@ -555,19 +555,19 @@ class UBloxMessage:
|
||||
'''format a message as a string'''
|
||||
if not self.valid():
|
||||
return 'UBloxMessage(INVALID)'
|
||||
type = self.msg_type()
|
||||
if type in msg_types:
|
||||
return msg_types[type].format(self)
|
||||
return 'UBloxMessage(UNKNOWN %s, %u)' % (str(type), self.msg_length())
|
||||
msg_type = self.msg_type()
|
||||
if msg_type in msg_types:
|
||||
return msg_types[msg_type].format(self)
|
||||
return 'UBloxMessage(UNKNOWN %s, %u)' % (str(msg_type), self.msg_length())
|
||||
|
||||
def as_dict(self):
|
||||
'''format a message as a string'''
|
||||
if not self.valid():
|
||||
return 'UBloxMessage(INVALID)'
|
||||
type = self.msg_type()
|
||||
if type in msg_types:
|
||||
return msg_types[type].format(self)
|
||||
return 'UBloxMessage(UNKNOWN %s, %u)' % (str(type), self.msg_length())
|
||||
msg_type = self.msg_type()
|
||||
if msg_type in msg_types:
|
||||
return msg_types[msg_type].format(self)
|
||||
return 'UBloxMessage(UNKNOWN %s, %u)' % (str(msg_type), self.msg_length())
|
||||
|
||||
def __getattr__(self, name):
|
||||
'''allow access to message fields'''
|
||||
@@ -598,29 +598,29 @@ class UBloxMessage:
|
||||
'''unpack a message'''
|
||||
if not self.valid():
|
||||
raise UBloxError('INVALID MESSAGE')
|
||||
type = self.msg_type()
|
||||
if type not in msg_types:
|
||||
raise UBloxError('Unknown message %s length=%u' % (str(type), len(self._buf)))
|
||||
msg_types[type].unpack(self)
|
||||
msg_type = self.msg_type()
|
||||
if msg_type not in msg_types:
|
||||
raise UBloxError('Unknown message %s length=%u' % (str(msg_type), len(self._buf)))
|
||||
msg_types[msg_type].unpack(self)
|
||||
return self._fields, self._recs
|
||||
|
||||
def pack(self):
|
||||
'''pack a message'''
|
||||
if not self.valid():
|
||||
raise UBloxError('INVALID MESSAGE')
|
||||
type = self.msg_type()
|
||||
if type not in msg_types:
|
||||
raise UBloxError('Unknown message %s' % str(type))
|
||||
msg_types[type].pack(self)
|
||||
msg_type = self.msg_type()
|
||||
if msg_type not in msg_types:
|
||||
raise UBloxError('Unknown message %s' % str(msg_type))
|
||||
msg_types[msg_type].pack(self)
|
||||
|
||||
def name(self):
|
||||
'''return the short string name for a message'''
|
||||
if not self.valid():
|
||||
raise UBloxError('INVALID MESSAGE')
|
||||
type = self.msg_type()
|
||||
if type not in msg_types:
|
||||
raise UBloxError('Unknown message %s length=%u' % (str(type), len(self._buf)))
|
||||
return msg_types[type].name
|
||||
msg_type = self.msg_type()
|
||||
if msg_type not in msg_types:
|
||||
raise UBloxError('Unknown message %s length=%u' % (str(msg_types), len(self._buf)))
|
||||
return msg_types[msg_type].name
|
||||
|
||||
def msg_class(self):
|
||||
'''return the message class'''
|
||||
@@ -655,9 +655,9 @@ class UBloxMessage:
|
||||
return False
|
||||
return True
|
||||
|
||||
def add(self, bytes):
|
||||
def add(self, data):
|
||||
'''add some bytes to a message'''
|
||||
self._buf += bytes
|
||||
self._buf += data
|
||||
while not self.valid_so_far() and len(self._buf) > 0:
|
||||
'''handle corrupted streams'''
|
||||
self._buf = self._buf[1:]
|
||||
@@ -933,7 +933,7 @@ class UBlox:
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
self.send_message(CLASS_CFG, MSG_CFG_NAVX5, payload)
|
||||
|
||||
def module_reset(self, set, mode):
|
||||
def module_reset(self, reset, mode):
|
||||
''' Reset the module for hot/warm/cold start'''
|
||||
payload = struct.pack('<HBB', set, mode, 0)
|
||||
payload = struct.pack('<HBB', reset, mode, 0)
|
||||
self.send_message(CLASS_CFG, MSG_CFG_RST, payload)
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ class ClientRedirectHandler(BaseHTTPRequestHandler):
|
||||
self.end_headers()
|
||||
self.wfile.write(b'Return to the CLI to continue')
|
||||
|
||||
def log_message(self, format, *args): # pylint: disable=redefined-builtin
|
||||
def log_message(self, *args): # pylint: disable=redefined-builtin
|
||||
pass # this prevent http server from dumping messages to stdout
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user