]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Adapt find_library() call to find libpq.dll on Windows
authorDaniel Fortunov <github@danielfortunov.com>
Sun, 19 Jul 2020 23:19:21 +0000 (00:19 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 24 Nov 2020 21:28:00 +0000 (21:28 +0000)
psycopg3/psycopg3/pq/__init__.py
psycopg3/psycopg3/pq/_pq_ctypes.py
tests/fix_pq.py

index 940d23adcb47c418a18e612b5eecb5925ed45175..1d53c2c48da200360e00a93498a4dcb83ee7277e 100644 (file)
@@ -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.
index 88947ca14dce42366249a2f1ce24c6ee462b1d70..4f1cac3b245a1f9b29124fa6ee68875aedeae7e4 100644 (file)
@@ -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")
 
index 551032bffcdf67de9a9cf06396d9965eef5b3f80..bb5a66ff9e0e48f4e821fcb9292a581e85118c9d 100644 (file)
@@ -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: