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