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