Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use psycopg(3) for Python 3.13 compatibility #49

Merged
merged 3 commits into from
Sep 4, 2024
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ source/version.py
dist
nitrate.egg-info/
*~
build
venv
.venv
77 changes: 1 addition & 76 deletions python-nitrate.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -52,72 +23,26 @@ 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}-psycopg2
Requires: python%{python3_pkgversion}-six
%endif
Conflicts: python2-nitrate < 1.5-3


%description -n python%{python3_pkgversion}-nitrate %_description

%prep
%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/
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
license='LGPLv2+',
install_requires=[
'gssapi',
'psycopg2',
'psycopg; python_version >= "3.13"',
'psycopg2; python_version < "3.13"',
'six',
],
url='https://psss.fedorapeople.org/python-nitrate/',
Expand Down
22 changes: 12 additions & 10 deletions source/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,22 @@
"""

import six
import psycopg2

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
Expand Down Expand Up @@ -842,7 +844,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])
Expand Down Expand Up @@ -915,7 +917,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
Expand Down
11 changes: 7 additions & 4 deletions source/teiid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,7 +32,10 @@
port = 5432
"""

import psycopg2
try:
import psycopg
except (ImportError, ModuleNotFoundError):
import psycopg2 as psycopg

from nitrate.config import log, Config
from nitrate.xmlrpc_driver import NitrateError
Expand Down Expand Up @@ -74,9 +77,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)
Expand Down
1 change: 0 additions & 1 deletion test/test-bed-prepare.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/python2
""" Prepare test bed - create Test Cases, Test Plans and Test Runs """

import nitrate
Expand Down
8 changes: 1 addition & 7 deletions tests/config.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 0 additions & 4 deletions tests/main.fmf
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
require: python3-nitrate

adjust:
- require: python2-nitrate
when: distro == centos-7