From 3f46d765e3ccda73a0ef26f7254fe6685b002848 Mon Sep 17 00:00:00 2001 From: Stefan Tatschner Date: Tue, 24 Sep 2024 16:58:44 +0200 Subject: [PATCH] chore: Remove tabulate dependency This is only used in one location for a really simple table. Let's get rid of the dependency. --- poetry.lock | 27 +----------------------- pyproject.toml | 2 -- src/gallia/commands/primitive/uds/dtc.py | 14 ++++++------ src/gallia/utils.py | 9 ++++++++ 4 files changed, 16 insertions(+), 36 deletions(-) diff --git a/poetry.lock b/poetry.lock index 18fbaf556..578e25946 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1768,20 +1768,6 @@ lint = ["mypy", "ruff (==0.5.5)", "types-docutils"] standalone = ["Sphinx (>=5)"] test = ["pytest"] -[[package]] -name = "tabulate" -version = "0.9.0" -description = "Pretty-print tabular data" -optional = false -python-versions = ">=3.7" -files = [ - {file = "tabulate-0.9.0-py3-none-any.whl", hash = "sha256:024ca478df22e9340661486f85298cff5f6dcdba14f3813e8830015b9ed1948f"}, - {file = "tabulate-0.9.0.tar.gz", hash = "sha256:0095b12bf5966de529c0feb1fa08671671b3368eec77d7ef7ab114be2c068b3c"}, -] - -[package.extras] -widechars = ["wcwidth"] - [[package]] name = "tomlkit" version = "0.13.2" @@ -1815,17 +1801,6 @@ files = [ {file = "types_psutil-6.0.0.20240901-py3-none-any.whl", hash = "sha256:20af311bfb0386a018a27ae47dc952119d7c0e849ff72b6aa24fc0433afb92a6"}, ] -[[package]] -name = "types-tabulate" -version = "0.9.0.20240106" -description = "Typing stubs for tabulate" -optional = false -python-versions = ">=3.8" -files = [ - {file = "types-tabulate-0.9.0.20240106.tar.gz", hash = "sha256:c9b6db10dd7fcf55bd1712dd3537f86ddce72a08fd62bb1af4338c7096ce947e"}, - {file = "types_tabulate-0.9.0.20240106-py3-none-any.whl", hash = "sha256:0378b7b6fe0ccb4986299496d027a6d4c218298ecad67199bbd0e2d7e9d335a1"}, -] - [[package]] name = "typing-extensions" version = "4.12.2" @@ -2135,4 +2110,4 @@ cffi = ["cffi (>=1.11)"] [metadata] lock-version = "2.0" python-versions = ">=3.11,<3.13" -content-hash = "5bfb99555575baa993a00e4d837942eb4e29471c7c076f5ea999a0d95b76feea" +content-hash = "7738c050272755107486cc28ac635f5a977bf7d7b0024b12bbba387ddbd8a2a1" diff --git a/pyproject.toml b/pyproject.toml index fab016431..80cb94375 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,6 @@ aiosqlite = ">=0.18" argcomplete = ">=2,<4" zstandard = ">=0.19" python-can = "^4.2" -tabulate = ">=0.9" construct = "^2.10" msgspec = ">=0.11,<0.19" pydantic = "^2.0" @@ -58,7 +57,6 @@ pytest-asyncio = ">=0.20,<0.25" python-lsp-server = "^1.5" types-aiofiles = ">=23.1,<25.0" types-psutil = ">=5.9.5.10,<7.0.0.0" -types-tabulate = "^0.9" myst-parser = ">=3.0.1,<4.1" sphinx-rtd-theme = ">=1,<3" reuse = "^4.0" diff --git a/src/gallia/commands/primitive/uds/dtc.py b/src/gallia/commands/primitive/uds/dtc.py index 91df3ad64..a48ab68c9 100644 --- a/src/gallia/commands/primitive/uds/dtc.py +++ b/src/gallia/commands/primitive/uds/dtc.py @@ -6,8 +6,6 @@ from argparse import Namespace from functools import partial -from tabulate import tabulate - from gallia.command import UDSScanner from gallia.log import get_logger from gallia.services.uds.core.constants import ( @@ -17,7 +15,7 @@ ) from gallia.services.uds.core.service import NegativeResponse from gallia.services.uds.core.utils import g_repr -from gallia.utils import auto_int +from gallia.utils import auto_int, format_table logger = get_logger(__name__) @@ -167,10 +165,10 @@ def show_bit_legend(self) -> None: "7 = warningIndicatorRequested: existing warning indicators (e.g. lamp, display)", ] - for line in ( - tabulate([[d] for d in bit_descriptions], headers=["bit descriptions"]) - ).splitlines(): - logger.result(line) + logger.result("bit descriptions") + logger.result("----------------") + for bit in bit_descriptions: + logger.result(bit) def show_summary(self, dtcs: list[list[str]]) -> None: dtcs.sort() @@ -188,7 +186,7 @@ def show_summary(self, dtcs: list[list[str]]) -> None: "7", ] - for line in tabulate(dtcs, headers=header, tablefmt="fancy_grid").splitlines(): + for line in format_table([header + dtcs]).splitlines(): logger.result(line) async def clear(self, args: Namespace) -> None: diff --git a/src/gallia/utils.py b/src/gallia/utils.py index dc0310955..058d09f66 100644 --- a/src/gallia/utils.py +++ b/src/gallia/utils.py @@ -85,6 +85,15 @@ def camel_to_dash(s: str) -> str: return camel_to_snake(s).replace("_", "-") +def format_table(data: list[list[Any]]) -> str: + out = "" + for row in data: + row_format ="{:>15}" * (len(row) + 1) + row_format += "\n" + out += row_format.format(*row) + return out + + def isotp_addr_repr(a: int) -> str: """ Default string representation of a CAN id.