[upstream_util, wpiutil] Refactor python scripts (#4614)

Co-authored-by: Sourcery AI <>
Co-authored-by: Vasista Vovveti <vasistavovveti@gmail.com>
Co-authored-by: David Vo <auscompgeek@users.noreply.github.com>
This commit is contained in:
Ege Akman
2022-11-14 10:11:54 +03:00
committed by GitHub
parent c4e526d315
commit 5a320c326b
3 changed files with 12 additions and 16 deletions

View File

@@ -73,12 +73,8 @@ def eigen_inclusions(dp, f):
]
modules_rgx = r"|".join("/" + m for m in modules)
# "Std" matches StdDeque, StdList, and StdVector headers
if re.search(modules_rgx, abspath) or "Std" in f:
return True
else:
# Exclude all other modules
return False
# "Std" matches StdDeque, StdList, and StdVector headers. Other modules are excluded.
return bool(re.search(modules_rgx, abspath) or "Std" in f)
def unsupported_inclusions(dp, f):

View File

@@ -126,12 +126,12 @@ def overwrite_files(wpiutil_files, llvm_files):
for wpi_file in wpiutil_files:
wpi_base_name = os.path.basename(wpi_file)
if wpi_base_name not in llvm_files:
if wpi_base_name not in unmatched_files_whitelist:
print(f"No file match for {wpi_file}, check if LLVM deleted it")
else:
if wpi_base_name in llvm_files:
shutil.copyfile(llvm_files[wpi_base_name], wpi_file)
elif wpi_base_name not in unmatched_files_whitelist:
print(f"No file match for {wpi_file}, check if LLVM deleted it")
def overwrite_source(wpiutil_root, llvm_root):
llvm_files = flattened_llvm_files(

View File

@@ -153,17 +153,17 @@ class DataLogRecord:
return arr
def getStringArray(self) -> List[str]:
size = int.from_bytes(self.data[0:4], byteorder="little", signed=False)
size = int.from_bytes(self.data[:4], byteorder="little", signed=False)
if size > ((len(self.data) - 4) / 4):
raise TypeError("not a string array")
arr = []
pos = 4
for i in range(size):
for _ in range(size):
val, pos = self._readInnerString(pos)
arr.append(val)
return arr
def _readInnerString(self, pos: int) -> str:
def _readInnerString(self, pos: int) -> tuple[str, int]:
size = int.from_bytes(
self.data[pos : pos + 4], byteorder="little", signed=False
)
@@ -225,7 +225,7 @@ class DataLogReader:
"""Returns true if the data log is valid (e.g. has a valid header)."""
return (
len(self.buf) >= 12
and self.buf[0:6] == b"WPILOG"
and self.buf[:6] == b"WPILOG"
and self.getVersion() >= 0x0100
)
@@ -307,7 +307,7 @@ if __name__ == "__main__":
print("Unrecognized control record")
else:
print(f"Data({record.entry}, size={len(record.data)}) ", end="")
entry = entries.get(record.entry, None)
entry = entries.get(record.entry)
if entry is None:
print("<ID not found>")
continue
@@ -324,7 +324,7 @@ if __name__ == "__main__":
print(f" {record.getDouble()}")
elif entry.type == "int64":
print(f" {record.getInteger()}")
elif entry.type == "string" or entry.type == "json":
elif entry.type in ("string", "json"):
print(f" '{record.getString()}'")
elif entry.type == "boolean":
print(f" {record.getBoolean()}")