Allow to specify psycopg* in extras and switch to build (#2907)

* remove check_psycopg() call from the setup.py, when installing from wheel it doesn't work anyway.
* call check_psycopg() function before process_arguments(), because the last one is trying to import psycopg and fails with the stacktrace, while the first one shows a nice human-readable error message.
* add psycopg2, psycopg2-binary, and psycopg3 extras, that will install psycopg2>=2.5.4, psycopg2-binary, or psycopg[binary]>=3.0.0 modules respectively.
* move check_psycopg() function to the __main__.py.
* introduce the new extra called `all`, it will allow to install all dependencies at once (except psycopg related).
* use the `build` module in order to create sdist bdist_wheel packages.
* update the documentation regarding psycopg and extras (dependencies).
This commit is contained in:
Alexander Kukushkin
2023-10-17 14:46:15 +02:00
committed by GitHub
parent 60d8bc3a70
commit fc67ba73f0
7 changed files with 112 additions and 119 deletions
+11 -4
View File
@@ -15,8 +15,7 @@ from patroni.dcs.etcd import AbstractEtcdClientWithFailover
from patroni.exceptions import DCSError
from patroni.postgresql import Postgresql
from patroni.postgresql.config import ConfigHandler
from patroni import check_psycopg
from patroni.__main__ import Patroni, main as _main
from patroni.__main__ import check_psycopg, Patroni, main as _main
from threading import Thread
from . import psycopg_connect, SleepException
@@ -25,10 +24,16 @@ from .test_postgresql import MockPostmaster
def mock_import(*args, **kwargs):
if args[0] == 'psycopg':
ret = Mock()
ret.__version__ = '2.5.3.dev1 a b c' if args[0] == 'psycopg2' else '3.1.0'
return ret
def mock_import2(*args, **kwargs):
if args[0] == 'psycopg2':
raise ImportError
ret = Mock()
ret.__version__ = '2.5.3.dev1 a b c'
ret.__version__ = '0.1.2'
return ret
@@ -205,6 +210,8 @@ class TestPatroni(unittest.TestCase):
with patch('builtins.__import__', Mock(side_effect=ImportError)):
self.assertRaises(SystemExit, check_psycopg)
with patch('builtins.__import__', mock_import):
self.assertIsNone(check_psycopg())
with patch('builtins.__import__', mock_import2):
self.assertRaises(SystemExit, check_psycopg)
def test_ensure_unique_name(self):