mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
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:
@@ -26,7 +26,6 @@ KEYWORDS = 'etcd governor patroni postgresql postgres ha haproxy confd' +\
|
||||
EXTRAS_REQUIRE = {'aws': ['boto3'], 'etcd': ['python-etcd'], 'etcd3': ['python-etcd'],
|
||||
'consul': ['python-consul'], 'exhibitor': ['kazoo'], 'zookeeper': ['kazoo'],
|
||||
'kubernetes': [], 'raft': ['pysyncobj', 'cryptography']}
|
||||
COVERAGE_XML = True
|
||||
|
||||
# Add here all kinds of additional classifiers as defined under
|
||||
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
|
||||
@@ -120,14 +119,21 @@ def read(fname):
|
||||
return fd.read()
|
||||
|
||||
|
||||
def setup_package(version):
|
||||
def get_versions():
|
||||
old_modules = sys.modules.copy()
|
||||
try:
|
||||
from patroni import MIN_PSYCOPG2, MIN_PSYCOPG3
|
||||
from patroni.version import __version__
|
||||
return __version__, MIN_PSYCOPG2, MIN_PSYCOPG3
|
||||
finally:
|
||||
sys.modules.clear()
|
||||
sys.modules.update(old_modules)
|
||||
|
||||
|
||||
def main():
|
||||
logging.basicConfig(format='%(message)s', level=os.getenv('LOGLEVEL', logging.WARNING))
|
||||
|
||||
# Assemble additional setup commands
|
||||
cmdclass = {'test': PyTest, 'flake8': Flake8}
|
||||
|
||||
install_requires = []
|
||||
|
||||
for r in read('requirements.txt').split('\n'):
|
||||
r = r.strip()
|
||||
if r == '':
|
||||
@@ -139,15 +145,22 @@ def setup_package(version):
|
||||
deps[i] = r
|
||||
EXTRAS_REQUIRE[e] = deps
|
||||
extra = True
|
||||
break
|
||||
if extra:
|
||||
break
|
||||
if not extra:
|
||||
install_requires.append(r)
|
||||
|
||||
# Just for convenience, if someone wants to install dependencies for all extras
|
||||
EXTRAS_REQUIRE['all'] = list({e for extras in EXTRAS_REQUIRE.values() for e in extras})
|
||||
|
||||
patroni_version, min_psycopg2, min_psycopg3 = get_versions()
|
||||
|
||||
# Make it possible to specify psycopg dependency as extra
|
||||
for name, version in {'psycopg[binary]': min_psycopg3, 'psycopg2': min_psycopg2, 'psycopg2-binary': None}.items():
|
||||
EXTRAS_REQUIRE[name] = [name + ('>=' + '.'.join(map(str, version)) if version else '')]
|
||||
EXTRAS_REQUIRE['psycopg3'] = EXTRAS_REQUIRE.pop('psycopg[binary]')
|
||||
|
||||
setup(
|
||||
name=NAME,
|
||||
version=version,
|
||||
version=patroni_version,
|
||||
url=URL,
|
||||
author=AUTHOR,
|
||||
author_email=AUTHOR_EMAIL,
|
||||
@@ -163,20 +176,10 @@ def setup_package(version):
|
||||
]},
|
||||
install_requires=install_requires,
|
||||
extras_require=EXTRAS_REQUIRE,
|
||||
cmdclass=cmdclass,
|
||||
cmdclass={'test': PyTest, 'flake8': Flake8},
|
||||
entry_points={'console_scripts': CONSOLE_SCRIPTS},
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
old_modules = sys.modules.copy()
|
||||
try:
|
||||
from patroni import check_psycopg
|
||||
from patroni.version import __version__
|
||||
finally:
|
||||
sys.modules.clear()
|
||||
sys.modules.update(old_modules)
|
||||
|
||||
check_psycopg()
|
||||
|
||||
setup_package(__version__)
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user