From: Daniel Fortunov Date: Sun, 19 Jul 2020 23:19:21 +0000 (+0100) Subject: Adapt find_library() call to find libpq.dll on Windows X-Git-Tag: 3.0.dev0~309 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=278b392a36b38d71083b0c4816f21f625fb65634;p=thirdparty%2Fpsycopg.git Adapt find_library() call to find libpq.dll on Windows --- diff --git a/psycopg3/psycopg3/pq/__init__.py b/psycopg3/psycopg3/pq/__init__.py index 940d23adc..1d53c2c48 100644 --- a/psycopg3/psycopg3/pq/__init__.py +++ b/psycopg3/psycopg3/pq/__init__.py @@ -37,7 +37,7 @@ PGcancel: Type[proto.PGcancel] def import_from_libpq() -> None: """ - Import pq objects implementation from the best libpw wrapper available. + Import pq objects implementation from the best libpq wrapper available. If an implementation is requested try to import only it, otherwise try to import the best implementation available. diff --git a/psycopg3/psycopg3/pq/_pq_ctypes.py b/psycopg3/psycopg3/pq/_pq_ctypes.py index 88947ca14..4f1cac3b2 100644 --- a/psycopg3/psycopg3/pq/_pq_ctypes.py +++ b/psycopg3/psycopg3/pq/_pq_ctypes.py @@ -6,13 +6,17 @@ libpq access using ctypes import ctypes import ctypes.util +import sys from ctypes import Structure, CFUNCTYPE, POINTER from ctypes import c_char, c_char_p, c_int, c_size_t, c_ubyte, c_uint, c_void_p from typing import List, Tuple from psycopg3.errors import NotSupportedError -libname = ctypes.util.find_library("pq") +if sys.platform == "win32": + libname = ctypes.util.find_library("libpq.dll") +else: + libname = ctypes.util.find_library("pq") if not libname: raise ImportError("libpq library not found") diff --git a/tests/fix_pq.py b/tests/fix_pq.py index 551032bff..bb5a66ff9 100644 --- a/tests/fix_pq.py +++ b/tests/fix_pq.py @@ -1,5 +1,7 @@ import re import operator +import sys + import pytest @@ -38,7 +40,10 @@ def libpq(): try: # Not available when testing the binary package - libname = ctypes.util.find_library("pq") + if sys.platform == "win32": + libname = ctypes.util.find_library("libpq.dll") + else: + libname = ctypes.util.find_library("pq") assert libname, "libpq libname not found" return ctypes.pydll.LoadLibrary(libname) except Exception as e: