psycopg.git / summary / log / commit / refs
commit e847fda09c5f73a201dbdd9b7b69daeeae3b2cd5
Author: Daniele Varrazzo <daniele.varrazzo@gmail.com>
Date: Mon Aug 15 11:41:01 2022 +0000
feat: use version() as __build_version__ for pq python implementation
Having __build_version__ to be null makes version checking needlessly
convoluted and version() has to be used anyway as fallback.
psycopg/psycopg/_pipeline.py | 3 ++-
psycopg/psycopg/pq/__init__.py | 8 ++++----
psycopg/psycopg/pq/pq_ctypes.py | 2 ++
tests/fix_pq.py | 2 +-
tests/pq/test_pq.py | 7 +------
5 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/psycopg/psycopg/_pipeline.py b/psycopg/psycopg/_pipeline.py
index e1593d1b..ac7d25ef 100644
--- a/psycopg/psycopg/_pipeline.py
+++ b/psycopg/psycopg/_pipeline.py
@@ -63,7 +63,8 @@ class BasePipeline:
# Support only depends on the libpq functions available in the pq
# wrapper, not on the database version.
pq_version = pq.__build_version__ or pq.version()
- BasePipeline._is_supported = pq_version >= 140000
+ # Pipeline support broken in libpq 14.5 (#350)
+ BasePipeline._is_supported = pq_version >= 140000 and pq_version != 140005
return BasePipeline._is_supported
def _enter_gen(self) -> PQGen[None]:
diff --git a/psycopg/psycopg/pq/__init__.py b/psycopg/psycopg/pq/__init__.py
index 3cf58cef..d5180b1b 100644
--- a/psycopg/psycopg/pq/__init__.py
+++ b/psycopg/psycopg/pq/__init__.py
@@ -11,7 +11,7 @@ implementation-dependant but all the implementations share the same interface.
import os
import logging
-from typing import Callable, List, Optional, Type
+from typing import Callable, List, Type
from . import abc
from .misc import ConninfoOption, PGnotify, PGresAttDesc
@@ -27,12 +27,12 @@ __impl__: str
Possible values include ``python``, ``c``, ``binary``.
"""
-__build_version__: Optional[int]
+__build_version__: int
"""The libpq version the C package was built with.
A number in the same format of `~psycopg.ConnectionInfo.server_version`
representing the libpq used to build the speedup module (``c``, ``binary``) if
-available. `!None` if `__impl__` is ``python``.
+available.
Certain features might not be available if the built version is too old.
"""
@@ -98,7 +98,7 @@ def import_from_libpq() -> None:
Conninfo = module.Conninfo
Escaping = module.Escaping
PGcancel = module.PGcancel
- __build_version__ = getattr(module, "__build_version__", None)
+ __build_version__ = module.__build_version__
elif impl:
raise ImportError(f"requested psycopg implementation '{impl}' unknown")
else:
diff --git a/psycopg/psycopg/pq/pq_ctypes.py b/psycopg/psycopg/pq/pq_ctypes.py
index ae3deed7..d0174adc 100644
--- a/psycopg/psycopg/pq/pq_ctypes.py
+++ b/psycopg/psycopg/pq/pq_ctypes.py
@@ -1047,3 +1047,5 @@ import ssl # noqa
# disable libcrypto setup in libpq, so it won't stomp on the callbacks
# that have already been set up
impl.PQinitOpenSSL(1, 0)
+
+__build_version__ = version()
diff --git a/tests/fix_pq.py b/tests/fix_pq.py
index af14c7d4..a17d2854 100644
--- a/tests/fix_pq.py
+++ b/tests/fix_pq.py
@@ -81,7 +81,7 @@ def setpgenv(monkeypatch):
@pytest.fixture
def trace(libpq):
- pqver = pq.__build_version__ or pq.version()
+ pqver = pq.__build_version__
if pqver < 140000:
pytest.skip(f"trace not available on libpq {pqver}")
if sys.platform != "linux":
diff --git a/tests/pq/test_pq.py b/tests/pq/test_pq.py
index d344d121..8cceace5 100644
--- a/tests/pq/test_pq.py
+++ b/tests/pq/test_pq.py
@@ -15,12 +15,7 @@ def test_version():
def test_build_version():
- if pq.__impl__ == "python":
- assert pq.__build_version__ is None
- elif pq.__impl__ in ["c", "binary"]:
- assert pq.__build_version__ and pq.__build_version__ >= 70400
- else:
- assert False, f"unexpected libpq implementation: {pq.__impl__}"
+ assert pq.__build_version__ and pq.__build_version__ >= 70400
@pytest.mark.skipif("not os.environ.get('PSYCOPG_TEST_WANT_LIBPQ_BUILD')")
[parent: 59a0221bea75]