summary refs log tree commit diff
path: root/pkgs/development/python-modules/sanic/default.nix
blob: 752802df209cdb5213bb4f4408a2d00f0212c1a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
{ lib
, stdenv
, buildPythonPackage
, fetchFromGitHub
, fetchpatch

# build-system
, setuptools
, wheel

# propagates
, aiofiles
, html5tagger
, httptools
, multidict
, sanic-routing
, tracerite
, typing-extensions
, ujson
, uvloop
, websockets

# optionals
, aioquic

# tests
, doCheck ? !stdenv.isDarwin # on Darwin, tests fail but pkg still works

, beautifulsoup4
, gunicorn
, pytest-asyncio
, pytestCheckHook
, pythonOlder
, sanic-testing
, uvicorn
}:

buildPythonPackage rec {
  pname = "sanic";
  version = "23.6.0";
  format = "pyproject";

  disabled = pythonOlder "3.7";

  src = fetchFromGitHub {
    owner = "sanic-org";
    repo = pname;
    rev = "refs/tags/v${version}";
    hash = "sha256-Ffw92mlYNV+ikb6299uw24EI1XPpl3Ju2st1Yt/YHKw=";
  };

  patches = [
    # https://github.com/sanic-org/sanic/pull/2801
    (fetchpatch {
      name = "fix-test-one-cpu.patch";
      url = "https://github.com/sanic-org/sanic/commit/a1df2a6de1c9c88a85d166e7e2636d26f7925852.patch";
      hash = "sha256-vljGuoP/Q9HrP+/AOoI1iUpbDQ4/1Pn7AURP1dncI00=";
    })
  ];

  nativeBuildInputs = [
    setuptools
    wheel
  ];

  propagatedBuildInputs = [
    aiofiles
    httptools
    html5tagger
    multidict
    sanic-routing
    tracerite
    typing-extensions
    ujson
    uvloop
    websockets
  ];

  passthru.optional-dependencies = {
    ext = [
      # TODO: sanic-ext
    ];
    http3 = [
      aioquic
    ];
  };

  nativeCheckInputs = [
    beautifulsoup4
    gunicorn
    pytest-asyncio
    pytestCheckHook
    sanic-testing
    uvicorn
  ] ++ passthru.optional-dependencies.http3;

  inherit doCheck;

  preCheck = ''
    # Some tests depends on sanic on PATH
    PATH="$out/bin:$PATH"
    PYTHONPATH=$PWD:$PYTHONPATH

    # needed for relative paths for some packages
    cd tests
  '' + lib.optionalString stdenv.isDarwin ''
    # OSError: [Errno 24] Too many open files
    ulimit -n 1024
  '';

  # uvloop usage is buggy
  #SANIC_NO_UVLOOP = true;

  pytestFlagsArray = [
    "--asyncio-mode=auto"
    "-vvv"
  ];

  disabledTests = [
    # Require networking
    "test_full_message"
    # Server mode mismatch (debug vs production)
    "test_num_workers"
    # Racy tests
    "test_keep_alive_client_timeout"
    "test_keep_alive_server_timeout"
    "test_zero_downtime"
    # sanic.exceptions.SanicException: Cannot setup Sanic Simple Server without a path to a directory
    "test_load_app_simple"
    # create defunct python processes
    "test_reloader_live"
    "test_reloader_live_with_dir"
    "test_reload_listeners"
    # crash the python interpreter
    "test_host_port_localhost"
    "test_host_port"
    "test_server_run"
    # NoneType object is not subscriptable
    "test_serve_app_implicit"
    # AssertionError: assert [] == ['Restarting a process', 'Begin restart termination', 'Starting a process']
    "test_default_reload_shutdown_order"
    # App not found.
    "test_input_is_dir"
    # HTTP 500 with Websocket subprotocols
    "test_websocket_route_with_subprotocols"
    # Socket closes early
    "test_no_exceptions_when_cancel_pending_request"
  ];

  disabledTestPaths = [
    # We are not interested in benchmarks
    "benchmark/"
    # We are also not interested in typing
    "typing/test_typing.py"
    # unable to create async loop
    "test_app.py"
    "test_asgi.py"
    # occasionally hangs
    "test_multiprocessing.py"
  ];

  # avoid usage of nixpkgs-review in darwin since tests will compete usage
  # for the same local port
  __darwinAllowLocalNetworking = true;

  pythonImportsCheck = [ "sanic" ];

  meta = with lib; {
    description = "Web server and web framework";
    homepage = "https://github.com/sanic-org/sanic/";
    changelog = "https://github.com/sanic-org/sanic/releases/tag/v${version}";
    license = licenses.mit;
    maintainers = with maintainers; [ AluisioASG ];
  };
}