1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonOlder,
6 fetchFromGitHub,
7 substituteAll,
8 llhttp,
9 python,
10 # build_requires
11 cython,
12 setuptools,
13 # install_requires
14 attrs,
15 multidict,
16 async-timeout,
17 yarl,
18 frozenlist,
19 aiosignal,
20 aiodns,
21 brotli,
22 # tests_require
23 freezegun,
24 gunicorn,
25 pytest-mock,
26 pytest7CheckHook,
27 python-on-whales,
28 re-assert,
29 trustme,
30}:
31
32buildPythonPackage rec {
33 pname = "aiohttp";
34 version = "3.9.5";
35 pyproject = true;
36
37 disabled = pythonOlder "3.8";
38
39 src = fetchFromGitHub {
40 owner = "aio-libs";
41 repo = "aiohttp";
42 rev = "refs/tags/v${version}";
43 hash = "sha256-FRtirmwgU8v+ee3db7rOFsmy0rNW8A7+yRZC5d6uYNA=";
44 };
45
46 patches = [
47 (substituteAll {
48 src = ./unvendor-llhttp.patch;
49 llhttpDev = lib.getDev llhttp;
50 llhttpLib = lib.getLib llhttp;
51 })
52 ];
53
54 postPatch = ''
55 sed -i '/--cov/d' setup.cfg
56
57 rm -r vendor
58 patchShebangs tools
59 touch .git # tools/gen.py uses .git to find the project root
60 '';
61
62 build-system = [
63 cython
64 setuptools
65 ];
66
67 preBuild = ''
68 make cythonize
69 '';
70
71 dependencies = [
72 attrs
73 multidict
74 async-timeout
75 yarl
76 frozenlist
77 aiosignal
78 aiodns
79 brotli
80 ];
81
82 postInstall = ''
83 # remove source code file with reference to dev dependencies
84 rm $out/${python.sitePackages}/aiohttp/_cparser.pxd{,.orig}
85 '';
86
87 # NOTE: pytest-xdist cannot be added because it is flaky. See https://github.com/NixOS/nixpkgs/issues/230597 for more info.
88 nativeCheckInputs =
89 [
90 freezegun
91 gunicorn
92 pytest-mock
93 pytest7CheckHook
94 python-on-whales
95 re-assert
96 ]
97 ++ lib.optionals (!(stdenv.isDarwin && stdenv.isAarch64)) [
98 # Optional test dependency. Depends indirectly on pyopenssl, which is
99 # broken on aarch64-darwin.
100 trustme
101 ];
102
103 disabledTests =
104 [
105 # Disable tests that require network access
106 "test_client_session_timeout_zero"
107 "test_mark_formdata_as_processed"
108 "test_requote_redirect_url_default"
109 # don't run benchmarks
110 "test_import_time"
111 ]
112 ++ lib.optionals stdenv.is32bit [ "test_cookiejar" ]
113 ++ lib.optionals stdenv.isDarwin [
114 "test_addresses" # https://github.com/aio-libs/aiohttp/issues/3572, remove >= v4.0.0
115 "test_close"
116 ];
117
118 disabledTestPaths = [
119 "tests/test_proxy_functional.py" # FIXME package proxy.py
120 ];
121
122 __darwinAllowLocalNetworking = true;
123
124 # aiohttp in current folder shadows installed version
125 preCheck =
126 ''
127 rm -r aiohttp
128 touch tests/data.unknown_mime_type # has to be modified after 1 Jan 1990
129 ''
130 + lib.optionalString stdenv.isDarwin ''
131 # Work around "OSError: AF_UNIX path too long"
132 export TMPDIR="/tmp"
133 '';
134
135 meta = with lib; {
136 changelog = "https://github.com/aio-libs/aiohttp/blob/v${version}/CHANGES.rst";
137 description = "Asynchronous HTTP Client/Server for Python and asyncio";
138 license = licenses.asl20;
139 homepage = "https://github.com/aio-libs/aiohttp";
140 maintainers = with maintainers; [ dotlambda ];
141 };
142}