Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix PyPy compatibility in adbapi init #4174

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions changelog.d/4174.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use psycopg2cffi consistently if running on PyPy
4 changes: 4 additions & 0 deletions synapse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 5 additions & 1 deletion synapse/storage/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 12 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = packaging, py27, py36, pep8, check_isort
envlist = packaging, py27, py36, pypy, pep8, check_isort

[base]
deps =
Expand Down Expand Up @@ -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 =
Expand Down