From 39e7eeeadbb76c0fe25afbedb119f82212923a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 15 Mar 2015 15:52:03 +0100 Subject: [PATCH] Add support for psycopg2cffi and PyPy issue4408 review11741002 --- .drone.yml | 2 +- CHANGELOG | 2 ++ doc/topics/install.rst | 2 ++ setup.py | 10 +++++++++- tox.ini | 5 +++-- trytond/backend/postgresql/database.py | 26 +++++++++++++++++--------- trytond/modules/__init__.py | 2 ++ 7 files changed, 36 insertions(+), 13 deletions(-) diff --git a/.drone.yml b/.drone.yml index a4d2595986..9d7c769d8c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,6 +4,6 @@ env: - MYSQL_URI=mysql://root@127.0.0.1:3306/ script: - pip install tox - - tox -e sqlite,postgresql + - tox -e "py27-{sqlite,postgresql}" services: - postgres diff --git a/CHANGELOG b/CHANGELOG index c53e831cd7..bae9d6764a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Add support for PyPy +* Add support for psycopg2cffi * Add noeval on PYSONDecoder * Add __repr__ to PYSON * Remove safe_eval diff --git a/doc/topics/install.rst b/doc/topics/install.rst index c9f4f1e99d..889e36029e 100644 --- a/doc/topics/install.rst +++ b/doc/topics/install.rst @@ -15,6 +15,8 @@ Prerequisites * polib (https://bitbucket.org/izi/polib/wiki/Home) * python-sql 0.2 or later (http://code.google.com/p/python-sql/) * Optional: psycopg 2 or later (http://www.initd.org/) + * Optional: psycopg2cffi 2.5.0 or later + (http://github.com/chtd/psycopg2cffi) * Optional: MySQL-python (http://sourceforge.net/projects/mysql-python/) * Optional: pywebdav 0.9.8 or later (http://code.google.com/p/pywebdav/) * Optional: pydot (http://code.google.com/p/pydot/) diff --git a/setup.py b/setup.py index b0052c6778..95d55528e1 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ from setuptools import setup, find_packages import os +import platform PACKAGE, VERSION, LICENSE, WEBSITE = None, None, None, None execfile(os.path.join('trytond', 'version.py')) @@ -23,6 +24,11 @@ if minor_version % 2: download_url = 'hg+http://hg.tryton.org/%s#egg=%s-%s' % ( PACKAGE, PACKAGE, VERSION) +if platform.python_implementation() == 'PyPy': + pg_require = ['psycopg2cffi >= 2.5'] +else: + pg_require = ['psycopg2 >= 2.0'] + setup(name=PACKAGE, version=VERSION, description='Tryton server', @@ -65,6 +71,8 @@ setup(name=PACKAGE, 'Natural Language :: Spanish', 'Operating System :: OS Independent', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Software Development :: Libraries :: Application Frameworks', ], platforms='any', @@ -78,7 +86,7 @@ setup(name=PACKAGE, 'python-sql >= 0.4', ], extras_require={ - 'PostgreSQL': ['psycopg2 >= 2.0'], + 'PostgreSQL': pg_require, 'MySQL': ['MySQL-python'], 'WebDAV': ['PyWebDAV >= 0.9.8'], 'unoconv': ['unoconv'], diff --git a/tox.ini b/tox.ini index cf317a8871..f8e91e9937 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,12 @@ [tox] -envlist = py27-{sqlite,postgresql,mysql} +envlist = py27-{sqlite,postgresql,mysql},pypy-{sqlite,postgresql} [testenv] commands = {envpython} setup.py test deps = mock - postgresql: psycopg2 >= 2.0 + py27-postgresql: psycopg2 >= 2.0 + pypy-postgresql: psycopg2cffi >= 2.5 mysql: MySQL-python setenv = sqlite: TRYTOND_DATABASE_URI={env:SQLITE_URI:sqlite://} diff --git a/trytond/backend/postgresql/database.py b/trytond/backend/postgresql/database.py index b5fb1dd6d2..70f8382f2b 100644 --- a/trytond/backend/postgresql/database.py +++ b/trytond/backend/postgresql/database.py @@ -1,7 +1,18 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from trytond.backend.database import DatabaseInterface, CursorInterface -from trytond.config import config, parse_uri +import time +import logging +import re +import os +if os.name == 'posix': + import pwd +from decimal import Decimal + +try: + from psycopg2cffi import compat + compat.register() +except ImportError: + pass from psycopg2.pool import ThreadedConnectionPool from psycopg2.extensions import cursor as PsycopgCursor from psycopg2.extensions import ISOLATION_LEVEL_REPEATABLE_READ @@ -14,15 +25,12 @@ except ImportError: PYDATE, PYDATETIME, PYTIME, PYINTERVAL = None, None, None, None from psycopg2 import IntegrityError as DatabaseIntegrityError from psycopg2 import OperationalError as DatabaseOperationalError -import time -import logging -import re -import os -if os.name == 'posix': - import pwd -from decimal import Decimal + from sql import Flavor +from trytond.backend.database import DatabaseInterface, CursorInterface +from trytond.config import config, parse_uri + __all__ = ['Database', 'DatabaseIntegrityError', 'DatabaseOperationalError', 'Cursor'] diff --git a/trytond/modules/__init__.py b/trytond/modules/__init__.py index f58c5266c7..d196c9d6d1 100644 --- a/trytond/modules/__init__.py +++ b/trytond/modules/__init__.py @@ -296,6 +296,8 @@ def get_module_list(): for file in os.listdir(MODULES_PATH): if file.startswith('.'): continue + if file == '__pycache__': + continue if os.path.isdir(OPJ(MODULES_PATH, file)): module_list.add(file) update_egg_modules()