Merge pull request #189937 from mweinelt/psycopg-3.1.1

This commit is contained in:
Martin Weinelt 2022-09-06 15:45:26 +02:00 committed by GitHub
commit 840dc5aba2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 25 deletions

View file

@ -0,0 +1,46 @@
diff --git a/psycopg/psycopg/pq/_pq_ctypes.py b/psycopg/psycopg/pq/_pq_ctypes.py
index 4f9d00fb..24b90ef6 100644
--- a/psycopg/psycopg/pq/_pq_ctypes.py
+++ b/psycopg/psycopg/pq/_pq_ctypes.py
@@ -11,14 +11,10 @@ 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, Optional, Tuple
-from .misc import find_libpq_full_path
from ..errors import NotSupportedError
-libname = find_libpq_full_path()
-if not libname:
- raise ImportError("libpq library not found")
-pq = ctypes.cdll.LoadLibrary(libname)
+pq = ctypes.cdll.LoadLibrary("@libpq@")
class FILE(Structure):
@@ -28,9 +24,7 @@ class FILE(Structure):
FILE_ptr = POINTER(FILE)
if sys.platform == "linux":
- libcname = ctypes.util.find_library("c")
- assert libcname
- libc = ctypes.cdll.LoadLibrary(libcname)
+ libc = ctypes.cdll.LoadLibrary("@libc@")
fdopen = libc.fdopen
fdopen.argtypes = (c_int, c_char_p)
diff --git a/tests/fix_pq.py b/tests/fix_pq.py
index 6811a26c..c1829c82 100644
--- a/tests/fix_pq.py
+++ b/tests/fix_pq.py
@@ -51,9 +51,7 @@ def libpq():
from psycopg.pq.misc import find_libpq_full_path
# Not available when testing the binary package
- libname = find_libpq_full_path()
- assert libname, "libpq libname not found"
- return ctypes.pydll.LoadLibrary(libname)
+ return ctypes.pydll.LoadLibrary("@libpq@")
except Exception as e:
if pq.__impl__ == "binary":
pytest.skip(f"can't load libpq for testing: {e}")

View file

@ -32,19 +32,20 @@
let
pname = "psycopg";
version = "3.1";
version = "3.1.1";
src = fetchFromGitHub {
owner = "psycopg";
repo = pname;
rev = "refs/tags/${version}";
hash = "sha256-N0Qc8pSWN2NFZn06lYZ7DKMbk6H8aIByS+wDnOQ/O+Y=";
hash = "sha256-PrWHjs8PLmx7bgKtyhXaiSKmz9oT2OhXDkKd4xi7e0A=";
};
patches = [
(substituteAll {
src = ./libpq.patch;
src = ./ctypes.patch;
libpq = "${postgresql.lib}/lib/libpq${stdenv.hostPlatform.extensions.sharedLibrary}";
libc = "${stdenv.cc.libc}/lib/libc.so.6";
})
];

View file

@ -1,22 +0,0 @@
diff --git a/psycopg/psycopg/pq/_pq_ctypes.py b/psycopg/psycopg/pq/_pq_ctypes.py
index bf04d560..9e79fc3f 100644
--- a/psycopg/psycopg/pq/_pq_ctypes.py
+++ b/psycopg/psycopg/pq/_pq_ctypes.py
@@ -13,16 +13,7 @@ from typing import List, Optional, Tuple
from ..errors import NotSupportedError
-if sys.platform == "win32":
- libname = ctypes.util.find_library("libpq.dll")
-elif sys.platform == "darwin":
- libname = ctypes.util.find_library("libpq.dylib")
-else:
- libname = ctypes.util.find_library("pq")
-if not libname:
- raise ImportError("libpq library not found")
-
-pq = ctypes.cdll.LoadLibrary(libname)
+pq = ctypes.cdll.LoadLibrary("@libpq@")
# Get the libpq version to define what functions are available.