Blob Blame History Raw
%global _with_bootstrap 1
%global srcname databases

# When bootstrapping, break circular dependency on starlette in the tests.
%bcond_with bootstrap

Name:           python-%{srcname}
Summary:        Async database support for Python
Version:        0.4.3
Release:        4%{?dist}

License:        BSD
URL:            https://www.encode.io/%{srcname}/
Source0:        https://github.com/encode/%{srcname}/archive/%{version}/%{srcname}-%{version}.tar.gz

# Patch with work-in-progress SQLAlchemy 1.4 support from upstream PR#299
# (https://github.com/encode/databases/pull/299); this corresponds to the
# PrettyWood:fix/sqlalchemy-1.4 branch at commit
# 40c41c2b7b3fedae484ad94d81b27ce88a09c5ed.
Patch0:        %{srcname}-pr-299-40c41c2b.patch

BuildArch:      noarch

BuildRequires:  python3-devel
BuildRequires:  pyproject-rpm-macros

# Additional BR’s for testing, from requirements.txt only (therefore not
# generated):
# “Sync database drivers for standard tooling around
# setup/teardown/migrations.”
BuildRequires:  python3dist(psycopg2)
BuildRequires:  python3dist(pymysql)

# “Testing”
# We have excluded formatters, linters, and analysis tools: autoflake, black,
# codecov, isort, mypy
BuildRequires:  python3dist(pytest)
BuildRequires:  python3dist(pytest-cov)
%if %{without bootstrap}
BuildRequires:  python3dist(starlette)
# Used only as a soft dependency of starlette
BuildRequires:  python3dist(requests)
%endif

%global common_description %{expand:
Databases gives you simple asyncio support for a range of databases.

It allows you to make queries using the powerful SQLAlchemy Core expression
language, and provides support for PostgreSQL, MySQL, and SQLite.

Databases is suitable for integrating against any async Web framework, such as
Starlette, Sanic, Responder, Quart, aiohttp, Tornado, or FastAPI.

Documentation: https://www.encode.io/databases/

Community: https://discuss.encode.io/c/databases}

%description %{common_description}


%pyproject_extras_subpkg -n python3-%{srcname} postgresql mysql sqlite postgresql_aiopg


%generate_buildrequires
%pyproject_buildrequires -x postgresql,mysql,sqlite,postgresql_aiopg


%package -n     python3-%{srcname}
Summary:        %{summary}

%description -n python3-%{srcname} %{common_description}


%package doc
Summary:        Documentation for %{name}

# See scripts/publish. These BR’s cannot be automatically generated.
BuildRequires:  python3dist(mkdocs)
# While scripts/publish installs mkautodoc,
#   BuildRequires:  python3dist(mkautodoc)
# it does not seem to be absolutely required to build usable documentation.
# This is good, as packaging it in Fedora should wait for
# https://github.com/tomchristie/mkautodoc/issues/30.

%description doc %{common_description}


%prep
%setup -q -n %{srcname}-%{version}
%if 0%{?fedora} > 34
%patch0 -p1
%endif
# The following is equivalent to the former patch file
# databases-0.4.3-wayward-license-file.patch, but the sed expression works
# regardless of whether databases-pr-299-40c41c2b.patch has affected nearby
# lines or not.
#
# Without this patch, the LICENSE.md file is installed under the prefix
# (generally, /usr/local or /usr), or when installed into a virtualenv, in the
# root of the virtualenv directory. Neither is correct.
#
# Upstream doesn’t want bug reports or PR’s in general
# (https://github.com/encode/.github/blob/
#  e018bb630a92efd4609c2b60955e9c4678cd6c11/CONTRIBUTING.md),
# so I raised the issue in the Gitter chat on 2021-04-26.
sed -i -r '/data_files=\[\("", \["LICENSE.md"\]\)\],/d' setup.py
# Drop dependency on mkdocs-material. See
# https://bugzilla.redhat.com/show_bug.cgi?id=1960274#c3. The result doesn’t
# look as nice but is still usable.
sed -r -i 's/\bmaterial\b/mkdocs/' mkdocs.yml


%build
%pyproject_wheel
mkdocs build


%install
%pyproject_install
%pyproject_save_files %{srcname}


%check
%if %{with bootstrap}
rm tests/test_integration.py
%endif

# E   ModuleNotFoundError: No module named 'tests'
touch tests/__init__.py

# We can only run the tests with SQLite; other databases require a properly
# configured server, which we cannot in general provide as an unprivileged
# user. The following environment variable is a comma-separated list.
export TEST_DATABASE_URLS="sqlite:///testsuite"

%pytest


%files -n python3-%{srcname} -f %{pyproject_files}
%license LICENSE.md


%files doc
%license LICENSE.md
%doc CHANGELOG.md
%doc README.md
%doc site


%changelog
* Fri Jun 04 2021 Python Maint <python-maint@redhat.com> - 0.4.3-4
- Bootstrap for Python 3.10

* Fri May 28 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.3-3
- Build documentation without the mkdocs-material theme

* Fri May 14 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.3-2
- Patch in SQLAlchemy 1.4 support from upstream PR#299 on Fedora 35
- Reimplement databases-0.4.3-wayward-license-file.patch using sed in %%prep

* Tue Apr 27 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.3-1
- Initial package