1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonOlder,
6 fetchPypi,
7
8 # build-system
9 cython,
10 setuptools,
11
12 # native dependencies
13 libuv,
14 CoreServices,
15 ApplicationServices,
16
17 # tests
18 psutil,
19 pyopenssl,
20 pytestCheckHook,
21}:
22
23buildPythonPackage rec {
24 pname = "uvloop";
25 version = "0.21.0";
26 pyproject = true;
27
28 disabled = pythonOlder "3.8";
29
30 src = fetchPypi {
31 inherit pname version;
32 hash = "sha256-O/ErD9poRHgGp62Ee/pZFhMXcnXTW2ckse5XP6o3BOM=";
33 };
34
35 build-system = [
36 cython
37 setuptools
38 ];
39
40 env.LIBUV_CONFIGURE_HOST = stdenv.hostPlatform.config;
41
42 buildInputs =
43 [ libuv ]
44 ++ lib.optionals stdenv.hostPlatform.isDarwin [
45 CoreServices
46 ApplicationServices
47 ];
48
49 nativeCheckInputs = [
50 pyopenssl
51 pytestCheckHook
52 psutil
53 ];
54
55 pytestFlagsArray =
56 [
57 # Tries to run "env", but fails to find it, even with coreutils provided
58 "--deselect=tests/test_process.py::Test_UV_Process::test_process_env_2"
59 "--deselect=tests/test_process.py::Test_AIO_Process::test_process_env_2"
60 # AssertionError: b'' != b'out\n'
61 "--deselect=tests/test_process.py::Test_UV_Process::test_process_streams_redirect"
62 "--deselect=tests/test_process.py::Test_AIO_Process::test_process_streams_redirect"
63 ]
64 ++ lib.optionals (pythonOlder "3.11") [
65 "--deselect=tests/test_tcp.py::Test_UV_TCPSSL::test_create_connection_ssl_failed_certificat"
66 ]
67 ++ lib.optionals (stdenv.hostPlatform.isDarwin) [
68 # Segmentation fault
69 "--deselect=tests/test_fs_event.py::Test_UV_FS_EVENT_RENAME::test_fs_event_rename"
70 # Broken: https://github.com/NixOS/nixpkgs/issues/160904
71 "--deselect=tests/test_context.py::Test_UV_Context::test_create_ssl_server_manual_connection_lost"
72 ];
73
74 disabledTestPaths = [
75 # ignore code linting tests
76 "tests/test_sourcecode.py"
77 ];
78
79 preCheck =
80 ''
81 # force using installed/compiled uvloop
82 rm -rf uvloop
83 ''
84 + lib.optionalString stdenv.hostPlatform.isDarwin ''
85 # Work around "OSError: AF_UNIX path too long"
86 # https://github.com/MagicStack/uvloop/issues/463
87 export TMPDIR="/tmp"
88 '';
89
90 pythonImportsCheck = [
91 "uvloop"
92 "uvloop.loop"
93 ];
94
95 # Some of the tests use localhost networking.
96 __darwinAllowLocalNetworking = true;
97
98 meta = with lib; {
99 changelog = "https://github.com/MagicStack/uvloop/releases/tag/v${version}";
100 description = "Fast implementation of asyncio event loop on top of libuv";
101 homepage = "https://github.com/MagicStack/uvloop";
102 license = licenses.mit;
103 maintainers = [ ];
104 };
105}