1{
2 lib,
3 stdenv,
4 aiofiles,
5 aioquic,
6 beautifulsoup4,
7 buildPythonPackage,
8 doCheck ? !stdenv.hostPlatform.isDarwin, # on Darwin, tests fail but pkg still works
9 fetchFromGitHub,
10 gunicorn,
11 html5tagger,
12 httptools,
13 multidict,
14 pytest-asyncio,
15 pytestCheckHook,
16 pythonAtLeast,
17 pythonOlder,
18 sanic-routing,
19 sanic-testing,
20 setuptools,
21 tracerite,
22 typing-extensions,
23 ujson,
24 uvicorn,
25 uvloop,
26 websockets,
27}:
28
29buildPythonPackage rec {
30 pname = "sanic";
31 version = "24.6.0";
32 pyproject = true;
33
34 disabled = pythonOlder "3.7";
35
36 src = fetchFromGitHub {
37 owner = "sanic-org";
38 repo = "sanic";
39 rev = "refs/tags/v${version}";
40 hash = "sha256-AviYqdr+r5ya4mFJKGUatBsaMMmCQGqE3YtDJwTuaY0=";
41 };
42
43 build-system = [ setuptools ];
44
45 dependencies = [
46 aiofiles
47 httptools
48 html5tagger
49 multidict
50 sanic-routing
51 tracerite
52 typing-extensions
53 ujson
54 uvloop
55 websockets
56 ];
57
58 optional-dependencies = {
59 ext = [
60 # TODO: sanic-ext
61 ];
62 http3 = [ aioquic ];
63 };
64
65 nativeCheckInputs = [
66 beautifulsoup4
67 gunicorn
68 pytest-asyncio
69 pytestCheckHook
70 sanic-testing
71 uvicorn
72 ] ++ optional-dependencies.http3;
73
74 inherit doCheck;
75
76 preCheck =
77 ''
78 # Some tests depends on sanic on PATH
79 PATH="$out/bin:$PATH"
80 PYTHONPATH=$PWD:$PYTHONPATH
81
82 # needed for relative paths for some packages
83 cd tests
84 ''
85 + lib.optionalString stdenv.hostPlatform.isDarwin ''
86 # OSError: [Errno 24] Too many open files
87 ulimit -n 1024
88 '';
89
90 # uvloop usage is buggy
91 #SANIC_NO_UVLOOP = true;
92
93 pytestFlagsArray = [
94 "--asyncio-mode=auto"
95 "-vvv"
96 ];
97
98 disabledTests =
99 [
100 # Require networking
101 "test_full_message"
102 # Server mode mismatch (debug vs production)
103 "test_num_workers"
104 # Racy tests
105 "test_custom_cert_loader"
106 "test_keep_alive_client_timeout"
107 "test_keep_alive_server_timeout"
108 "test_logger_vhosts"
109 "test_ssl_in_multiprocess_mode"
110 "test_zero_downtime"
111 # sanic.exceptions.SanicException: Cannot setup Sanic Simple Server without a path to a directory
112 "test_load_app_simple"
113 # Tests create defunct Python processes
114 "test_reloader_live"
115 "test_reloader_live_with_dir"
116 "test_reload_listeners"
117 # Tests crash the Python interpreter
118 "test_host_port_localhost"
119 "test_host_port"
120 "test_server_run"
121 # NoneType object is not subscriptable
122 "test_serve_app_implicit"
123 # AssertionError: assert [] == ['Restarting a process', 'Begin restart termination', 'Starting a process']
124 "test_default_reload_shutdown_order"
125 # App not found.
126 "test_input_is_dir"
127 # HTTP 500 with Websocket subprotocols
128 "test_websocket_route_with_subprotocols"
129 # Socket closes early
130 "test_no_exceptions_when_cancel_pending_request"
131 ]
132 ++ lib.optionals (pythonAtLeast "3.12") [
133 # AttributeError: 'has_calls' is not a valid assertion. Use a spec for the mock if 'has_calls' is meant to be an attribute.
134 "test_ws_frame_put_message_into_queue"
135 ];
136
137 disabledTestPaths = [
138 # We are not interested in benchmarks
139 "benchmark/"
140 # We are also not interested in typing
141 "typing/test_typing.py"
142 # unable to create async loop
143 "test_app.py"
144 "test_asgi.py"
145 # occasionally hangs
146 "test_multiprocessing.py"
147 ];
148
149 # Avoid usage of nixpkgs-review in darwin since tests will compete usage
150 # for the same local port
151 __darwinAllowLocalNetworking = true;
152
153 pythonImportsCheck = [ "sanic" ];
154
155 meta = with lib; {
156 description = "Web server and web framework";
157 homepage = "https://github.com/sanic-org/sanic/";
158 changelog = "https://github.com/sanic-org/sanic/releases/tag/v${version}";
159 license = licenses.mit;
160 maintainers = [ ];
161 mainProgram = "sanic";
162 };
163}