From 7d03afff100cea356fc273af221e2e7ac305bc3a Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 12 Nov 2018 11:26:59 +0100 Subject: [PATCH 1/5] Use psycopg2cffi for adbapi if running under PyPy --- synapse/server.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/synapse/server.py b/synapse/server.py index 9985687b95d9..0b2b64b7d51e 100644 --- a/synapse/server.py +++ b/synapse/server.py @@ -21,6 +21,7 @@ # Imports required for the default HomeServer() implementation import abc import logging +import platform from twisted.enterprise import adbapi from twisted.mail.smtp import sendmail @@ -367,6 +368,9 @@ def build_http_client(self): def build_db_pool(self): name = self.db_config["name"] + if (name == "psycopg2" and platform.python_implementation() == "PyPy"): + name = "psycopg2cffi" + return adbapi.ConnectionPool( name, cp_reactor=self.get_reactor(), From d37779e98f19996c139f595f4ba5173f8b32f2df Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 12 Nov 2018 11:28:52 +0100 Subject: [PATCH 2/5] add pypy3.5 to tox and travis test matrix Signed-off-by: Vincent Breitmoser --- .travis.yml | 8 ++++++++ tox.ini | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 655fab9d8e8e..77fac80b335a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,6 +57,14 @@ matrix: services: - postgresql + - python: "pypy3.5" + env: TOX_ENV=pypy + + - python: "pypy3.5" + env: TOX_ENV=pypy-postgres TRIAL_FLAGS="-j 4" + services: + - postgresql + - # we only need to check for the newsfragment if it's a PR build if: type = pull_request python: 3.6 diff --git a/tox.ini b/tox.ini index 03ddaeb0b71b..b3fc53ccb5cc 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = packaging, py27, py36, pep8, check_isort +envlist = packaging, py27, py36, pypy, pep8, check_isort [base] deps = @@ -110,6 +110,17 @@ setenv = {[base]setenv} SYNAPSE_POSTGRES = 1 +[testenv:pypy] +usedevelop=true + +[testenv:pypy-postgres] +usedevelop=true +deps = + {[base]deps} + psycopg2cffi +setenv = + {[base]setenv} + SYNAPSE_POSTGRES = 1 [testenv:packaging] deps = From 32fb21383bbab0455ccecf4162b07980f737a92e Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 12 Nov 2018 16:52:37 +0100 Subject: [PATCH 3/5] Use psycopg2cffi in place of psycopg2 in search.py for PyPy --- synapse/storage/search.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/synapse/storage/search.py b/synapse/storage/search.py index d5b5df93e6af..3c48fc110e75 100644 --- a/synapse/storage/search.py +++ b/synapse/storage/search.py @@ -186,7 +186,11 @@ def create_index(conn): # have an event_search_fts_idx; unfortunately postgres 9.4 # doesn't support CREATE INDEX IF EXISTS so we just catch the # exception and ignore it. - import psycopg2 + import platform + if platform.python_implementation() == "PyPy": + import psycopg2cffi as psycopg2 + else: + import psycopg2 try: c.execute( "CREATE INDEX CONCURRENTLY event_search_fts_idx" From 17bf8608c15bbb5703ed8be0eb372aca530a6964 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 13 Nov 2018 13:48:45 +0100 Subject: [PATCH 4/5] Use psycopg2cffi in place of psycopg2 in test/utils.py for PyPy --- tests/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/utils.py b/tests/utils.py index 67ab916f30a3..3fc0614bcbe1 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -252,7 +252,11 @@ def setup_test_homeserver( else: # We need to do cleanup on PostgreSQL def cleanup(): - import psycopg2 + import platform + if platform.python_implementation() == "PyPy": + import psycopg2cffi as psycopg2 + else: + import psycopg2 # Close all the db pools hs.get_db_pool().close() From 2528c16251daded34d032c3514965e4d7c23eaec Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 13 Nov 2018 14:49:41 +0100 Subject: [PATCH 5/5] add changelog file --- changelog.d/4174.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/4174.misc diff --git a/changelog.d/4174.misc b/changelog.d/4174.misc new file mode 100644 index 000000000000..d2cd79fc8bf7 --- /dev/null +++ b/changelog.d/4174.misc @@ -0,0 +1 @@ +Use psycopg2cffi consistently if running on PyPy