Skip to content

Commit 19f75b4

Browse files
authored
Compatibility with prettytable>=3.12.0 (patroni#3217)
They started showing deprecation warning when importing ALL and FRAME constants.
1 parent 3f00b7a commit 19f75b4

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

patroni/ctl.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@
3838
import urllib3
3939
import yaml
4040

41-
from prettytable import ALL, FRAME, PrettyTable
41+
from prettytable import PrettyTable
42+
43+
try: # pragma: no cover
44+
from prettytable import HRuleStyle
45+
hrule_all = HRuleStyle.ALL
46+
hrule_frame = HRuleStyle.FRAME
47+
except ImportError: # pragma: no cover
48+
from prettytable import ALL as hrule_all, FRAME as hrule_frame
4249

4350
if TYPE_CHECKING: # pragma: no cover
4451
from psycopg import Cursor
@@ -437,7 +444,7 @@ def print_output(columns: Optional[List[str]], rows: List[List[Any]], alignment:
437444
else:
438445
# If any value is multi-line, then add horizontal between all table rows while printing to get a clear
439446
# visual separation of rows.
440-
hrules = ALL if any(any(isinstance(c, str) and '\n' in c for c in r) for r in rows) else FRAME
447+
hrules = hrule_all if any(any(isinstance(c, str) and '\n' in c for c in r) for r in rows) else hrule_frame
441448
table = PatronictlPrettyTable(header, columns, hrules=hrules)
442449
table.align = 'l'
443450
for k, v in (alignment or {}).items():

tests/test_ctl.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
import etcd
1010

1111
from click.testing import CliRunner
12-
from prettytable import ALL, PrettyTable
12+
from prettytable import PrettyTable
13+
14+
try:
15+
from prettytable import HRuleStyle
16+
hrule_all = HRuleStyle.ALL
17+
except ImportError:
18+
from prettytable import ALL as hrule_all
19+
1320
from urllib3 import PoolManager
1421

1522
from patroni import global_config
@@ -747,7 +754,7 @@ def test_reinit_wait(self):
747754
class TestPatronictlPrettyTable(unittest.TestCase):
748755

749756
def setUp(self):
750-
self.pt = PatronictlPrettyTable(' header', ['foo', 'bar'], hrules=ALL)
757+
self.pt = PatronictlPrettyTable(' header', ['foo', 'bar'], hrules=hrule_all)
751758

752759
def test__get_hline(self):
753760
expected = '+-----+-----+'

typings/prettytable/__init__.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
from enum import IntEnum
12
from typing import Any, Dict, List
2-
FRAME = 1
3-
ALL = 1
3+
class HRuleStyle(IntEnum):
4+
FRAME = 0
5+
ALL = 1
6+
FRAME = HRuleStyle.FRAME
7+
ALL = HRuleStyle.ALL
48
class PrettyTable:
59
def __init__(self, *args: str, **kwargs: Any) -> None: ...
610
def _stringify_hrule(self, options: Dict[str, Any], where: str = '') -> str: ...

0 commit comments

Comments
 (0)