summary refs log tree commit diff
path: root/pkgs/development/python-modules/sanic/default.nix
blob: 228bf2a5624185fc8865b764d0b74e6e4c30d603 (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
{ lib
, stdenv
, aiofiles
, beautifulsoup4
, buildPythonPackage
, doCheck ? true
, fetchFromGitHub
, gunicorn
, httptools
, multidict
, pytest-asyncio
, pytest-benchmark
, pytest-sugar
, pytestCheckHook
, pythonOlder
, pythonAtLeast
, sanic-routing
, sanic-testing
, ujson
, uvicorn
, uvloop
, websockets
}:

buildPythonPackage rec {
  pname = "sanic";
  version = "21.12.1";
  format = "setuptools";

  disabled = pythonOlder "3.7" ||
    pythonAtLeast "3.10"; # see GHSA-7p79-6x2v-5h88

  src = fetchFromGitHub {
    owner = "sanic-org";
    repo = pname;
    rev = "v${version}";
    sha256 = "0jyl23q7b7fyqzan97qflkqcvmfpzbxbzv0qgygxasrzh80zx67g";
  };

  postPatch = ''
    # Loosen dependency requirements.
    substituteInPlace setup.py \
      --replace "pytest==6.2.5" "pytest" \
      --replace "gunicorn==20.0.4" "gunicorn" \
      --replace "multidict>=5.0,<6.0" "multidict"

    sed '/pytest-sanic/d' setup.py

    # Patch a request headers test to allow brotli encoding
    # (we build httpx with brotli support, upstream doesn't).
    substituteInPlace tests/test_headers.py \
      --replace "deflate\r\n" "deflate, br\r\n"
  '';

  propagatedBuildInputs = [
    aiofiles
    httptools
    multidict
    sanic-routing
    ujson
    uvloop
    websockets
  ];

  checkInputs = [
    beautifulsoup4
    gunicorn
    pytest-asyncio
    pytest-benchmark
    pytest-sugar
    pytestCheckHook
    sanic-testing
    uvicorn
  ];

  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
  '';

  # uvloop usage is buggy
  #SANIC_NO_UVLOOP = true;

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

  disabledTests = [
    # Lack of uvloop setup through fixtures
    "test_create_asyncio_server"
    "test_listeners_triggered_async"
    "test_tls_options"
    # Tests are flaky
    "test_keep_alive_client_timeout"
    "test_check_timeouts_request_timeout"
    "test_check_timeouts_response_timeout"
    "test_reloader_live"
    "test_zero_downtime"
    # Not working from 21.9.1
    "test_create_server_main"
    "test_create_server_main_convenience"
    "test_debug"
    "test_auto_reload"
    "test_no_exceptions_when_cancel_pending_request"
    "test_ipv6_address_is_not_wrapped"
    # Failure of the redirect tests seems to be related to httpx>0.20.0
    "test_redirect"
    "test_chained_redirect"
    "test_unix_connection"
    # These appear to be very sensitive to output of commands
    "test_access_logs"
    "test_auto_reload"
    "test_host_port"
    "test_no_exceptions_when_cancel_pending_request"
    "test_num_workers"
    "test_server_run"
    "test_version"
    # Sensitive comparison of raw HTTP header fails
    "test_raw_headers"
    # noisy_exceptions sometimes missing from sanic stdout
    "test_noisy_exceptions"
  ] ++ lib.optionals (stdenv.hostPlatform.system == "aarch64-linux") [
    # test fail on aarch64
    "test_tls_wrong_options"
    "test_cookie_expires"
    "test_gunicorn_worker"
    "test_gunicorn_worker_no_logs"
    "test_gunicorn_worker_with_logs"
  ];

  disabledTestPaths = [
    # 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/";
    license = licenses.mit;
    maintainers = with maintainers; [ costrouc AluisioASG ];
  };
}