Compatibility with prettytable>=3.12.0 (#3217)

They started showing deprecation warning when importing ALL and FRAME constants.
This commit is contained in:
Alexander Kukushkin
2024-11-19 09:09:09 +01:00
committed by GitHub
parent 3f00b7a6c7
commit 19f75b407e
3 changed files with 24 additions and 6 deletions

View File

@@ -38,7 +38,14 @@ import dateutil.tz
import urllib3
import yaml
from prettytable import ALL, FRAME, PrettyTable
from prettytable import PrettyTable
try: # pragma: no cover
from prettytable import HRuleStyle
hrule_all = HRuleStyle.ALL
hrule_frame = HRuleStyle.FRAME
except ImportError: # pragma: no cover
from prettytable import ALL as hrule_all, FRAME as hrule_frame
if TYPE_CHECKING: # pragma: no cover
from psycopg import Cursor
@@ -437,7 +444,7 @@ def print_output(columns: Optional[List[str]], rows: List[List[Any]], alignment:
else:
# If any value is multi-line, then add horizontal between all table rows while printing to get a clear
# visual separation of rows.
hrules = ALL if any(any(isinstance(c, str) and '\n' in c for c in r) for r in rows) else FRAME
hrules = hrule_all if any(any(isinstance(c, str) and '\n' in c for c in r) for r in rows) else hrule_frame
table = PatronictlPrettyTable(header, columns, hrules=hrules)
table.align = 'l'
for k, v in (alignment or {}).items():

View File

@@ -9,7 +9,14 @@ import click
import etcd
from click.testing import CliRunner
from prettytable import ALL, PrettyTable
from prettytable import PrettyTable
try:
from prettytable import HRuleStyle
hrule_all = HRuleStyle.ALL
except ImportError:
from prettytable import ALL as hrule_all
from urllib3 import PoolManager
from patroni import global_config
@@ -747,7 +754,7 @@ class TestCtl(unittest.TestCase):
class TestPatronictlPrettyTable(unittest.TestCase):
def setUp(self):
self.pt = PatronictlPrettyTable(' header', ['foo', 'bar'], hrules=ALL)
self.pt = PatronictlPrettyTable(' header', ['foo', 'bar'], hrules=hrule_all)
def test__get_hline(self):
expected = '+-----+-----+'

View File

@@ -1,6 +1,10 @@
from enum import IntEnum
from typing import Any, Dict, List
FRAME = 1
ALL = 1
class HRuleStyle(IntEnum):
FRAME = 0
ALL = 1
FRAME = HRuleStyle.FRAME
ALL = HRuleStyle.ALL
class PrettyTable:
def __init__(self, *args: str, **kwargs: Any) -> None: ...
def _stringify_hrule(self, options: Dict[str, Any], where: str = '') -> str: ...