1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 unittestCheckHook,
7 pythonAtLeast,
8 pythonOlder,
9 setuptools,
10 werkzeug,
11}:
12
13buildPythonPackage rec {
14 pname = "websockets";
15 version = "15.0.1";
16 pyproject = true;
17
18 disabled = pythonOlder "3.9";
19
20 src = fetchFromGitHub {
21 owner = "aaugustin";
22 repo = "websockets";
23 tag = version;
24 hash = "sha256-DC1nK+TvCoCqchyWJOyT4Ul4gkTYXixu7XmTqvytqEo=";
25 };
26
27 build-system = [ setuptools ];
28
29 disabledTests =
30 [
31 # Disables tests relying on tight timeouts to avoid failures like:
32 # File "/build/source/tests/legacy/test_protocol.py", line 1270, in test_keepalive_ping_with_no_ping_timeout
33 # ping_1_again, ping_2 = tuple(self.protocol.pings)
34 # ValueError: too many values to unpack (expected 2)
35 "test_keepalive_ping_stops_when_connection_closing"
36 "test_keepalive_ping_does_not_crash_when_connection_lost"
37 "test_keepalive_ping"
38 "test_keepalive_ping_not_acknowledged_closes_connection"
39 "test_keepalive_ping_with_no_ping_timeout"
40 ]
41 ++ lib.optionals (pythonAtLeast "3.13") [
42 # https://github.com/python-websockets/websockets/issues/1569
43 "test_writing_in_send_context_fails"
44 ]
45 ++ lib.optionals (pythonOlder "3.11") [
46 # Our Python 3.10 and older raise SSLError instead of SSLCertVerificationError
47 "test_reject_invalid_server_certificate"
48 ];
49
50 nativeCheckInputs = [
51 unittestCheckHook
52 werkzeug
53 ];
54
55 preCheck = ''
56 # https://github.com/python-websockets/websockets/issues/1509
57 export WEBSOCKETS_TESTS_TIMEOUT_FACTOR=100
58 # Disable all tests that need to terminate within a predetermined amount of
59 # time. This is nondeterministic.
60 sed -i 's/with self.assertCompletesWithin.*:/if True:/' \
61 tests/legacy/test_protocol.py
62 '';
63
64 # Tests fail on Darwin with `OSError: AF_UNIX path too long`
65 doCheck = !stdenv.hostPlatform.isDarwin;
66
67 pythonImportsCheck = [ "websockets" ];
68
69 meta = with lib; {
70 description = "WebSocket implementation in Python";
71 homepage = "https://websockets.readthedocs.io/";
72 changelog = "https://github.com/aaugustin/websockets/blob/${src.tag}/docs/project/changelog.rst";
73 license = licenses.bsd3;
74 maintainers = with maintainers; [ fab ];
75 };
76}