Blob Blame History Raw
%bcond_without tests

Name:           python-aiohttp
Version:        3.9.5
Release:        %autorelease
Summary:        Python HTTP client/server for asyncio

License:        Apache-2.0
URL:            https://github.com/aio-libs/aiohttp
# We use requirements/*.txt to generate test dependencies; these files are not
# present in the PyPI sdist, so we must use the GitHub archive.
Source0:        %{url}/archive/v%{version}/aiohttp-%{version}.tar.gz

# downstream only patch
Patch:          0001-Unbundle-llhttp.patch

BuildRequires:  gcc

# CVE-2024-27982 requires >= 9.2.1. The actual lower bound is based on the
# version that upstream bundles/vendors.
BuildRequires:  llhttp-devel >= 9.2.1

BuildRequires:  python3-devel

%global common_description %{expand:
Python HTTP client/server for asyncio which supports both the client and the
server side of the HTTP protocol, client and server websocket, and webservers
with middlewares and pluggable routing.}

%description %{common_description}

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

Recommends:     python3-aiohttp+speedups

%description -n python3-aiohttp %{common_description}

%pyproject_extras_subpkg -n python3-aiohttp speedups

%prep
%autosetup -p 1 -n aiohttp-%{version}
# Remove bundled llhttp
rm -rv vendor/llhttp
# Disable test coverage reports
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#_linters
sed -r -i '/--cov=/d' setup.cfg
# Comment out:
#   - optional test dependencies that are not yet packaged or are useless here
#   - coverage dependnecies
#   - the “-c” constraint, which the pyproject-rpm-macros don’t support
sed -r \
   -e 's/^(proxy[-\.]py|python-on-whales|wait-for-it)/# &/' \
   -e 's/^(coverage|pytest-cov|mypy)/# &/' \
   -e 's/^(setuptools-git)/# &/' \
   -e 's/^-c /# &/' \
   requirements/test.in |
%if 0%{?el9}
   sed -r 's/^time-machine\b/# /' |
%endif
   tee requirements/test.in.filtered
%if 0%{?el9}
# This is normally a test dependency, but we can still run tests without it
sed -r -i 's/^uvloop\b/# &/' requirements/base.in
%endif

# Make sure the source archive does not include any files generated by Cython
grep -rl '/\* Generated by Cython' | xargs -r rm -v
# don't treat DeprecationWarnings as errors in subprocess based tests
sed -i 's/"-W", "error"/"-W", "error", "-W", "ignore::DeprecationWarning"/' tests/test_circular_imports.py

%generate_buildrequires
%{pyproject_buildrequires \
    requirements/cython.in \
    %{?with_tests:requirements/test.in.filtered}}

%build
# Recreate removed Cython files using commands extracted from the Makefile.
# We don't run make directly, as it pip-installs Cython.
#
# We don't need a real git checkout, but we do need a .git directory to help
# certain scripts find the root of the source tree.
mkdir -p .git
# See the aiohttp/_find_header.c target in the Makefile; this also generates
# _headers.pyi.
%{python3} tools/gen.py
# Now we can invoke Cython.
%{python3} -m cython -3 aiohttp/*.pyx -I aiohttp
# Now we need to remove the .git directory again, because its presence will
# lead the actual build astray, something like:
#   Install submodules when building from git clone
#   Hint:
#     git submodule update --init
rm -rvf .git
# Now we can actually proceed with building the package.
%pyproject_wheel

%install
%pyproject_install
%pyproject_save_files aiohttp

%check
%if %{with tests}
# Fixes problems importing compiled extensions from subprocesses.
export PYTHONSAFEPATH=1
# Setting PYTHONSAFEPATH works only for Python 3.11+, so we must skip any
# affected tests on older Pythons.
%if v"0%{?python3_version}" < v"3.11"
k="${k-}${k+ and }not test_no_warnings"
%endif
# test_proxy_functional.py requires python3dist(proxy-py)
ignore="${ignore-} --ignore=tests/test_proxy_functional.py"
# These require python-on-whales and a running Docker
ignore="${ignore-} --ignore=tests/autobahn"
# test_client_session_timeout_zero requires DNS
k="${k-}${k+ and }not test_client_session_timeout_zero"
# A slow builder may easily violate an arbitrary bound on how long it should
# take to import the package. This is not something we need to care about
# downstream.
k="${k-}${k+ and }not test_import_time"
%if 0%{?fc39} || 0%{?fc38}
# E           TypeError: Unsupported destination
#             datetime.timedelta(seconds=1000)
# This appears to be an incompatibility with older versions of the test
# dependency time-machine.
k="${k-}${k+ and }not (TestCookieJarSafe and test_max_age)"
%endif
%if 0%{?el9}
# E       TypeError: 'NoneType' object is not callable
# This is probably due to the absence of the test dependency time-machine.
k="${k-}${k+ and }not (TestCookieJarSafe and test_expires)"
k="${k-}${k+ and }not (TestCookieJarSafe and test_max_age)"
k="${k-}${k+ and }not test_cookie_jar_clear_expired"
%endif
# A warning comes from our version of uvloop that is not one of the ignored
# types.
#   UserWarning: enum class uv_fs_event not importable from uvloop.includes.uv.
#   You are probably using a cpdef enum declared in a .pxd file that does not
#   have a .py  or .pyx file.
k="${k-}${k+ and }not test_no_warnings[aiohttp.pytest_plugin]"
# This depends on the exact compressed byte stream, which doesn’t match
# upstream’s expectation due to
# https://fedoraproject.org/wiki/Changes/ZlibNGTransition.
k="${k-}${k+ and }not test_send_compress_text"
%pytest -Wdefault ${ignore-} -k "${k-}" -m 'not dev_mode'
%else
# aiohttp.worker requires gunicorn
%pyproject_check_import -e aiohttp.pytest_plugin -e aiohttp.worker
%endif

%files -n python3-aiohttp -f %{pyproject_files}
%doc CHANGES.rst
%doc HISTORY.rst
%doc README.rst

%changelog
%autochangelog