# Sphinx-generated HTML documentation is not suitable for packaging; see
# https://bugzilla.redhat.com/show_bug.cgi?id=2006555 for discussion.
#
# We can generate PDF documentation as a substitute.
%bcond_without doc_pdf
Name: python-asyncpg
Summary: A fast PostgreSQL Database Client Library for Python/asyncio
Version: 0.23.0
Release: %autorelease
License: ASL 2.0
URL: https://github.com/MagicStack/asyncpg
Source0: %{pypi_source asyncpg}
# Replace sphinxcontrib-asyncio with sphinxcontrib-trio
# https://bugzilla.redhat.com/show_bug.cgi?id=1991952
Patch0: asyncpg-0.23.0-use-sphinxcontrib-trio.patch
BuildRequires: gcc
BuildRequires: python3-devel
%if %{with doc_pdf}
BuildRequires: python3-docs
BuildRequires: make
BuildRequires: python3-sphinx-latex
BuildRequires: latexmk
%endif
# For tests:
#
# For pg_config binary
BuildRequires: libpq-devel
# For pg_ctl binary
BuildRequires: postgresql-server
# For citext extension
BuildRequires: postgresql-contrib
# Note that asyncpg/pgproto comes from a git submodule referencing a separate
# project, https://github.com/MagicStack/py-pgproto. However, we do not treat
# it as a bundled dependency because it contains only sources; it has no build
# system and is not designed for separate installation; and it is managed as a
# part of the asyncpg package, as evidenced by the comment “This module is part
# of asyncpg” in the file headers.
%global common_description %{expand:
asyncpg is a database interface library designed specifically for PostgreSQL
and Python/asyncio. asyncpg is an efficient, clean implementation of PostgreSQL
server binary protocol for use with Python’s asyncio framework. You can read
more about asyncpg in an introductory blog post
http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/.}
%description %{common_description}
%package -n python3-asyncpg
Summary: %{summary}
%description -n python3-asyncpg %{common_description}
%package doc
Summary: Documentation for %{name}
BuildArch: noarch
Requires: python3-docs
%description doc %{common_description}
%prep
%autosetup -n asyncpg-%{version} -p1
# Remove pre-generated C sources from Cython to ensure they are re-generated
# and not used in the build. Note that recordobj.c is not a generated source,
# and must not be removed!
find asyncpg -type f -name '*.c' ! -name 'recordobj.c' -print -delete
# Loosen pinned versions of documentation and selected test dependencies in
# setup.py to allow later versions as needed. We must work with what is
# packaged.
sed -r -i \
-e 's/(pycodestyle|uvloop)~=/\1>=/g' \
-e 's/(flake8|Sphinx|sphinx_rtd_theme)~=/\1>=/g' setup.py
# Use local inventory in intersphinx mapping.
#
# Do not put the source directory at the front of the path, as this keeps us
# from using our own PYTHONPATH setting to allow importing the compiled
# extension modules.
sed -r -i \
-e 's|https://docs.python.org/3|/%{_docdir}/python3-docs/html|' \
-e 's|(sys\.path\.)insert\(0,[[:blank:]]*|\1append\(|' \
docs/conf.py
# Loosen SemVer pins to allow newer versions of Sphinx-related dependencies.
sed -r -i 's/([Ss]phinx.*)~=/\1>=/g' setup.py
# We will not run style linting tests since they are brittle, so we might as
# well drop the corresponding dependencies.
sed -r -i '/(pycodestyle|flake8)/d' setup.py
%generate_buildrequires
# Note dev extra includes doc and test extras
%pyproject_buildrequires -x dev
%build
%set_build_flags
%pyproject_wheel
%if %{with doc_pdf}
(
# Temporary local installation so we can import the Cython extension module
# to build documentation:
PYTEMP="${PWD}/%{_vpath_builddir}/pytemp"
export PYTHONPATH="${PYTEMP}"
%{python3} -m pip install --target="${PYTEMP}" \
--no-deps --use-pep517 --no-build-isolation \
--disable-pip-version-check --no-clean --progress-bar off --verbose \
%{_pyproject_wheeldir}/*.whl
%make_build -C docs latex SPHINXBUILD='sphinx-build' SPHINXOPTS='%{?_smp_mflags}'
%make_build -C docs/_build/latex LATEXMKOPTS='-quiet'
rm -rf "${PYTEMP}"
)
%endif
%install
%pyproject_install
%pyproject_save_files asyncpg
%check
# It is not clear why the tests always import asyncpg as ../asyncpg/__init__.py
# even if we set PYTHONPATH to the installed sitearch directory. This
# workaround is ugly, but there is nothing actually wrong with it, as the
# install is already done by the time the check section runs:
rm -rf asyncpg
ln -s %{buildroot}%{python3_sitearch}/asyncpg/
# Do not run flake8 code style tests, which may fail; besides, we have patched
# flake8 and pycodestyle out of the test dependencies
k="${k-}${k+ and }not TestFlake8"
%pytest -k "${k}"
%files -n python3-asyncpg -f %{pyproject_files}
# Do not ship C source files (.c, .h).
%exclude %{python3_sitearch}/asyncpg/*/*.c
%exclude %{python3_sitearch}/asyncpg/*/*.h
%exclude %{python3_sitearch}/asyncpg/*/*/*.c
%exclude %{python3_sitearch}/asyncpg/*/*/*.h
%files doc
%license LICENSE
%doc README.rst
%if %{with doc_pdf}
%doc docs/_build/latex/asyncpg.pdf
%endif
%changelog
%autochangelog