changeset 51164f435179 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=51164f435179
description:
        Drop support for PyPy and psycopg2cffi

        issue11330
        review386371003
diffstat:

 CHANGELOG                              |   1 +
 setup.py                               |   8 +-------
 tox.ini                                |   5 ++---
 trytond/backend/postgresql/database.py |  29 +++++++----------------------
 4 files changed, 11 insertions(+), 32 deletions(-)

diffs (114 lines):

diff -r 729c8b90ada1 -r 51164f435179 CHANGELOG
--- a/CHANGELOG Sun Apr 10 17:24:15 2022 +0200
+++ b/CHANGELOG Sun Apr 10 19:10:14 2022 +0200
@@ -1,3 +1,4 @@
+* Drop support for PyPy and psycopg2cffi
 * Use a set for field's depends
 * Relax the constraint on a field's depends
 * Include only needed fields when fetching a view definition
diff -r 729c8b90ada1 -r 51164f435179 setup.py
--- a/setup.py  Sun Apr 10 17:24:15 2022 +0200
+++ b/setup.py  Sun Apr 10 19:10:14 2022 +0200
@@ -5,7 +5,6 @@
 import glob
 import io
 import os
-import platform
 import re
 import subprocess
 
@@ -73,10 +72,6 @@
         'https://trydevpi.tryton.org/?local_version='
         + '.'.join(local_version))
 
-if platform.python_implementation() == 'PyPy':
-    pg_require = ['psycopg2cffi > 2.9.0']
-else:
-    pg_require = ['psycopg2 >= 2.7.0']
 tests_require = ['pillow']
 
 setup(name=name,
@@ -150,7 +145,6 @@
         'Programming Language :: Python :: 3.9',
         'Programming Language :: Python :: 3.10',
         'Programming Language :: Python :: Implementation :: CPython',
-        'Programming Language :: Python :: Implementation :: PyPy',
         'Topic :: Software Development :: Libraries :: Application Frameworks',
         ],
     platforms='any',
@@ -169,7 +163,7 @@
         'passlib >= 1.7.0',
         ],
     extras_require={
-        'PostgreSQL': pg_require,
+        'PostgreSQL': ['psycopg2 >= 2.7.0'],
         'graphviz': ['pydot'],
         'Levenshtein': ['python-Levenshtein'],
         'BCrypt': ['passlib[bcrypt]'],
diff -r 729c8b90ada1 -r 51164f435179 tox.ini
--- a/tox.ini   Sun Apr 10 17:24:15 2022 +0200
+++ b/tox.ini   Sun Apr 10 19:10:14 2022 +0200
@@ -1,5 +1,5 @@
 [tox]
-envlist = {py37,py38,py39,py310}-{sqlite,postgresql},pypy3-{sqlite,postgresql}
+envlist = {py37,py38,py39,py310}-{sqlite,postgresql}
 
 [testenv]
 commands =
@@ -7,8 +7,7 @@
     coverage report --include=./trytond/* --omit=*/tests/*
 deps =
     coverage
-    {py37,py38,py39,py310}-postgresql: psycopg2 >= 2.5
-    pypy3-postgresql: psycopg2cffi >= 2.5
+    postgresql: psycopg2 >= 2.7.0
 setenv =
     sqlite: TRYTOND_DATABASE_URI={env:SQLITE_URI:sqlite://}
     postgresql: TRYTOND_DATABASE_URI={env:POSTGRESQL_URI:postgresql://}
diff -r 729c8b90ada1 -r 51164f435179 trytond/backend/postgresql/database.py
--- a/trytond/backend/postgresql/database.py    Sun Apr 10 17:24:15 2022 +0200
+++ b/trytond/backend/postgresql/database.py    Sun Apr 10 19:10:14 2022 +0200
@@ -11,16 +11,10 @@
 from itertools import chain, repeat
 from threading import RLock
 
-try:
-    from psycopg2 import connect
-except ImportError:
-    from psycopg2cffi import compat
-    compat.register()
-    from psycopg2 import connect
-from psycopg2 import Binary
+from psycopg2 import Binary, connect
 from psycopg2.extensions import (
-    ISOLATION_LEVEL_AUTOCOMMIT, ISOLATION_LEVEL_REPEATABLE_READ, UNICODE, AsIs,
-    cursor, register_adapter, register_type)
+    ISOLATION_LEVEL_REPEATABLE_READ, UNICODE, AsIs, cursor, register_adapter,
+    register_type)
 from psycopg2.pool import PoolError, ThreadedConnectionPool
 from psycopg2.sql import SQL, Identifier
 
@@ -272,19 +266,10 @@
                 logger.error(
                     'connection to "%s" failed', self.name, exc_info=True)
                 raise
-        # We do not use set_session because psycopg2 < 2.7 and psycopg2cffi
-        # change the default_transaction_* attributes which breaks external
-        # pooling at the transaction level.
-        if autocommit:
-            conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
-        else:
-            conn.set_isolation_level(ISOLATION_LEVEL_REPEATABLE_READ)
-        # psycopg2cffi does not have the readonly property
-        if hasattr(conn, 'readonly'):
-            conn.readonly = readonly
-        elif not autocommit and readonly:
-            cursor = conn.cursor()
-            cursor.execute('SET TRANSACTION READ ONLY')
+        conn.set_session(
+            isolation_level=ISOLATION_LEVEL_REPEATABLE_READ,
+            readonly=readonly,
+            autocommit=autocommit)
         return conn
 
     def put_connection(self, connection, close=False):

Reply via email to