Skip to content

Commit 6c073b2

Browse files
committed
meta: make psycopg optional
Workers don't need it, and neither do many coordinators.
1 parent 6d4e3a7 commit 6c073b2

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

setup.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@
2424
"humanize",
2525
# required to decompress repodata into tar
2626
"zstandard",
27-
"psycopg",
28-
"psycopg[c] ; platform_python_implementation == 'CPython'",
2927
],
28+
extras_require={
29+
"history": [
30+
"psycopg",
31+
"psycopg[c] ; platform_python_implementation == 'CPython'",
32+
]
33+
},
3034
include_package_data=True,
3135
entry_points={
3236
"console_scripts": [

xbbs/coordinator/__init__.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@
2626
import gevent.time
2727
import gevent.util
2828
import msgpack as msgpk
29-
import psycopg
3029
import toml
3130
import valideer as V
3231
import zmq.green as zmq
3332
from logbook import Logger, StderrHandler
3433

34+
try:
35+
from psycopg import Connection as PgConnection
36+
except ImportError:
37+
PgConnection = None
38+
3539
import xbbs.messages as msgs
3640
import xbbs.protocol
3741
import xbbs.util as xutils
@@ -161,7 +165,7 @@ class Xbbs:
161165
project_greenlets = attr.ib(factory=list)
162166
zmq = attr.ib(default=zmq.Context.instance())
163167
outgoing_job_queue = attr.ib(factory=lambda: gevent.queue.Queue(1))
164-
db: psycopg.Connection = attr.ib(default=None)
168+
db: PgConnection = attr.ib(default=None)
165169

166170
@classmethod
167171
def create(cls, cfg):
@@ -1172,8 +1176,14 @@ def main():
11721176

11731177
database_conn = contextlib.nullcontext(None)
11741178
if cfg.get("artifact_history"):
1175-
database_conn = psycopg.connect()
1176-
log.debug("established PG connection ({})", database_conn)
1179+
if PgConnection:
1180+
database_conn = PgConnection.connect()
1181+
log.debug("established PG connection ({})", database_conn)
1182+
else:
1183+
log.error(
1184+
"psycopg3 was not found. In order to use artifact_history, you will"
1185+
" need to install xbbs with the history extras group."
1186+
)
11771187

11781188
with database_conn as inst.db, \
11791189
inst.zmq.socket(zmq.REP) as sock_cmd, \

0 commit comments

Comments
 (0)