From 9ddf537b9f2f487fe11454048a91ccf08f37ac02 Mon Sep 17 00:00:00 2001 From: Martin Hoyer Date: Wed, 21 Aug 2024 15:00:15 +0200 Subject: [PATCH 1/3] Use psycopg(3) for Python 3.13 compatibility --- python-nitrate.spec | 3 ++- setup.py | 2 +- source/containers.py | 6 +++--- source/teiid.py | 8 ++++---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/python-nitrate.spec b/python-nitrate.spec index 1b349f5..74708e6 100644 --- a/python-nitrate.spec +++ b/python-nitrate.spec @@ -78,9 +78,10 @@ Summary: %{summary} %{?python_provide:%python_provide python3-nitrate} %if %{with oldreqs} Requires: python%{python3_pkgversion}-gssapi -Requires: python%{python3_pkgversion}-psycopg2 +Requires: python%{python3_pkgversion}-psycopg3 Requires: python%{python3_pkgversion}-six %endif +Requires: libpq Conflicts: python2-nitrate < 1.5-3 %description -n python%{python3_pkgversion}-nitrate %_description diff --git a/setup.py b/setup.py index 2056f0a..b9d0c86 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ license='LGPLv2+', install_requires=[ 'gssapi', - 'psycopg2', + 'psycopg', 'six', ], url='https://psss.fedorapeople.org/python-nitrate/', diff --git a/source/containers.py b/source/containers.py index 93ab2b5..90202a1 100644 --- a/source/containers.py +++ b/source/containers.py @@ -58,7 +58,7 @@ """ import six -import psycopg2 +import psycopg from six.moves import xmlrpc_client as xmlrpclib @@ -842,7 +842,7 @@ def _fetch(self, inset=None): injects = self._teiid.run_cases(self.id) except teiid.TeiidNotConfigured: injects = self._server.TestRun.get_test_cases(self.id) - except psycopg2.DatabaseError as error: + except psycopg.DatabaseError as error: log.debug("Failed to fetch data from Teiid: {0}".format(error)) injects = self._server.TestRun.get_test_cases(self.id) self._current = set([TestCase(inject) for inject in injects]) @@ -915,7 +915,7 @@ def _fetch(self, inset=None): injects = self._teiid.run_case_runs(self.id) except teiid.TeiidNotConfigured: injects = self._server.TestRun.get_test_case_runs(self.id) - except psycopg2.DatabaseError as error: + except psycopg.DatabaseError as error: log.debug("Failed to fetch data from Teiid: {0}".format(error)) injects = self._server.TestRun.get_test_case_runs(self.id) # Feed the TestRun.testcases container with the initial object diff --git a/source/teiid.py b/source/teiid.py index a6046e5..9c6a826 100644 --- a/source/teiid.py +++ b/source/teiid.py @@ -22,7 +22,7 @@ Teiid support For enhanced query performance it's possible to use a Teiid instance. -Use the following config snippet to enable access via psycopg2 module: +Use the following config snippet to enable access via psycopg module: [teiid] user = username @@ -32,7 +32,7 @@ port = 5432 """ -import psycopg2 +import psycopg from nitrate.config import log, Config from nitrate.xmlrpc_driver import NitrateError @@ -74,9 +74,9 @@ def __init__(self): log.debug("Connecting as {0} to database {1} at {2}:{3}".format( user, database, host, port)) try: - self.connection = psycopg2.connect(database=database, + self.connection = psycopg.connect(database=database, user=user, password=password, host=host, port=port) - except psycopg2.DatabaseError as error: + except psycopg.DatabaseError as error: log.error("Teiid connect error: {0}".format(error)) raise TeiidError("Failed to connect to the Teiid instance") self.connection.set_isolation_level(0) From 5ca299ded683c42d00eb7f5489a2a0bb12662765 Mon Sep 17 00:00:00 2001 From: Martin Hoyer Date: Tue, 27 Aug 2024 16:24:58 +0200 Subject: [PATCH 2/3] Remove python2 support --- .gitignore | 3 ++ python-nitrate.spec | 79 +++------------------------------------- source/containers.py | 18 +++++---- source/teiid.py | 5 ++- test/test-bed-prepare.py | 1 - tests/config.fmf | 8 +--- tests/main.fmf | 4 -- 7 files changed, 23 insertions(+), 95 deletions(-) diff --git a/.gitignore b/.gitignore index b0d9eb1..710758b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ source/version.py dist nitrate.egg-info/ *~ +build +venv +.venv diff --git a/python-nitrate.spec b/python-nitrate.spec index 74708e6..0b9bc44 100644 --- a/python-nitrate.spec +++ b/python-nitrate.spec @@ -8,40 +8,11 @@ License: LGPLv2+ URL: https://github.com/psss/python-nitrate Source0: %{url}/releases/download/%{version}/%{name}-%{version}.tar.bz2 -# Depending on the distro, we set some defaults. -# Note that the bcond macros are named for the CLI option they create. -# "%%bcond_without" means "ENABLE by default and create a --without option" - -# Fedora or RHEL 8+ -%if 0%{?fedora} || 0%{?rhel} > 7 -%bcond_with oldreqs -%bcond_with englocale -%else -# The automatic runtime dependency generator doesn't exist yet -%bcond_without oldreqs -# The C.UTF-8 locale doesn't exist, Python defaults to C (ASCII) -%bcond_without englocale -%endif - -# For older Fedora and RHEL build python2-nitrate as well -%if 0%{?fedora} > 31 || 0%{?rhel} > 7 -%bcond_with python2 -%else -%bcond_without python2 -%endif - BuildArch: noarch BuildRequires: git-core BuildRequires: python%{python3_pkgversion}-devel BuildRequires: python%{python3_pkgversion}-setuptools BuildRequires: python%{python3_pkgversion}-six -%if %{with python2} -BuildRequires: python2-devel -BuildRequires: python2-setuptools -BuildRequires: python2-six -%endif - -%{?python_enable_dependency_generator} %global _description %{expand: A Python interface to the Nitrate test case management system. @@ -52,37 +23,17 @@ for fast debugging and experimenting).} %description %_description - -# Python 2 -%if %{with python2} -%package -n python2-nitrate -Summary: %{summary} -%{?python_provide:%python_provide python2-nitrate} -%if %{with oldreqs} -%if 0%{?rhel} > 7 -Requires: python2-gssapi -Requires: python2-psycopg2 -%else -Requires: python-gssapi -Requires: python-psycopg2 -%endif -Requires: python2-six -%endif - -%description -n python2-nitrate %_description -%endif - -# Python 3 %package -n python%{python3_pkgversion}-nitrate Summary: %{summary} %{?python_provide:%python_provide python3-nitrate} -%if %{with oldreqs} Requires: python%{python3_pkgversion}-gssapi -Requires: python%{python3_pkgversion}-psycopg3 Requires: python%{python3_pkgversion}-six -%endif Requires: libpq -Conflicts: python2-nitrate < 1.5-3 +%if 0%{?rhel} == 8 +Requires: python%{python3_pkgversion}-psycopg2 +%else +Requires: python%{python3_pkgversion}-psycopg3 +%endif %description -n python%{python3_pkgversion}-nitrate %_description @@ -90,35 +41,15 @@ Conflicts: python2-nitrate < 1.5-3 %autosetup -S git %build -%if %{with englocale} -export LANG=en_US.utf-8 -%endif -%if %{with python2} -%py2_build -%endif %py3_build %install -%if %{with englocale} -export LANG=en_US.utf-8 -%endif -%if %{with python2} -%py2_install -%endif %py3_install mkdir -p %{buildroot}%{_mandir}/man1 install -pm 644 docs/*.1.gz %{buildroot}%{_mandir}/man1 -# https://fedoraproject.org/wiki/Changes/Python3.12#pathfix.py_tool_will_be_removed %py3_shebang_fix %{buildroot}%{_bindir}/nitrate -%if %{with python2} -%files -n python2-nitrate -%{python2_sitelib}/nitrate/ -%{python2_sitelib}/nitrate-*.egg-info/ -%license LICENSE -%endif - %files -n python%{python3_pkgversion}-nitrate %{python3_sitelib}/nitrate/ %{python3_sitelib}/nitrate-*.egg-info/ diff --git a/source/containers.py b/source/containers.py index 90202a1..9680405 100644 --- a/source/containers.py +++ b/source/containers.py @@ -58,20 +58,22 @@ """ import six -import psycopg -from six.moves import xmlrpc_client as xmlrpclib +try: + import psycopg +except (ImportError, ModuleNotFoundError): + import psycopg2 as psycopg + import nitrate.config as config import nitrate.teiid as teiid - -from nitrate.config import log -from nitrate.utils import pretty, listed, sliced from nitrate.base import Nitrate, NitrateNone, _getter, _idify -from nitrate.immutable import Component, Bug, Tag +from nitrate.config import log +from nitrate.immutable import Bug, Component, Tag +from nitrate.mutable import CasePlan, CaseRun, Mutable, TestCase, TestPlan, TestRun +from nitrate.utils import listed, pretty, sliced from nitrate.xmlrpc_driver import NitrateError -from nitrate.mutable import ( - Mutable, TestPlan, TestRun, TestCase, CaseRun, CasePlan) +from six.moves import xmlrpc_client as xmlrpclib # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Container Class diff --git a/source/teiid.py b/source/teiid.py index 9c6a826..780aed9 100644 --- a/source/teiid.py +++ b/source/teiid.py @@ -32,7 +32,10 @@ port = 5432 """ -import psycopg +try: + import psycopg +except (ImportError, ModuleNotFoundError): + import psycopg2 as psycopg from nitrate.config import log, Config from nitrate.xmlrpc_driver import NitrateError diff --git a/test/test-bed-prepare.py b/test/test-bed-prepare.py index 445e25a..19753b9 100755 --- a/test/test-bed-prepare.py +++ b/test/test-bed-prepare.py @@ -1,4 +1,3 @@ -#!/usr/bin/python2 """ Prepare test bed - create Test Cases, Test Plans and Test Runs """ import nitrate diff --git a/tests/config.fmf b/tests/config.fmf index 5e816c6..d1a001d 100644 --- a/tests/config.fmf +++ b/tests/config.fmf @@ -3,10 +3,4 @@ test: | set +o pipefail command="import nitrate; print(nitrate.TestCase(1234))" message="Please, provide at least a minimal config" - $python -c "$command" 2>&1 | grep "$message" -environment: - python: python3 -adjust+: - - environment: - python: python2 - when: distro == centos-7 + python3 -c "$command" 2>&1 | grep "$message" diff --git a/tests/main.fmf b/tests/main.fmf index e664952..1ee1265 100644 --- a/tests/main.fmf +++ b/tests/main.fmf @@ -1,5 +1 @@ require: python3-nitrate - -adjust: - - require: python2-nitrate - when: distro == centos-7 From 84358d391e05b5855a7808a70e236e1f1779a854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Zachar?= Date: Tue, 3 Sep 2024 14:19:26 +0200 Subject: [PATCH 3/3] Remove explicit Requires, let pyscopg3 be py3.13+ Python macro can use setup.py as the Requires source, lets have it on single place. --- python-nitrate.spec | 9 +-------- setup.py | 3 ++- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/python-nitrate.spec b/python-nitrate.spec index 0b9bc44..fab3739 100644 --- a/python-nitrate.spec +++ b/python-nitrate.spec @@ -26,14 +26,7 @@ for fast debugging and experimenting).} %package -n python%{python3_pkgversion}-nitrate Summary: %{summary} %{?python_provide:%python_provide python3-nitrate} -Requires: python%{python3_pkgversion}-gssapi -Requires: python%{python3_pkgversion}-six -Requires: libpq -%if 0%{?rhel} == 8 -Requires: python%{python3_pkgversion}-psycopg2 -%else -Requires: python%{python3_pkgversion}-psycopg3 -%endif + %description -n python%{python3_pkgversion}-nitrate %_description diff --git a/setup.py b/setup.py index b9d0c86..ec15f2e 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,8 @@ license='LGPLv2+', install_requires=[ 'gssapi', - 'psycopg', + 'psycopg; python_version >= "3.13"', + 'psycopg2; python_version < "3.13"', 'six', ], url='https://psss.fedorapeople.org/python-nitrate/',