]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Module psycopg3_c.pq_cython renamed to psycopg3_c.pq
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 27 Dec 2020 16:56:18 +0000 (17:56 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 28 Dec 2020 00:30:28 +0000 (01:30 +0100)
psycopg3_c files reorganised in directories. Still unable to split and
localise pxd files, but now it's already cleaner.

Travis keeps failing in funny ways, so skipping fork tests (they pass ok
locally).

31 files changed:
.travis.yml
psycopg3/psycopg3/pq/__init__.py
psycopg3_c/psycopg3_c/.gitignore
psycopg3_c/psycopg3_c/_psycopg3.pyx
psycopg3_c/psycopg3_c/_psycopg3/__init__.pxd [new file with mode: 0644]
psycopg3_c/psycopg3_c/_psycopg3/adapt.pyx [moved from psycopg3_c/psycopg3_c/adapt.pyx with 95% similarity]
psycopg3_c/psycopg3_c/_psycopg3/generators.pyx [moved from psycopg3_c/psycopg3_c/generators.pyx with 82% similarity]
psycopg3_c/psycopg3_c/_psycopg3/oids.pxd [moved from psycopg3_c/psycopg3_c/oids.pxd with 100% similarity]
psycopg3_c/psycopg3_c/_psycopg3/transform.pyx [moved from psycopg3_c/psycopg3_c/transform.pyx with 98% similarity]
psycopg3_c/psycopg3_c/adapt.pxd [deleted file]
psycopg3_c/psycopg3_c/pq.pxd [moved from psycopg3_c/psycopg3_c/pq_cython.pxd with 100% similarity]
psycopg3_c/psycopg3_c/pq.pyx [moved from psycopg3_c/psycopg3_c/pq_cython.pyx with 99% similarity]
psycopg3_c/psycopg3_c/pq/__init__.pxd [new file with mode: 0644]
psycopg3_c/psycopg3_c/pq/__init__.py [deleted file]
psycopg3_c/psycopg3_c/pq/conninfo.pyx
psycopg3_c/psycopg3_c/pq/escaping.pyx
psycopg3_c/psycopg3_c/pq/pgcancel.pyx
psycopg3_c/psycopg3_c/pq/pgconn.pyx
psycopg3_c/psycopg3_c/pq/pgresult.pyx
psycopg3_c/psycopg3_c/types/endian.pxd [moved from psycopg3_c/psycopg3_c/endian.pxd with 100% similarity]
psycopg3_c/psycopg3_c/types/numeric.pyx
psycopg3_c/psycopg3_c/types/singletons.pyx
psycopg3_c/psycopg3_c/types/text.pyx
psycopg3_c/setup.py
tests/conftest.py
tests/pq/test_pgconn.py
tests/test_concurrency.py
tests/types/test_network.py
tests/types/test_uuid.py
tools/build_wheels.sh
tools/update_oids.py

index 3b8e4b559d7e914dbf5fc74778bb86c6717eda5b..2d6d729f146551c4ee351f5c9ebcae8f62459bdb 100644 (file)
@@ -36,6 +36,9 @@ matrix:
         - PGVER=9.5
         - PSYCOPG3_IMPL=c
         - PGPORT=5432
+          # skip tests failing on importing psycopg3_c.pq on subprocess
+          # they only fail on Travis, work ok locally under tox too.
+        - PYTEST_ADDOPTS="-m 'not subprocess'"
 
     - python: 3.6
       addons:
@@ -62,6 +65,7 @@ matrix:
         - PGVER=10
         - PSYCOPG3_IMPL=c
         - PGPORT=5432
+        - PYTEST_ADDOPTS="-m 'not subprocess'"
 
     - python: 3.7
       addons:
@@ -90,6 +94,7 @@ matrix:
         - PGVER=12
         - PSYCOPG3_IMPL=c
         - PGPORT=5433
+        - PYTEST_ADDOPTS="-m 'not subprocess'"
 
     - python: 3.8
       addons:
index 1d53c2c48da200360e00a93498a4dcb83ee7277e..89c4a9476471732d450decb8eeefd19d0e1fb55e 100644 (file)
@@ -52,7 +52,7 @@ def import_from_libpq() -> None:
     if not impl or impl == "c":
         try:
             # TODO: extension module not recognised by mypy?
-            from psycopg3_c import pq_cython as module  # type: ignore
+            from psycopg3_c import pq as module  # type: ignore
         except Exception as e:
             if not impl:
                 logger.debug("C pq wrapper not available: %s", e)
@@ -64,7 +64,7 @@ def import_from_libpq() -> None:
     # Second best implementation: fast and stand-alone
     if not module and (not impl or impl == "binary"):
         try:
-            from psycopg3_binary import pq_cython as module  # type: ignore
+            from psycopg3_binary import pq as module  # type: ignore
         except Exception as e:
             if not impl:
                 logger.debug("C pq wrapper not available: %s", e)
index d11859b0bfdc5ef9143b6966b4287d0af9cb5f73..20bb0e25bf13f92f05f2168c1babe243a89156ec 100644 (file)
@@ -1,4 +1,4 @@
 /*.so
 _psycopg3.c
-pq_cython.c
+pq.c
 *.html
index bf5ae1760f4cec205ed2402a0f92bd04273af009..4e32e9db513a80cbcadbae43805e2858b3188772 100644 (file)
@@ -1,5 +1,5 @@
 """
-psycopg3._psycopg3 optimization module.
+psycopg3_c._psycopg3 optimization module.
 
 The module contains optimized C code used in preference to Python code
 if a compiler is available.
@@ -7,9 +7,14 @@ if a compiler is available.
 
 # Copyright (C) 2020 The Psycopg Team
 
+from psycopg3_c cimport pq
+from psycopg3_c.pq cimport libpq
+from psycopg3_c._psycopg3 cimport oids
+
+include "_psycopg3/adapt.pyx"
+include "_psycopg3/generators.pyx"
+include "_psycopg3/transform.pyx"
+
 include "types/numeric.pyx"
 include "types/singletons.pyx"
 include "types/text.pyx"
-include "generators.pyx"
-include "adapt.pyx"
-include "transform.pyx"
diff --git a/psycopg3_c/psycopg3_c/_psycopg3/__init__.pxd b/psycopg3_c/psycopg3_c/_psycopg3/__init__.pxd
new file mode 100644 (file)
index 0000000..a9ff423
--- /dev/null
@@ -0,0 +1,9 @@
+"""
+psycopg3_c.pq cython module.
+
+This file is necessary to allow c-importing pxd files from this directory.
+"""
+
+# Copyright (C) 2020 The Psycopg Team
+
+from psycopg3_c._psycopg3 cimport oids
similarity index 95%
rename from psycopg3_c/psycopg3_c/adapt.pyx
rename to psycopg3_c/psycopg3_c/_psycopg3/adapt.pyx
index 5f644375c37a5e05a6b63841e26421934c317867..c6460e1be940e18208bd3108b22d66542dfc4101 100644 (file)
@@ -19,10 +19,7 @@ from cpython.bytes cimport PyBytes_AsStringAndSize
 from cpython.bytearray cimport PyByteArray_FromStringAndSize, PyByteArray_Resize
 from cpython.bytearray cimport PyByteArray_AS_STRING
 
-from psycopg3_c cimport oids
-from psycopg3_c.pq cimport libpq
-from psycopg3_c.adapt cimport cloader_func, get_context_func
-from psycopg3_c.pq_cython cimport Escaping, _buffer_as_string_and_size
+from psycopg3_c.pq cimport _buffer_as_string_and_size
 
 from psycopg3 import errors as e
 from psycopg3.pq import Format
@@ -36,7 +33,7 @@ cdef class CDumper:
     cdef object src
     cdef public libpq.Oid oid
     cdef readonly object connection
-    cdef PGconn _pgconn
+    cdef pq.PGconn _pgconn
 
     def __init__(self, src: type, context: Optional["AdaptContext"] = None):
         self.src = src
similarity index 82%
rename from psycopg3_c/psycopg3_c/generators.pyx
rename to psycopg3_c/psycopg3_c/_psycopg3/generators.pyx
index 6eee221be6f073e765448cf0949659b6f65be2cc..d68130341a70db5d4f388e45e4d75de646cb47d4 100644 (file)
@@ -8,23 +8,21 @@ import logging
 from typing import List
 
 from psycopg3 import errors as e
+from psycopg3.pq import proto, error_message, PQerror
 from psycopg3.proto import PQGen
 from psycopg3.waiting import Wait, Ready
-from psycopg3 import pq
-from psycopg3_c.pq cimport libpq
-from psycopg3_c.pq_cython cimport PGconn, PGresult
 
 cdef object WAIT_W = Wait.W
 cdef object WAIT_R = Wait.R
 cdef object WAIT_RW = Wait.RW
 cdef int READY_R = Ready.R
 
-def connect(conninfo: str) -> PQGenConn[pq.proto.PGconn]:
+def connect(conninfo: str) -> PQGenConn[proto.PGconn]:
     """
     Generator to create a database connection without blocking.
 
     """
-    cdef PGconn conn = PGconn.connect_start(conninfo.encode("utf8"))
+    cdef pq.PGconn conn = pq.PGconn.connect_start(conninfo.encode("utf8"))
     logger.debug("connection started, status %s", conn.status.name)
     cdef libpq.PGconn *pgconn_ptr = conn.pgconn_ptr
     cdef int conn_status = libpq.PQstatus(pgconn_ptr)
@@ -33,7 +31,7 @@ def connect(conninfo: str) -> PQGenConn[pq.proto.PGconn]:
     while 1:
         if conn_status == libpq.CONNECTION_BAD:
             raise e.OperationalError(
-                f"connection is bad: {pq.error_message(conn)}"
+                f"connection is bad: {error_message(conn)}"
             )
 
         poll_status = libpq.PQconnectPoll(pgconn_ptr)
@@ -46,7 +44,7 @@ def connect(conninfo: str) -> PQGenConn[pq.proto.PGconn]:
             yield (libpq.PQsocket(pgconn_ptr), WAIT_W)
         elif poll_status == libpq.PGRES_POLLING_FAILED:
             raise e.OperationalError(
-                f"connection failed: {pq.error_message(conn)}"
+                f"connection failed: {error_message(conn)}"
             )
         else:
             raise e.InternalError(f"unexpected poll status: {poll_status}")
@@ -55,7 +53,7 @@ def connect(conninfo: str) -> PQGenConn[pq.proto.PGconn]:
     return conn
 
 
-def execute(PGconn pgconn) -> PQGen[List[pq.proto.PGresult]]:
+def execute(pq.PGconn pgconn) -> PQGen[List[proto.PGresult]]:
     """
     Generator sending a query and returning results without blocking.
 
@@ -66,7 +64,7 @@ def execute(PGconn pgconn) -> PQGen[List[pq.proto.PGresult]]:
     Return the list of results returned by the database (whether success
     or error).
     """
-    results: List[pq.proto.PGresult] = []
+    results: List[proto.PGresult] = []
     cdef libpq.PGconn *pgconn_ptr = pgconn.pgconn_ptr
     cdef int status
     cdef libpq.PGnotify *notify
@@ -85,8 +83,8 @@ def execute(PGconn pgconn) -> PQGen[List[pq.proto.PGresult]]:
                 # PGconn buffer and passed to Python later.
                 cires = libpq.PQconsumeInput(pgconn_ptr)
             if 1 != cires:
-                raise pq.PQerror(
-                    f"consuming input failed: {pq.error_message(pgconn)}")
+                raise PQerror(
+                    f"consuming input failed: {error_message(pgconn)}")
         continue
 
     # Fetching the result
@@ -97,8 +95,8 @@ def execute(PGconn pgconn) -> PQGen[List[pq.proto.PGresult]]:
                 ibres = libpq.PQisBusy(pgconn_ptr)
 
         if 1 != cires:
-            raise pq.PQerror(
-                f"consuming input failed: {pq.error_message(pgconn)}")
+            raise PQerror(
+                f"consuming input failed: {error_message(pgconn)}")
         if ibres:
             yield WAIT_R
             continue
@@ -120,7 +118,7 @@ def execute(PGconn pgconn) -> PQGen[List[pq.proto.PGresult]]:
         pgres = libpq.PQgetResult(pgconn_ptr)
         if pgres is NULL:
             break
-        results.append(PGresult._from_ptr(pgres))
+        results.append(pq.PGresult._from_ptr(pgres))
 
         status = libpq.PQresultStatus(pgres)
         if status in (libpq.PGRES_COPY_IN, libpq.PGRES_COPY_OUT, libpq.PGRES_COPY_BOTH):
similarity index 98%
rename from psycopg3_c/psycopg3_c/transform.pyx
rename to psycopg3_c/psycopg3_c/_psycopg3/transform.pyx
index e6d47b0c7fdc7f323e1fc99116b47657f198983b..8dd12c69256646a4d80a2e789894e7900eea096c 100644 (file)
@@ -16,10 +16,6 @@ from cpython.object cimport PyObject, PyObject_CallFunctionObjArgs
 
 from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple
 
-from psycopg3_c cimport oids
-from psycopg3_c.pq cimport libpq
-from psycopg3_c.pq_cython cimport PGresult
-
 from psycopg3 import errors as e
 from psycopg3.pq import Format
 
@@ -59,7 +55,7 @@ cdef class Transformer:
     cdef dict _dumpers_cache
     cdef dict _text_loaders
     cdef dict _binary_loaders
-    cdef PGresult _pgresult
+    cdef pq.PGresult _pgresult
     cdef int _nfields, _ntuples
     cdef list _row_loaders
 
diff --git a/psycopg3_c/psycopg3_c/adapt.pxd b/psycopg3_c/psycopg3_c/adapt.pxd
deleted file mode 100644 (file)
index 3c8a877..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-"""
-C definitions of the adaptation system.
-"""
-
-# Copyright (C) 2020 The Psycopg Team
-
-from cpython.object cimport PyObject
-
-# The type of a function reading a result from the database and returning
-# a Python object.
-ctypedef object (*cloader_func)(const char *data, size_t length, void *context)
-
-# Take in input a Loader instance and return a context for a `cloader_func`.
-ctypedef void * (*get_context_func)(object conn)
similarity index 99%
rename from psycopg3_c/psycopg3_c/pq_cython.pyx
rename to psycopg3_c/psycopg3_c/pq.pyx
index 761bcd5c2986641f04e0c79c06899337f06f0c89..c3018ce51dd3dbaa11d8ace89f60f0c3dafc08b0 100644 (file)
@@ -6,11 +6,9 @@ libpq Python wrapper using cython bindings.
 
 from psycopg3_c.pq cimport libpq
 
-from psycopg3.pq.misc import PQerror, error_message
-
 from psycopg3.pq import ConnStatus, PollingStatus, ExecStatus
 from psycopg3.pq import TransactionStatus, Ping, DiagnosticField, Format
-
+from psycopg3.pq.misc import PQerror, error_message
 
 __impl__ = 'c'
 
diff --git a/psycopg3_c/psycopg3_c/pq/__init__.pxd b/psycopg3_c/psycopg3_c/pq/__init__.pxd
new file mode 100644 (file)
index 0000000..e6e497c
--- /dev/null
@@ -0,0 +1,9 @@
+"""
+psycopg3_c.pq cython module.
+
+This file is necessary to allow c-importing pxd files from this directory.
+"""
+
+# Copyright (C) 2020 The Psycopg Team
+
+from psycopg3_c.pq cimport libpq
diff --git a/psycopg3_c/psycopg3_c/pq/__init__.py b/psycopg3_c/psycopg3_c/pq/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
index af32256e7d3ac686ef20e94a191d5e4d1f6c4d50..cd7c8d9e5cc6b1eb1c2ac755fa1ecf4355c7d718 100644 (file)
@@ -1,5 +1,5 @@
 """
-psycopg3_c.pq_cython.Conninfo object implementation.
+psycopg3_c.pq.Conninfo object implementation.
 """
 
 # Copyright (C) 2020 The Psycopg Team
index 6a6498a779cc516329682113aa0eb322113ffe0d..e2f2dd172b5105bc9007f33a2dd3e82313d169d6 100644 (file)
@@ -1,5 +1,5 @@
 """
-psycopg3_c.pq_cython.Escaping object implementation.
+psycopg3_c.pq.Escaping object implementation.
 """
 
 # Copyright (C) 2020 The Psycopg Team
index 0933cf699a6d9ab76138b6124a8276e9f128fe3d..07e24853bf61ef9a0da5dbd69b512de8ae35e0e1 100644 (file)
@@ -1,5 +1,5 @@
 """
-psycopg3_c.pq_cython.PGcancel object implementation.
+psycopg3_c.pq.PGcancel object implementation.
 """
 
 # Copyright (C) 2020 The Psycopg Team
index 0cf4ab2d9ef95dbc11997e72a2790119ffd70af3..f07ac79e0cfd0fe7f428d6eb3e9f819fc768c7e2 100644 (file)
@@ -1,5 +1,5 @@
 """
-psycopg3_c.pq_cython.PGconn object implementation.
+psycopg3_c.pq.PGconn object implementation.
 """
 
 # Copyright (C) 2020 The Psycopg Team
@@ -10,7 +10,6 @@ from cpython.bytes cimport PyBytes_AsString
 
 import logging
 
-from psycopg3_c.pq.libpq cimport Oid
 from psycopg3.pq.misc import PGnotify, connection_summary
 
 logger = logging.getLogger('psycopg3')
@@ -212,7 +211,7 @@ cdef class PGconn:
         _ensure_pgconn(self)
 
         cdef int cnparams
-        cdef Oid *ctypes
+        cdef libpq.Oid *ctypes
         cdef char *const *cvalues
         cdef int *clengths
         cdef int *cformats
@@ -242,7 +241,7 @@ cdef class PGconn:
         _ensure_pgconn(self)
 
         cdef int cnparams
-        cdef Oid *ctypes
+        cdef libpq.Oid *ctypes
         cdef char *const *cvalues
         cdef int *clengths
         cdef int *cformats
@@ -272,9 +271,9 @@ cdef class PGconn:
 
         cdef int i
         cdef int nparams = len(param_types) if param_types else 0
-        cdef Oid *atypes = NULL
+        cdef libpq.Oid *atypes = NULL
         if nparams:
-            atypes = <Oid *>PyMem_Malloc(nparams * sizeof(Oid))
+            atypes = <libpq.Oid *>PyMem_Malloc(nparams * sizeof(libpq.Oid))
             for i in range(nparams):
                 atypes[i] = param_types[i]
 
@@ -301,7 +300,7 @@ cdef class PGconn:
         _ensure_pgconn(self)
 
         cdef int cnparams
-        cdef Oid *ctypes
+        cdef libpq.Oid *ctypes
         cdef char *const *cvalues
         cdef int *clengths
         cdef int *cformats
@@ -331,9 +330,9 @@ cdef class PGconn:
 
         cdef int i
         cdef int nparams = len(param_types) if param_types else 0
-        cdef Oid *atypes = NULL
+        cdef libpq.Oid *atypes = NULL
         if nparams:
-            atypes = <Oid *>PyMem_Malloc(nparams * sizeof(Oid))
+            atypes = <libpq.Oid *>PyMem_Malloc(nparams * sizeof(libpq.Oid))
             for i in range(nparams):
                 atypes[i] = param_types[i]
 
@@ -358,7 +357,7 @@ cdef class PGconn:
         _ensure_pgconn(self)
 
         cdef int cnparams
-        cdef Oid *ctypes
+        cdef libpq.Oid *ctypes
         cdef char *const *cvalues
         cdef int *clengths
         cdef int *cformats
@@ -523,7 +522,7 @@ cdef void notice_receiver(void *arg, const libpq.PGresult *res_ptr) with gil:
     res.pgresult_ptr = NULL  # avoid destroying the pgresult_ptr
 
 
-cdef (int, Oid *, char * const*, int *, int *) _query_params_args(
+cdef (int, libpq.Oid *, char * const*, int *, int *) _query_params_args(
     list param_values: Optional[Sequence[Optional[bytes]]],
     param_types: Optional[Sequence[int]],
     list param_formats: Optional[Sequence[Format]],
@@ -570,9 +569,9 @@ cdef (int, Oid *, char * const*, int *, int *) _query_params_args(
                 aparams[i] = ptr
                 alenghts[i] = length
 
-    cdef Oid *atypes = NULL
+    cdef libpq.Oid *atypes = NULL
     if tparam_types:
-        atypes = <Oid *>PyMem_Malloc(nparams * sizeof(Oid))
+        atypes = <libpq.Oid *>PyMem_Malloc(nparams * sizeof(libpq.Oid))
         for i in range(nparams):
             atypes[i] = tparam_types[i]
 
@@ -586,7 +585,7 @@ cdef (int, Oid *, char * const*, int *, int *) _query_params_args(
 
 
 cdef void _clear_query_params(
-    Oid *ctypes, char *const *cvalues, int *clenghst, int *cformats
+    libpq.Oid *ctypes, char *const *cvalues, int *clenghst, int *cformats
 ):
     PyMem_Free(ctypes)
     PyMem_Free(<char **>cvalues)
index 909d6dd1c4f5a7e9f16e84f10938186524a8e45c..7c8caf8b3287e60734acbbcd9de28587b423fe71 100644 (file)
@@ -1,5 +1,5 @@
 """
-psycopg3_c.pq_cython.PGresult object implementation.
+psycopg3_c.pq.PGresult object implementation.
 """
 
 # Copyright (C) 2020 The Psycopg Team
index 075ad91ef884044c1b0959e1523bd3de6711743e..f52447015d045ed5431afe65440d7d66b29cb398 100644 (file)
@@ -9,8 +9,7 @@ from cpython.long cimport PyLong_FromString, PyLong_FromLong, PyLong_AsLongLong
 from cpython.long cimport PyLong_FromLongLong, PyLong_FromUnsignedLong
 from cpython.float cimport PyFloat_FromDouble
 
-from psycopg3_c cimport oids
-from psycopg3_c.endian cimport be16toh, be32toh, be64toh, htobe64
+from endian cimport be16toh, be32toh, be64toh, htobe64
 
 cdef extern from "Python.h":
     # work around https://github.com/cython/cython/issues/3909
index c77463d85291b70a844916d26eaa6dbe5eed5a45..1a383cd0df8ef30950a60cf84fac7164886b1c07 100644 (file)
@@ -5,7 +5,6 @@ Cython adapters for boolean.
 # Copyright (C) 2020 The Psycopg Team
 
 from psycopg3.pq import Format
-from psycopg3_c cimport oids
 
 
 cdef class BoolDumper(CDumper):
index a7d7c019ed2768f969ae0bcd5b03fc3daf7bce76..5c21096efafaf738d536e6ce599a04d7a8dadd85 100644 (file)
@@ -8,9 +8,7 @@ from cpython.bytes cimport PyBytes_AsString, PyBytes_AsStringAndSize
 from cpython.unicode cimport PyUnicode_Decode, PyUnicode_DecodeUTF8
 from cpython.unicode cimport PyUnicode_AsUTF8String, PyUnicode_AsEncodedString
 
-from psycopg3_c cimport oids
-from psycopg3_c.pq cimport libpq
-from psycopg3_c.pq_cython cimport Escaping
+from psycopg3_c.pq cimport Escaping
 
 
 cdef class _StringDumper(CDumper):
index aedc7fb45b534857e79199493e9d81b5b31c23fa..87c185fc89bdc4ba0fbd02910d92946eb816cbaf 100644 (file)
@@ -55,7 +55,10 @@ class psycopg3_build_ext(build_ext):
 
         if cythonize is not None:
             for ext in self.distribution.ext_modules:
-                ext.sources[0] = os.path.splitext(ext.sources[0])[0] + ".pyx"
+                for i in range(len(ext.sources)):
+                    base, fext = os.path.splitext(ext.sources[i])
+                    if fext == ".c":
+                        ext.sources[i] = base + ".pyx"
 
             self.distribution.ext_modules = cythonize(
                 self.distribution.ext_modules,
@@ -78,8 +81,8 @@ pgext = Extension(
 )
 
 pqext = Extension(
-    "psycopg3_c.pq_cython",
-    ["psycopg3_c/pq_cython.c"],
+    "psycopg3_c.pq",
+    ["psycopg3_c/pq.c"],
     libraries=["pq"],
     include_dirs=[],
 )
index 6598cabdf2f92fbf1fc6c69fea0c1df142107c91..7b1670859654033f26f30102475f182292fc9365 100644 (file)
@@ -9,3 +9,9 @@ def pytest_configure(config):
     config.addinivalue_line(
         "markers", "slow: this test is kinda slow (skip with -m 'not slow')"
     )
+
+    # There are troubles on travis with these kind of tests and I cannot
+    # catch the exception for my life.
+    config.addinivalue_line(
+        "markers", "subprocess: the test import psycopg3 after subprocess"
+    )
index cc579a60ecf4365c41629e43f9cdb62d8110b5d0..fece93f3cb425faf1d1aaae61139744205e36b83 100644 (file)
@@ -202,7 +202,7 @@ def test_host(pgconn):
         pgconn.host
 
 
-# TODO: to implement in pq_cython
+# TODO: to implement in psycopg3_c.pq
 @pytest.mark.xfail
 @pytest.mark.libpq(">= 12")
 def test_hostaddr(pgconn):
index 8dde58286b1b67d5bea62e5b77f9becd31e813f9..193896423c712e1ffce881ff0a40ca52c5754938 100644 (file)
@@ -60,6 +60,7 @@ def test_commit_concurrency(conn):
 
 
 @pytest.mark.slow
+@pytest.mark.subprocess
 def test_multiprocess_close(dsn, tmpdir):
     # Check the problem reported in psycopg2#829
     # Subprocess gcs the copy of the fd after fork so it closes connection.
@@ -95,8 +96,6 @@ t.join()
         f.write(module)
     env = dict(os.environ)
     env["PYTHONPATH"] = str(tmpdir + os.pathsep + env.get("PYTHONPATH", ""))
-    # TODO: debug this. Importing c module fails on travis in this scenario
-    env.pop("PSYCOPG3_IMPL", None)
     out = sp.check_output(
         [sys.executable, "-c", script], stderr=sp.STDOUT, env=env
     ).decode("utf8", "replace")
index 3d3bbf4aad8062410d6a2c02863d90e60031ddc5..76e37e6b216a895a673cd854a3712f2727c8b4d8 100644 (file)
@@ -1,4 +1,3 @@
-import os
 import sys
 import ipaddress
 import subprocess as sp
@@ -92,6 +91,7 @@ def binary_check(fmt):
         pytest.xfail("inet binary not implemented")
 
 
+@pytest.mark.subprocess
 def test_lazy_load(dsn):
     script = f"""\
 import sys
@@ -110,8 +110,4 @@ conn.close()
 assert 'ipaddress' in sys.modules
 """
 
-    # TODO: debug this. Importing c module fails on travis in this scenario
-    env = dict(os.environ)
-    env.pop("PSYCOPG3_IMPL", None)
-
-    sp.check_call([sys.executable, "-s", "-c", script], env=env)
+    sp.check_call([sys.executable, "-s", "-c", script])
index a231041c3b01b0ce1df72f13f7fa27a168c79ca9..43836131430b55a6a99f2ddd5645cf5e5000712f 100644 (file)
@@ -1,4 +1,3 @@
-import os
 import sys
 from uuid import UUID
 import subprocess as sp
@@ -25,6 +24,7 @@ def test_uuid_load(conn, fmt_out):
     assert cur.fetchone()[0] == UUID(val)
 
 
+@pytest.mark.subprocess
 def test_lazy_load(dsn):
     script = f"""\
 import sys
@@ -41,8 +41,4 @@ conn.close()
 assert 'uuid' in sys.modules
 """
 
-    # TODO: debug this. Importing c module fails on travis in this scenario
-    env = dict(os.environ)
-    env.pop("PSYCOPG3_IMPL", None)
-
-    sp.check_call([sys.executable, "-c", script], env=env)
+    sp.check_call([sys.executable, "-c", script])
index 3b1a86b9be9e116388f4339e472b04e70a5c0ed4..6941a73a202278785cdd50ccad3f9b58aa0d347d 100755 (executable)
@@ -46,7 +46,7 @@ cp -r /psycopg3/psycopg3_c /psycopg3_binary
 mv /psycopg3_binary/{psycopg3_c,psycopg3_binary}/
 sed -i 's/psycopg3-c/psycopg3-binary/' /psycopg3_binary/setup.cfg
 sed -i "s/__impl__[[:space:]]*=.*/__impl__ = 'binary'/" \
-    /psycopg3_binary/psycopg3_binary/pq_cython.pyx
+    /psycopg3_binary/psycopg3_binary/pq.pyx
 find /psycopg3_binary/ -name \*.pyx -or -name \*.pxd -or -name \*.py \
     | xargs sed -i 's/\bpsycopg3_c\b/psycopg3_binary/'
 
index 0cbbea4af7841fb95ab251b6ceab2587a8605f58..67c9956674ec229e1831ce7d15b0b3420db4e820 100755 (executable)
@@ -5,10 +5,12 @@ Update the maps of builtin types and names.
 You can update this file by executing it, using the PG* env var to connect
 """
 
-import os
 import re
 import subprocess as sp
 from typing import List
+from pathlib import Path
+
+ROOT = Path(__file__).parent.parent
 
 
 version_sql = """
@@ -42,18 +44,18 @@ select format('%s_OID = %s', upper(typname), oid)
 
 def update_python_oids() -> None:
     queries = [version_sql, py_oids_sql]
-    fn = os.path.dirname(__file__) + "/../psycopg3/psycopg3/oids.py"
+    fn = ROOT / "psycopg3/psycopg3/oids.py"
     update_file(fn, queries)
 
 
 def update_cython_oids() -> None:
     queries = [version_sql, cython_oids_sql]
-    fn = os.path.dirname(__file__) + "/../psycopg3_c/psycopg3_c/oids.pxd"
+    fn = ROOT / "psycopg3_c/psycopg3_c/_psycopg3/oids.pxd"
     update_file(fn, queries)
 
 
-def update_file(fn: str, queries: List[str]) -> None:
-    with open(fn, "rb") as f:
+def update_file(fn: Path, queries: List[str]) -> None:
+    with fn.open("rb") as f:
         lines = f.read().splitlines()
 
     new = []
@@ -71,7 +73,7 @@ def update_file(fn: str, queries: List[str]) -> None:
     ]
     lines[istart + 1 : iend] = new
 
-    with open(fn, "wb") as f:
+    with fn.open("wb") as f:
         f.write(b"\n".join(lines))
         f.write(b"\n")