1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonOlder,
6 fetchPypi,
7 fetchpatch,
8
9 # build-system
10 cython,
11 setuptools,
12
13 # native dependencies
14 libuv,
15
16 # tests
17 psutil,
18 pyopenssl,
19 pytestCheckHook,
20}:
21
22buildPythonPackage rec {
23 pname = "uvloop";
24 version = "0.21.0";
25 pyproject = true;
26
27 disabled = pythonOlder "3.8";
28
29 src = fetchPypi {
30 inherit pname version;
31 hash = "sha256-O/ErD9poRHgGp62Ee/pZFhMXcnXTW2ckse5XP6o3BOM=";
32 };
33
34 patches = [
35 # fix test failures on Python 3.13
36 # (remove on next update)
37 (fetchpatch {
38 url = "https://github.com/MagicStack/uvloop/commit/96b7ed31afaf02800d779a395591da6a2c8c50e1.patch";
39 hash = "sha256-Nbe3BuIuwlylll5fIYij+OiP90ZeFNI0GKHK9SwWRk8=";
40 excludes = [ ".github/workflows/tests.yml" ];
41 })
42 (fetchpatch {
43 url = "https://github.com/MagicStack/uvloop/commit/56807922f847ddac231a53d5b03eef70092b987c.patch";
44 hash = "sha256-X5Ob1t/CRy9csw2JrWvwS55G6qTqZhIuGLTy83O03GU=";
45 })
46 ];
47
48 postPatch = ''
49 rm -rf vendor
50
51 substituteInPlace setup.py \
52 --replace-fail "use_system_libuv = False" "use_system_libuv = True"
53 '';
54
55 build-system = [
56 cython
57 setuptools
58 ];
59
60 env.LIBUV_CONFIGURE_HOST = stdenv.hostPlatform.config;
61
62 buildInputs = [ libuv ];
63
64 nativeCheckInputs = [
65 pyopenssl
66 pytestCheckHook
67 psutil
68 ];
69
70 pytestFlagsArray =
71 [
72 # Tries to run "env", but fails to find it, even with coreutils provided
73 "--deselect=tests/test_process.py::Test_UV_Process::test_process_env_2"
74 "--deselect=tests/test_process.py::Test_AIO_Process::test_process_env_2"
75 # AssertionError: b'' != b'out\n'
76 "--deselect=tests/test_process.py::Test_UV_Process::test_process_streams_redirect"
77 "--deselect=tests/test_process.py::Test_AIO_Process::test_process_streams_redirect"
78 # Depends on performance of builder
79 "--deselect=tests/test_base.py::TestBaseUV.test_call_at"
80 # Pointless and flaky (at least on darwin, depending on the sandbox perhaps)
81 "--deselect=tests/test_dns.py"
82 ]
83 ++ lib.optionals (pythonOlder "3.11") [
84 "--deselect=tests/test_tcp.py::Test_UV_TCPSSL::test_create_connection_ssl_failed_certificat"
85 ]
86 ++ lib.optionals (stdenv.hostPlatform.isDarwin) [
87 # Segmentation fault
88 "--deselect=tests/test_fs_event.py::Test_UV_FS_EVENT_RENAME::test_fs_event_rename"
89 # Broken: https://github.com/NixOS/nixpkgs/issues/160904
90 "--deselect=tests/test_context.py::Test_UV_Context::test_create_ssl_server_manual_connection_lost"
91 ];
92
93 disabledTestPaths = [
94 # ignore code linting tests
95 "tests/test_sourcecode.py"
96 ];
97
98 preCheck =
99 ''
100 # force using installed/compiled uvloop
101 rm -rf uvloop
102 ''
103 + lib.optionalString stdenv.hostPlatform.isDarwin ''
104 # Work around "OSError: AF_UNIX path too long"
105 # https://github.com/MagicStack/uvloop/issues/463
106 export TMPDIR="/tmp"
107 '';
108
109 pythonImportsCheck = [
110 "uvloop"
111 "uvloop.loop"
112 ];
113
114 # Some of the tests use localhost networking.
115 __darwinAllowLocalNetworking = true;
116
117 meta = with lib; {
118 changelog = "https://github.com/MagicStack/uvloop/releases/tag/v${version}";
119 description = "Fast implementation of asyncio event loop on top of libuv";
120 homepage = "https://github.com/MagicStack/uvloop";
121 license = licenses.mit;
122 maintainers = [ ];
123 };
124}