diff --git a/pgtoolkit/ctl.py b/pgtoolkit/ctl.py index 3198bb7..810669b 100644 --- a/pgtoolkit/ctl.py +++ b/pgtoolkit/ctl.py @@ -151,7 +151,6 @@ class Status(enum.IntEnum): class AbstractPGCtl(abc.ABC): bindir: Path - version: int @cached_property def pg_ctl(self) -> Path: @@ -161,9 +160,6 @@ def pg_ctl(self) -> Path: raise OSError("pg_ctl executable not found") return value - def version_cmd(self) -> list[str]: - return [str(self.pg_ctl), "--version"] - def init_cmd(self, datadir: Path | str, **opts: str | Literal[True]) -> list[str]: cmd = [str(self.pg_ctl), "init"] + ["-D", str(datadir)] options = _args_to_opts(opts) @@ -270,10 +266,6 @@ def __init__( ).stdout.strip() self.bindir = Path(bindir) self.run_command = run_command - version = run_command( - self.version_cmd(), check=True, capture_output=True - ).stdout.strip() - self.version = num_version(version) def init( self, datadir: Path | str, **opts: str | Literal[True] @@ -434,10 +426,6 @@ async def get( ).stdout.strip() bindir = Path(bindir) self = cls(bindir, run_command) - version = ( - await run_command(self.version_cmd(), check=True, capture_output=True) - ).stdout.strip() - self.version = num_version(version) return self async def init( @@ -513,67 +501,3 @@ def parse_control_data(lines: Sequence[str]) -> dict[str, str]: if m: controldata[m.group(1).strip()] = m.group(2).strip() return controldata - - -def num_version(text_version: str) -> int: - """Return PostgreSQL numeric version as defined by LibPQ PQserverVersion - - >>> num_version('pg_ctl (PostgreSQL) 9.6.3') - 90603 - >>> num_version('pg_ctl (PostgreSQL) 9.2.0') - 90200 - >>> num_version('pg_ctl (PostgreSQL) 11.10') - 110010 - >>> num_version('pg_ctl (PostgreSQL) 11.1') - 110001 - >>> num_version("pg_ctl (PostgreSQL) 14devel") - 140000 - >>> num_version("pg_ctl (PostgreSQL) 9.6devel") - 90600 - >>> num_version("pg_ctl (PostgreSQL) 9.6rc1") - 90600 - """ - res = re.match( - r"pg_ctl \(\w+\) ([0-9]+)\.([0-9]+)(?:\.([0-9]+))?", - text_version, - ) - if res is not None: - rmatch = res.group(1) - if int(res.group(1)) < 10: - rmatch += res.group(2).rjust(2, "0") - if res.group(3) is not None: - rmatch += res.group(3).rjust(2, "0") - else: - return num_dev_version(text_version) - else: - rmatch += res.group(2).rjust(4, "0") - pg_num_version = int(rmatch) - return pg_num_version - return num_dev_version(text_version) - - -def num_dev_version(text_version: str) -> int: - """Return PostgreSQL numeric version as defined by LibPQ PQserverVersion - - >>> num_dev_version("pg_ctl (PostgreSQL) 14devel") - 140000 - >>> num_dev_version("pg_ctl (PostgreSQL) 13beta1") - 130000 - >>> num_dev_version("pg_ctl (PostgreSQL) 13rc1") - 130000 - >>> num_dev_version("pg_ctl (PostgreSQL) 9.6devel") - 90600 - """ - res = re.match( - r"pg_ctl \(\w+\) ([0-9]+)(?:\.([0-9]+))?(devel|beta[0-9]+|rc[0-9]+)", - text_version, - ) - if not res: - raise Exception(f"Undefined PostgreSQL version: {text_version}") - rmatch = res.group(1) - if res.group(2) is not None: - rmatch += res.group(2).rjust(2, "0") + "00" - else: - rmatch += "0000" - pg_num_version = int(rmatch) - return pg_num_version diff --git a/tests/test_ctl.py b/tests/test_ctl.py index c687e10..19534a4 100644 --- a/tests/test_ctl.py +++ b/tests/test_ctl.py @@ -66,10 +66,6 @@ def pgctl(bindir: Path) -> ctl.PGCtl: return c -def test_version(pgctl: ctl.AsyncPGCtl) -> None: - assert pgctl.version == 110010 - - def test_init_cmd(pgctl: ctl.PGCtl) -> None: assert pgctl.init_cmd( "data", @@ -170,11 +166,6 @@ async def run_command(args: Sequence[str], **kwargs: Any) -> ctl.CompletedProces return c -@pytest.mark.asyncio -async def test_version_async(apgctl: ctl.AsyncPGCtl) -> None: - assert apgctl.version == 110010 - - @pytest.mark.parametrize( "rc, status", [ diff --git a/tests/test_ctl_func.py b/tests/test_ctl_func.py index 5520461..b23c673 100644 --- a/tests/test_ctl_func.py +++ b/tests/test_ctl_func.py @@ -103,8 +103,6 @@ def tmp_port() -> int: def test_start_stop_status_restart_reload( initdb: tuple[Path, Path, Path], pgctl: ctl.PGCtl, tmp_port: int ) -> None: - from psycopg2 import connect - datadir, __, pidpath = initdb assert pgctl.status("invalid") == ctl.Status.unspecified_datadir assert pgctl.status(str(datadir)) == ctl.Status.not_running @@ -113,9 +111,6 @@ def test_start_stop_status_restart_reload( assert pidpath.exists() pid1 = pidpath.read_text() - connection = connect(dbname="postgres", host="0.0.0.0", port=tmp_port) - assert connection.info.server_version == pgctl.version - assert pgctl.status(str(datadir)) == ctl.Status.running pgctl.restart(str(datadir), mode="immediate", wait=2) pid2 = pidpath.read_text() @@ -134,8 +129,6 @@ def test_start_stop_status_restart_reload( async def test_start_stop_status_restart_reload_async( ainitdb: tuple[Path, Path, Path], apgctl: ctl.AsyncPGCtl, tmp_port: int ) -> None: - from psycopg2 import connect - datadir, __, pidpath = ainitdb assert (await apgctl.status("invalid")) == ctl.Status.unspecified_datadir assert (await apgctl.status(str(datadir))) == ctl.Status.not_running @@ -144,9 +137,6 @@ async def test_start_stop_status_restart_reload_async( assert pidpath.exists() pid1 = pidpath.read_text() - connection = connect(dbname="postgres", host="0.0.0.0", port=tmp_port) - assert connection.info.server_version == apgctl.version - assert (await apgctl.status(str(datadir))) == ctl.Status.running await apgctl.restart(str(datadir), mode="immediate", wait=2) pid2 = pidpath.read_text()