import os
import logging
-from typing import Callable, List, Type
+from typing import Callable, List, Optional, Type
from . import abc
from .misc import ConninfoOption, PGnotify, PGresAttDesc
Possible values include ``python``, ``c``, ``binary``.
"""
+__build_version__: Optional[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``.
+
+Certain features might not be available if the built version is too old.
+"""
+
version: Callable[[], int]
PGconn: Type[abc.PGconn]
PGresult: Type[abc.PGresult]
try to import the best implementation available.
"""
# import these names into the module on success as side effect
- global __impl__, version, PGconn, PGresult, Conninfo, Escaping, PGcancel
+ global __impl__, version, __build_version__
+ global PGconn, PGresult, Conninfo, Escaping, PGcancel
impl = os.environ.get("PSYCOPG_IMPL", "").lower()
module = None
Conninfo = module.Conninfo
Escaping = module.Escaping
PGcancel = module.PGcancel
+ __build_version__ = getattr(module, "__build_version__", None)
elif impl:
raise ImportError(f"requested psycopg impementation '{impl}' unknown")
else:
rv = pq.version()
assert rv > 90500
assert rv < 200000 # you are good for a while
+
+
+def test_build_version():
+ if pq.__impl__ == "python":
+ assert pq.__build_version__ is None
+ elif pq.__impl__ in ["c", "binary"]:
+ assert pq.__build_version__ >= 70400
+ else:
+ assert False, f"unexpected libpq implementation: {pq.__impl__}"