style(memmap): format with Ruff
This change adds the Python formatter and linter Ruff to the Poetry
development dependencies for the memory map script, and formats the
entire project using it.
Change-Id: I7c5898bd8ee364e3b72476014ef6b4b11947ae18
Signed-off-by: Chris Kay <chris.kay@arm.com>
diff --git a/tools/memory/src/memory/buildparser.py b/tools/memory/src/memory/buildparser.py
index ea417e1..5fb275a 100755
--- a/tools/memory/src/memory/buildparser.py
+++ b/tools/memory/src/memory/buildparser.py
@@ -47,9 +47,7 @@
@property
def symbols(self) -> list:
- return [
- (*sym, k) for k, v in self._modules.items() for sym in v.symbols
- ]
+ return [(*sym, k) for k, v in self._modules.items() for sym in v.symbols]
@staticmethod
def filter_symbols(symbols: list, regex: str = None) -> list:
diff --git a/tools/memory/src/memory/elfparser.py b/tools/memory/src/memory/elfparser.py
index e6581c9..146b825 100644
--- a/tools/memory/src/memory/elfparser.py
+++ b/tools/memory/src/memory/elfparser.py
@@ -54,9 +54,9 @@
"""Converts a pyelfparser Segment or Section to a TfaMemObject."""
# Ensure each segment is provided a name since they aren't in the
# program header.
- assert not (
- segment and name is None
- ), "Attempting to make segment without a name"
+ assert not (segment and name is None), (
+ "Attempting to make segment without a name"
+ )
if children is None:
children = list()
@@ -91,9 +91,7 @@
def set_segment_section_map(self, segments, sections):
"""Set segment to section mappings."""
- segments = list(
- filter(lambda seg: seg["p_type"] == "PT_LOAD", segments)
- )
+ segments = list(filter(lambda seg: seg["p_type"] == "PT_LOAD", segments))
for sec in sections:
for n, seg in enumerate(segments):
@@ -103,9 +101,7 @@
seg, name=f"{n:#02}", segment=True
)
- self._segments[n].children.append(
- self.tfa_mem_obj_factory(sec)
- )
+ self._segments[n].children.append(self.tfa_mem_obj_factory(sec))
def get_memory_layout_from_symbols(self, expr=None) -> dict:
"""Retrieve information about the memory configuration from the symbol
diff --git a/tools/memory/src/memory/mapparser.py b/tools/memory/src/memory/mapparser.py
index 1c28e71..0d59f50 100644
--- a/tools/memory/src/memory/mapparser.py
+++ b/tools/memory/src/memory/mapparser.py
@@ -57,19 +57,14 @@
if "start" and "length" and "end" in memory_layout[region]:
memory_layout[region]["limit"] = (
- memory_layout[region]["start"]
- + memory_layout[region]["length"]
+ memory_layout[region]["start"] + memory_layout[region]["length"]
)
memory_layout[region]["free"] = (
- memory_layout[region]["limit"]
- - memory_layout[region]["end"]
+ memory_layout[region]["limit"] - memory_layout[region]["end"]
)
- memory_layout[region]["total"] = memory_layout[region][
- "length"
- ]
+ memory_layout[region]["total"] = memory_layout[region]["length"]
memory_layout[region]["size"] = (
- memory_layout[region]["end"]
- - memory_layout[region]["start"]
+ memory_layout[region]["end"] - memory_layout[region]["start"]
)
return memory_layout
diff --git a/tools/memory/src/memory/memmap.py b/tools/memory/src/memory/memmap.py
index f46db8c..c9556fe 100755
--- a/tools/memory/src/memory/memmap.py
+++ b/tools/memory/src/memory/memmap.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python3
-
#
# Copyright (c) 2023-2025, Arm Limited. All rights reserved.
#
@@ -9,6 +7,7 @@
from pathlib import Path
import click
+
from memory.buildparser import TfaBuildParser
from memory.printer import TfaPrettyPrinter
diff --git a/tools/memory/src/memory/printer.py b/tools/memory/src/memory/printer.py
index f797139..58f80d9 100755
--- a/tools/memory/src/memory/printer.py
+++ b/tools/memory/src/memory/printer.py
@@ -50,13 +50,11 @@
if len_over > 0:
section_name = section_name[len_over:-len_over]
- sec_row = f"+{section_name:-^{width-1}}+"
+ sec_row = f"+{section_name:-^{width - 1}}+"
sep, fill = ("+", "-") if is_edge else ("|", "")
sec_row_l = empty_col.format(sep, fill + "<", width) * rel_pos
- sec_row_r = empty_col.format(sep, fill + ">", width) * (
- columns - rel_pos - 1
- )
+ sec_row_r = empty_col.format(sep, fill + ">", width) * (columns - rel_pos - 1)
return leading + sec_row_l + sec_row + sec_row_r
@@ -84,9 +82,7 @@
table.add_row(
[
mod.upper(),
- *self.format_args(
- *[val[k.lower()] for k in fields[1:]]
- ),
+ *self.format_args(*[val[k.lower()] for k in fields[1:]]),
]
)
print(table, "\n")
@@ -102,22 +98,17 @@
col_width = int((self.term_size - start) / len(modules))
address_fixed_width = 11
- num_fmt = (
- f"0=#0{address_fixed_width}x" if not self.as_decimal else ">10"
- )
+ num_fmt = f"0=#0{address_fixed_width}x" if not self.as_decimal else ">10"
_symbol_map = [
- " " * start
- + "".join(self.format_args(*modules, fmt=f"^{col_width}"))
+ " " * start + "".join(self.format_args(*modules, fmt=f"^{col_width}"))
]
last_addr = None
for i, (name, addr, mod) in enumerate(symbols):
# Do not print out an address twice if two symbols overlap,
# for example, at the end of one region and start of another.
- leading = (
- f"{addr:{num_fmt}}" + " " if addr != last_addr else " " * start
- )
+ leading = f"{addr:{num_fmt}}" + " " if addr != last_addr else " " * start
_symbol_map.append(
self.map_elf_symbol(