Blob Blame History Raw
%global forgeurl https://github.com/encode/databases

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

Name:           python-databases
Summary:        Async database support for Python
Version:        0.5.3
Release:        %autorelease

License:        BSD
URL:            https://www.encode.io/databases/
Source0:        %{forgeurl}/archive/%{version}/databases-%{version}.tar.gz

BuildArch:      noarch

BuildRequires:  python3-devel

# 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
# Work around RHBZ#2012590, in which python3-sqlalchemy fails to depend on
# python3-greenlet on some architectures, by adding a direct dependency.
BuildRequires:  python3dist(greenlet)

Obsoletes:      python-databases-doc < 0.5.2-4

%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}


# README.md:
#   Note that if you are using any synchronous SQLAlchemy functions such as
#   `engine.create_all()` or [alembic][alembic] migrations then you still have
#   to install a synchronous DB driver: [psycopg2][psycopg2] for PostgreSQL and
#   [pymysql][pymysql] for MySQL.
# Therefore we manually write out the extras metapackages for PostgreSQL and
# MySQL so that we can add these drivers as Recommends. Use, e.g.:
#   rpm -E '%%pyproject_extras_subpkg -n python3-databases postgresql …'
# to see the proper macro expanson (but note that the absolute path to
# %%{_pyproject_ghost_distinfo} must be fixed). We can still handle SQLite the
# easy way.
%pyproject_extras_subpkg -n python3-databases sqlite


%package -n python3-databases+postgresql
Summary:        Metapackage for python3-databases: postgresql extras

Requires:       python3-databases = %{version}-%{release}
Recommends:     python3dist(psycopg2)

%description -n python3-databases+postgresql
This is a metapackage bringing in postgresql extras requires for
python3-databases.
It makes sure the dependencies are installed.

%files -n python3-databases+postgresql -f %{_pyproject_ghost_distinfo}


%package -n python3-databases+mysql
Summary: Metapackage for python3-databases: mysql extras
Recommends:     python3dist(pymysql)

Requires: python3-databases = %{version}-%{release}

%description -n python3-databases+mysql
This is a metapackage bringing in mysql extras requires for python3-databases.
It makes sure the dependencies are installed.

%files -n python3-databases+mysql -f %{_pyproject_ghost_distinfo}


%package -n python3-databases+postgresql_aiopg
Summary: Metapackage for python3-databases: postgresql_aiopg extras

Requires: python3-databases = %{version}-%{release}
Recommends:     python3dist(psycopg2)

%description -n python3-databases+postgresql_aiopg
This is a metapackage bringing in postgresql_aiopg extras requires for
python3-databases.
It makes sure the dependencies are installed.

%files -n python3-databases+postgresql_aiopg -f %{_pyproject_ghost_distinfo}


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

# Work around RHBZ#2012590, in which python3-sqlalchemy fails to depend on
# python3-greenlet on some architectures, by adding a direct dependency.
Requires:       python3dist(greenlet)

%description -n python3-databases %{common_description}


%prep
%autosetup -n databases-%{version}
# 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


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


%build
%pyproject_wheel


%install
%pyproject_install
%pyproject_save_files databases


%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, sqlite+aiosqlite:///testsuite"

%pytest


%files -n python3-databases -f %{pyproject_files}
%doc CHANGELOG.md
%doc README.md


%changelog
%autochangelog