1{ lib
2, buildPythonPackage
3, fetchPypi
4, httptools
5, aiofiles
6, websockets
7, multidict
8, uvloop
9, ujson
10, pytest
11, gunicorn
12, aiohttp
13, beautifulsoup4
14, pytest-sanic
15, pytest-benchmark
16
17# required just httpcore / requests-async
18, h11
19, h2
20, certifi
21, chardet
22, idna
23, requests
24, rfc3986
25, uvicorn
26}:
27
28let
29
30 # This version of sanic depends on two packages that have been deprecated by
31 # their development teams:
32 #
33 # - requests-async [where first line of pypi says to use `http3` instead now]
34 # - httpcore [where the homepage redirects to `http3` now]
35 #
36 # Since no other packages in nixpkg depend on these right now, define these
37 # packages just as local dependencies here, to avoid bloat.
38
39 httpcore = buildPythonPackage rec {
40 pname = "httpcore";
41 version = "0.3.0";
42 src = fetchPypi {
43 inherit pname version;
44 sha256 = "0n3bamaixxhcm27gf1ws3g6rkamvqx87087c88r6hyyl52si1ycn";
45 };
46
47 propagatedBuildInputs = [ certifi chardet h11 h2 idna rfc3986 ];
48
49 # relax pinned old version of h11
50 postConfigure = ''
51 substituteInPlace setup.py \
52 --replace "h11==0.8.*" "h11"
53 '';
54
55 # LICENCE.md gets propagated without this, causing collisions
56 postInstall = ''
57 rm $out/LICENSE.md
58 '';
59 };
60
61 requests-async = buildPythonPackage rec {
62 pname = "requests-async";
63 version = "0.5.0";
64 src = fetchPypi {
65 inherit pname version;
66 sha256 = "8731420451383196ecf2fd96082bfc8ae5103ada90aba185888499d7784dde6f";
67 };
68
69 propagatedBuildInputs = [ requests httpcore ];
70
71 # LICENCE.md gets propagated without this, causing collisions
72 postInstall = ''
73 rm $out/LICENSE.md
74 '';
75 };
76
77in
78
79buildPythonPackage rec {
80 pname = "sanic";
81 version = "19.6.3";
82
83 src = fetchPypi {
84 inherit pname version;
85 sha256 = "0b1qqsvdjkibrw5kgr0pm7n7jzb1403132wjmb0lx3k5wyvqfi95";
86 };
87
88 propagatedBuildInputs = [
89 httptools
90 aiofiles
91 websockets
92 multidict
93 requests-async
94 uvloop
95 ujson
96 ];
97
98 checkInputs = [
99 pytest
100 gunicorn
101 aiohttp
102 beautifulsoup4
103 pytest-sanic
104 pytest-benchmark
105 uvicorn
106 ];
107
108 # Sanic says it needs websockets 7.x, but the changelog for 8.x is actually
109 # nearly compatible with sanic's use. So relax this constraint, with a small
110 # required code change.
111 postConfigure = ''
112 substituteInPlace setup.py --replace \
113 "websockets>=7.0,<8.0" \
114 "websockets>=7.0,<9.0"
115 substituteInPlace sanic/websocket.py --replace \
116 "self.websocket.subprotocol = subprotocol" \
117 "self.websocket.subprotocol = subprotocol
118 self.websocket.is_client = False"
119 '';
120
121 # 10/500 tests ignored due to missing directory and
122 # requiring network access
123 checkPhase = ''
124 pytest --ignore tests/test_blueprints.py \
125 --ignore tests/test_routes.py \
126 --ignore tests/test_worker.py
127 '';
128
129 meta = with lib; {
130 description = "A microframework based on uvloop, httptools, and learnings of flask";
131 homepage = "http://github.com/channelcat/sanic/";
132 license = licenses.mit;
133 maintainers = [ maintainers.costrouc ];
134 };
135}