Blob Blame History Raw
# Sphinx-generated HTML documentation is not suitable for packaging; see
# 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
Source0:        %{pypi_source asyncpg}

# Replace sphinxcontrib-asyncio with sphinxcontrib-trio
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

# 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, 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}

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

%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
# 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'

# 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||/%{_docdir}/python3-docs/html|' \
    -e 's|(sys\.path\.)insert\(0,[[:blank:]]*|\1append\(|' \

# Loosen SemVer pins to allow newer versions of Sphinx-related dependencies.
sed -r -i 's/([Ss]phinx.*)~=/\1>=/g'

# 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'

# Note dev extra includes doc and test extras
%pyproject_buildrequires -x dev


%if %{with doc_pdf}
  # Temporary local installation so we can import the Cython extension module
  # to build documentation:

  %{python3} -m pip install --target="${PYTEMP}" \
      --no-deps --use-pep517 --no-build-isolation \
      --disable-pip-version-check --no-clean --progress-bar off --verbose \

  %make_build -C docs latex SPHINXBUILD='sphinx-build' SPHINXOPTS='%{?_smp_mflags}'
  %make_build -C docs/_build/latex LATEXMKOPTS='-quiet'

  rm -rf "${PYTEMP}"

%pyproject_save_files asyncpg

# It is not clear why the tests always import asyncpg as ../asyncpg/
# 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