b95aad0
# When bootstrapping, break circular dependency on starlette in the tests.
b95aad0
%bcond_with bootstrap
b95aad0
fb93eeb
# MySQL tests require interacting with a temporary MySQL database. We are able
fb93eeb
# to do this, but leave a build conditional in case it breaks.
fb93eeb
%bcond_without mysql_tests
fb93eeb
eecf44b
# Post-release snapshot
e188686
# %%global commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
e188686
# %%global snapdate ########
eecf44b
5187759
Name:           python-databases
b95aad0
Summary:        Async database support for Python
e188686
Version:        0.7.0%{?commit:^%{snapdate}git%(echo '%{commit}' | cut -b -7)}
5b89981
Release:        %autorelease
b95aad0
eecf44b
%{?!commit:%global srcversion %{version}}
eecf44b
%{?commit:%global srcversion %{commit}}
eecf44b
0aa0c27
License:        BSD-3-Clause
5187759
URL:            https://www.encode.io/databases/
fb93eeb
%global forgeurl https://github.com/encode/databases
eecf44b
Source0:        %{forgeurl}/archive/%{srcversion}/databases-%{srcversion}.tar.gz
b95aad0
43b02df
BuildArch:      noarch
43b02df
43b02df
# https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval
43b02df
ExcludeArch:    %{ix86}
b95aad0
b95aad0
BuildRequires:  python3-devel
b95aad0
b95aad0
# Additional BR’s for testing, from requirements.txt only (therefore not
b95aad0
# generated):
b95aad0
# “Sync database drivers for standard tooling around
b95aad0
# setup/teardown/migrations.”
b95aad0
BuildRequires:  python3dist(psycopg2)
b95aad0
BuildRequires:  python3dist(pymysql)
b95aad0
b95aad0
# “Testing”
b95aad0
# We have excluded formatters, linters, and analysis tools: autoflake, black,
3e08b29
# codecov, isort, mypy, pytest-cov
b95aad0
BuildRequires:  python3dist(pytest)
b95aad0
%if %{without bootstrap}
b95aad0
BuildRequires:  python3dist(starlette)
b95aad0
# Used only as a soft dependency of starlette
b95aad0
BuildRequires:  python3dist(requests)
86ce2e9
# Used only as a soft dependency of starlette.testclient
86ce2e9
BuildRequires:  python3dist(httpx)
b95aad0
%endif
b95aad0
fb93eeb
%if %{with mysql_tests}
fb93eeb
BuildRequires:  mariadb-server
fb93eeb
%endif
2b41dae
b95aad0
%global common_description %{expand:
b95aad0
Databases gives you simple asyncio support for a range of databases.
b95aad0
b95aad0
It allows you to make queries using the powerful SQLAlchemy Core expression
b95aad0
language, and provides support for PostgreSQL, MySQL, and SQLite.
b95aad0
b95aad0
Databases is suitable for integrating against any async Web framework, such as
b95aad0
Starlette, Sanic, Responder, Quart, aiohttp, Tornado, or FastAPI.
b95aad0
b95aad0
Documentation: https://www.encode.io/databases/
b95aad0
b95aad0
Community: https://discuss.encode.io/c/databases}
b95aad0
b95aad0
%description %{common_description}
b95aad0
b95aad0
4bea3d7
# README.md:
3e08b29
#
4bea3d7
#   Note that if you are using any synchronous SQLAlchemy functions such as
4bea3d7
#   `engine.create_all()` or [alembic][alembic] migrations then you still have
4bea3d7
#   to install a synchronous DB driver: [psycopg2][psycopg2] for PostgreSQL and
4bea3d7
#   [pymysql][pymysql] for MySQL.
3e08b29
#
4bea3d7
# Therefore we manually write out the extras metapackages for PostgreSQL and
43b02df
# MySQL backends so that we can add these drivers as weak dependencies
43b02df
# (Recommends). We can still handle the SQLite extras the easy way.
3e08b29
%package -n python3-databases+postgresql
3e08b29
Summary:        Metapackage for python3-databases: postgresql extras
ad86470
ad86470
Requires:       python3-databases = %{version}-%{release}
3e08b29
Recommends:     python3dist(psycopg2)
ad86470
3e08b29
%description -n python3-databases+postgresql
3e08b29
This is a metapackage bringing in postgresql extras requires for
ad86470
python3-databases. It makes sure the dependencies are installed.
ad86470
3e08b29
%files -n python3-databases+postgresql
8f79234
%ghost %{python3_sitelib}/*.dist-info
4bea3d7
4bea3d7
3e08b29
%package -n python3-databases+asyncpg
3e08b29
Summary:        Metapackage for python3-databases: asyncpg extras
4bea3d7
5187759
Requires:       python3-databases = %{version}-%{release}
4bea3d7
Recommends:     python3dist(psycopg2)
4bea3d7
3e08b29
%description -n python3-databases+asyncpg
3e08b29
This is a metapackage bringing in asyncpg extras requires for
fb93eeb
python3-databases. It makes sure the dependencies are installed.
4bea3d7
3e08b29
%files -n python3-databases+asyncpg
3e08b29
%ghost %{python3_sitelib}/*.dist-info
3e08b29
3e08b29
3e08b29
%package -n python3-databases+aiopg
3e08b29
Summary:        Metapackage for python3-databases: aiopg extras
3e08b29
3e08b29
Requires:       python3-databases = %{version}-%{release}
3e08b29
Recommends:     python3dist(psycopg2)
3e08b29
3e08b29
# Provide upgrade/migration path for three releases:
3e08b29
%if 0%{?fedora} && 0%{?fedora} < 40
3e08b29
Provides:       python3-databases+postgresql_aiopg = %{version}-%{release}
3e08b29
Obsoletes:      python3-databases+postgresql_aiopg < 0.6.0-1
3e08b29
%endif
3e08b29
3e08b29
%description -n python3-databases+aiopg
3e08b29
This is a metapackage bringing in aiopg extras requires for
3e08b29
python3-databases. It makes sure the dependencies are installed.
3e08b29
3e08b29
%files -n python3-databases+aiopg
3e08b29
%ghost %{python3_sitelib}/*.dist-info
3e08b29
3e08b29
3e08b29
%package -n python3-databases+mysql
3e08b29
Summary:        Metapackage for python3-databases: mysql extras
3e08b29
3e08b29
Requires:       python3-databases = %{version}-%{release}
3e08b29
Recommends:     python3dist(pymysql)
3e08b29
3e08b29
%description -n python3-databases+mysql
3e08b29
This is a metapackage bringing in mysql extras requires for
3e08b29
python3-databases. It makes sure the dependencies are installed.
3e08b29
3e08b29
%files -n python3-databases+mysql
3e08b29
%ghost %{python3_sitelib}/*.dist-info
3e08b29
3e08b29
3e08b29
%package -n python3-databases+aiomysql
3e08b29
Summary:        Metapackage for python3-databases: aiomysql extras
3e08b29
3e08b29
Requires:       python3-databases = %{version}-%{release}
3e08b29
Recommends:     python3dist(pymysql)
3e08b29
3e08b29
%description -n python3-databases+aiomysql
3e08b29
This is a metapackage bringing in aiomysql extras requires for
3e08b29
python3-databases. It makes sure the dependencies are installed.
3e08b29
3e08b29
%files -n python3-databases+aiomysql
8f79234
%ghost %{python3_sitelib}/*.dist-info
4bea3d7
4bea3d7
3e08b29
%package -n python3-databases+asyncmy
3e08b29
Summary:        Metapackage for python3-databases: asyncmy extras
4bea3d7
Recommends:     python3dist(pymysql)
4bea3d7
5187759
Requires: python3-databases = %{version}-%{release}
4bea3d7
3e08b29
# Provide upgrade/migration path for three releases:
3e08b29
%if 0%{?fedora} && 0%{?fedora} < 40
3e08b29
Provides:       python3-databases+mysql_asyncmy = %{version}-%{release}
3e08b29
Obsoletes:      python3-databases+mysql_asyncmy < 0.6.0-1
3e08b29
%endif
3e08b29
3e08b29
%description -n python3-databases+asyncmy
3e08b29
This is a metapackage bringing in asyncmy extras requires for
fb93eeb
python3-databases. It makes sure the dependencies are installed.
4bea3d7
3e08b29
%files -n python3-databases+asyncmy
8f79234
%ghost %{python3_sitelib}/*.dist-info
3e08b29
3e08b29
43b02df
%pyproject_extras_subpkg -n python3-databases sqlite aiosqlite
b95aad0
b95aad0
5187759
%package -n     python3-databases
b95aad0
Summary:        %{summary}
b95aad0
fb93eeb
Obsoletes:      python-databases-doc < 0.5.2-4
aa21ab5
5187759
%description -n python3-databases %{common_description}
b95aad0
b95aad0
b95aad0
%prep
43b02df
%autosetup -n databases-%{srcversion}
b95aad0
b95aad0
4fa6fbc
%generate_buildrequires
3e08b29
%{pyproject_buildrequires \
3e08b29
    -x postgresql \
3e08b29
    -x asyncpg \
3e08b29
    -x aiopg \
3e08b29
    -x mysql \
3e08b29
    -x aiomysql \
43b02df
    -x asyncmy \
3e08b29
    -x sqlite \
3e08b29
    -x aiosqlite}
4fa6fbc
4fa6fbc
b95aad0
%build
b95aad0
%pyproject_wheel
b95aad0
b95aad0
b95aad0
%install
b95aad0
%pyproject_install
5187759
%pyproject_save_files databases
b95aad0
b95aad0
b95aad0
%check
b95aad0
%if %{with bootstrap}
b95aad0
rm tests/test_integration.py
b95aad0
%endif
b95aad0
3e08b29
# Since we won’t be able to test all of the backends, we start with an
3e08b29
# import-only “smoke test”
43b02df
%pyproject_check_import
3e08b29
b95aad0
# E   ModuleNotFoundError: No module named 'tests'
b95aad0
touch tests/__init__.py
b95aad0
3e08b29
# We can only easily run the tests with SQLite; other databases require a
3e08b29
# properly configured server, which we cannot in general provide as an
3e08b29
# unprivileged user. However, see the MySQL support below.
3e08b29
#
3e08b29
# The following environment variable is a comma-separated list with (optional?)
3e08b29
# whitespace.
ac6db98
export TEST_DATABASE_URLS="sqlite:///testsuite, sqlite+aiosqlite:///testsuite"
b95aad0
fb93eeb
%if %{with mysql_tests}
fb93eeb
# Based on rubygem-mysql2 packaging; see also python-asyncmy
fb93eeb
fb93eeb
# Use a randomized port in case the standard mysqld port 3306 is occupied, and
fb93eeb
# to account for multiple simultaneous builds on the same host.
fb93eeb
# https://src.fedoraproject.org/rpms/rubygem-pg/pull-request/3
fb93eeb
MYSQL_PORT="$((13306 + ${RANDOM} % 1000))"
fb93eeb
MYSQL_USER="$(whoami)"
fb93eeb
MYSQL_DATA_DIR="${PWD}/data"
fb93eeb
MYSQL_SOCKET="${PWD}/mysql.sock"
fb93eeb
MYSQL_LOG="${PWD}/mysql.log"
fb93eeb
MYSQL_PID_FILE="${PWD}/mysql.pid"
fb93eeb
fb93eeb
mkdir "${MYSQL_DATA_DIR}"
fb93eeb
mysql_install_db --datadir="${MYSQL_DATA_DIR}" --log-error="${MYSQL_LOG}"
fb93eeb
4957ca6
%{_libexecdir}/mysqld --port="${MYSQL_PORT}" --skip-ssl \
fb93eeb
    --datadir="${MYSQL_DATA_DIR}" --log-error="${MYSQL_LOG}" \
fb93eeb
    --socket="${MYSQL_SOCKET}" --pid-file="${MYSQL_PID_FILE}" & :
fb93eeb
fb93eeb
echo "Waiting for server… ${i}" 1>&2
fb93eeb
TIMEOUT=30
fb93eeb
while ! grep -q 'ready for connections.' "${MYSQL_LOG}"
fb93eeb
do
fb93eeb
  sleep 1
fb93eeb
  TIMEOUT=$((TIMEOUT - 1))
fb93eeb
  if [[ "${TIMEOUT}" = '0' ]]
fb93eeb
  then
fb93eeb
    echo 'Timed out' 1>&2
fb93eeb
    exit 1
fb93eeb
  fi
fb93eeb
done
fb93eeb
fb93eeb
echo 'Ready' 1>&2
fb93eeb
trap "kill $(cat "${MYSQL_PID_FILE}")" INT TERM EXIT
fb93eeb
fb93eeb
# See https://github.com/brianmario/mysql2/blob/master/.travis_setup.sh
fb93eeb
mysql -u "${MYSQL_USER}" -S "${MYSQL_SOCKET}" -P "${MYSQL_PORT}" \
fb93eeb
  -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';"
fb93eeb
mysql -u 'root' --password='123456' \
fb93eeb
  --protocol='TCP' -h 'localhost' -P "${MYSQL_PORT}" \
fb93eeb
  -e 'CREATE DATABASE testsuite;'
fb93eeb
fb93eeb
for url in \
3e08b29
    "mysql://root:123456@localhost:${MYSQL_PORT}/testsuite" \
3e08b29
%if %{with asyncmy}
3e08b29
    "mysql+asyncmy://root:123456@localhost:${MYSQL_PORT}/testsuite" \
3e08b29
%endif
3e08b29
    "mysql+aiomysql://root:123456@localhost:${MYSQL_PORT}/testsuite"
fb93eeb
do
fb93eeb
  export TEST_DATABASE_URLS="${TEST_DATABASE_URLS}, ${url}"
fb93eeb
done
fb93eeb
%endif
fb93eeb
fb93eeb
%pytest --verbose
fb93eeb
b95aad0
5187759
%files -n python3-databases -f %{pyproject_files}
b95aad0
%doc CHANGELOG.md
b95aad0
%doc README.md
b95aad0
b95aad0
b95aad0
%changelog
5b89981
%autochangelog