From 5f9f8e41da82b02362d59e7d9a676ae9a193c525 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:39:45 +0200 Subject: [PATCH 1/2] Replace deprecated constants with enums --- pyproject.toml | 2 +- requirements.txt | 2 +- src/norwegianblue/__init__.py | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9d6cb88..1048f58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ dynamic = [ "version" ] dependencies = [ "httpx>=0.19", "platformdirs", - "prettytable>=2.4", + "prettytable>=3.12", "pytablewriter[html]>=0.63", "python-dateutil", "python-slugify", diff --git a/requirements.txt b/requirements.txt index 3b34750..6ede68d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ freezegun==1.5.1 httpx==0.27.2 platformdirs==4.3.6 -prettytable==3.11.0 +prettytable==3.12.0 pytablewriter[html]==1.2.0 pytest==8.3.3 pytest-cov==5.0.0 diff --git a/src/norwegianblue/__init__.py b/src/norwegianblue/__init__.py index 6c6badc..bcdb3ea 100644 --- a/src/norwegianblue/__init__.py +++ b/src/norwegianblue/__init__.py @@ -227,10 +227,12 @@ def _prettytable( color: str = "yes", title: str | None = None, ) -> str: - from prettytable import MARKDOWN, SINGLE_BORDER, PrettyTable + from prettytable import PrettyTable, TableStyle x = PrettyTable() - x.set_style(MARKDOWN if format_ == "markdown" else SINGLE_BORDER) + x.set_style( + TableStyle.MARKDOWN if format_ == "markdown" else TableStyle.SINGLE_BORDER + ) do_color = color != "no" and format_ == "pretty" for header in headers: From d6cc0d28770fe4435a6121dddb6d0891a764a07e Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:40:31 +0200 Subject: [PATCH 2/2] Rename 'x' variable to 'table' --- src/norwegianblue/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/norwegianblue/__init__.py b/src/norwegianblue/__init__.py index bcdb3ea..d2d07a4 100644 --- a/src/norwegianblue/__init__.py +++ b/src/norwegianblue/__init__.py @@ -229,8 +229,8 @@ def _prettytable( ) -> str: from prettytable import PrettyTable, TableStyle - x = PrettyTable() - x.set_style( + table = PrettyTable() + table.set_style( TableStyle.MARKDOWN if format_ == "markdown" else TableStyle.SINGLE_BORDER ) do_color = color != "no" and format_ == "pretty" @@ -239,19 +239,19 @@ def _prettytable( left_align = header in ("cycle", "latest", "link") display_header = colored(header, attrs=["bold"]) if do_color else header col_data = [row[header] if header in row else "" for row in data] - x.add_column(display_header, col_data) + table.add_column(display_header, col_data) if left_align: - x.align[display_header] = "l" + table.align[display_header] = "l" title_prefix = "" if title: if format_ == "pretty": - x.title = colored(title, attrs=["bold"]) if do_color else title + table.title = colored(title, attrs=["bold"]) if do_color else title else: title_prefix = f"## {title}\n\n" - return title_prefix + x.get_string() + return title_prefix + table.get_string() def _pytablewriter(