1{ lib
2, stdenv
3, buildPythonPackage
4, pythonOlder
5, fetchPypi
6, fetchpatch
7, python
8
9# build-system
10, hatchling
11, hatch-fancy-pypi-readme
12
13# dependencies
14, attrs
15, automat
16, constantly
17, hyperlink
18, incremental
19, typing-extensions
20, zope_interface
21
22# optional-dependencies
23, appdirs
24, bcrypt
25, cryptography
26, h2
27, idna
28, priority
29, pyasn1
30, pyopenssl
31, pyserial
32, service-identity
33
34# tests
35, cython-test-exception-raiser
36, git
37, glibcLocales
38, pyhamcrest
39, hypothesis
40
41 # for passthru.tests
42, cassandra-driver
43, klein
44, magic-wormhole
45, scrapy
46, treq
47, txaio
48, txamqp
49, txrequests
50, txtorcon
51, thrift
52, nixosTests
53}:
54
55buildPythonPackage rec {
56 pname = "twisted";
57 version = "23.8.0";
58 format = "pyproject";
59
60 disabled = pythonOlder "3.6";
61
62 src = fetchPypi {
63 inherit pname version;
64 extension = "tar.gz";
65 hash = "sha256-PHM2Ct0XM2piLA2BHCos4phmtuWbESX9ZQmxclIJiiQ=";
66 };
67
68 patches = [
69 (fetchpatch {
70 name = "11787.diff";
71 url = "https://github.com/twisted/twisted/commit/da3bf3dc29f067e7019b2a1c205834ab64b2139a.diff";
72 hash = "sha256-bQgUmbvDa61Vg8p/o/ivfkOAHyj1lTgHkrRVEGLM9aU=";
73 })
74 (fetchpatch {
75 # Conditionally skip tests that require METHOD_CRYPT
76 # https://github.com/twisted/twisted/pull/11827
77 url = "https://github.com/mweinelt/twisted/commit/e69e652de671aac0abf5c7e6c662fc5172758c5a.patch";
78 hash = "sha256-LmvKUTViZoY/TPBmSlx4S9FbJNZfB5cxzn/YcciDmoI=";
79 })
80 ];
81
82 __darwinAllowLocalNetworking = true;
83
84 nativeBuildInputs = [
85 hatchling
86 hatch-fancy-pypi-readme
87 incremental
88 ];
89
90 propagatedBuildInputs = [
91 attrs
92 automat
93 constantly
94 hyperlink
95 incremental
96 typing-extensions
97 zope_interface
98 ];
99
100 postPatch = ''
101 echo 'ListingTests.test_localeIndependent.skip = "Timezone issue"'>> src/twisted/conch/test/test_cftp.py
102 echo 'ListingTests.test_newFile.skip = "Timezone issue"'>> src/twisted/conch/test/test_cftp.py
103 echo 'ListingTests.test_newSingleDigitDayOfMonth.skip = "Timezone issue"'>> src/twisted/conch/test/test_cftp.py
104 echo 'ListingTests.test_oldFile.skip = "Timezone issue"'>> src/twisted/conch/test/test_cftp.py
105 echo 'ListingTests.test_oldSingleDigitDayOfMonth.skip = "Timezone issue"'>> src/twisted/conch/test/test_cftp.py
106
107 echo 'WrapClientTLSParserTests.test_tls.skip = "pyopenssl update"' >> src/twisted/internet/test/test_endpoints.py
108 echo 'UNIXTestsBuilder_AsyncioSelectorReactorTests.test_sendFileDescriptorTriggersPauseProducing.skip = "sendFileDescriptor producer was not paused"'>> src/twisted/internet/test/test_unix.py
109 echo 'UNIXTestsBuilder_SelectReactorTests.test_sendFileDescriptorTriggersPauseProducing.skip = "sendFileDescriptor producer was not paused"'>> src/twisted/internet/test/test_unix.py
110
111 echo 'FileObserverTests.test_getTimezoneOffsetEastOfUTC.skip = "mktime argument out of range"'>> src/twisted/test/test_log.py
112 echo 'FileObserverTests.test_getTimezoneOffsetWestOfUTC.skip = "mktime argument out of range"'>> src/twisted/test/test_log.py
113 echo 'FileObserverTests.test_getTimezoneOffsetWithoutDaylightSavingTime.skip = "tuple differs, values not"'>> src/twisted/test/test_log.py
114
115 echo 'MulticastTests.test_joinLeave.skip = "No such device"'>> src/twisted/test/test_udp.py
116 echo 'MulticastTests.test_loopback.skip = "No such device"'>> src/twisted/test/test_udp.py
117 echo 'MulticastTests.test_multicast.skip = "Reactor was unclean"'>> src/twisted/test/test_udp.py
118 echo 'MulticastTests.test_multiListen.skip = "No such device"'>> src/twisted/test/test_udp.py
119
120 # fails since migrating to libxcrypt
121 echo 'HelperTests.test_refuteCryptedPassword.skip = "OSError: Invalid argument"' >> src/twisted/conch/test/test_checkers.py
122
123 # expectation mismatch with `python -m twisted --help` and `python -m twisted.trial --help` usage output
124 echo 'MainTests.test_twisted.skip = "Expectation Mismatch"' >> src/twisted/test/test_main.py
125 echo 'MainTests.test_trial.skip = "Expectation Mismatch"' >> src/twisted/test/test_main.py
126
127 # tests for missing https support in usage
128 echo 'ServiceTests.test_HTTPSFailureOnMissingSSL.skip = "Expectation Mismatch"' >> src/twisted/web/test/test_tap.py
129
130 # not packaged
131 substituteInPlace src/twisted/test/test_failure.py \
132 --replace "from cython_test_exception_raiser import raiser # type: ignore[import]" "raiser = None"
133 '' + lib.optionalString stdenv.isLinux ''
134 echo 'PTYProcessTestsBuilder_EPollReactorTests.test_openFileDescriptors.skip = "invalid syntax"'>> src/twisted/internet/test/test_process.py
135 echo 'PTYProcessTestsBuilder_PollReactorTests.test_openFileDescriptors.skip = "invalid syntax"'>> src/twisted/internet/test/test_process.py
136 echo 'UNIXTestsBuilder_EPollReactorTests.test_sendFileDescriptorTriggersPauseProducing.skip = "sendFileDescriptor producer was not paused"'>> src/twisted/internet/test/test_unix.py
137 echo 'UNIXTestsBuilder_PollReactorTests.test_sendFileDescriptorTriggersPauseProducing.skip = "sendFileDescriptor producer was not paused"'>> src/twisted/internet/test/test_unix.py
138
139 # Patch t.p._inotify to point to libc. Without this,
140 # twisted.python.runtime.platform.supportsINotify() == False
141 substituteInPlace src/twisted/python/_inotify.py --replace \
142 "ctypes.util.find_library(\"c\")" "'${stdenv.cc.libc}/lib/libc.so.6'"
143 '' + lib.optionalString stdenv.isDarwin ''
144 echo 'ProcessTestsBuilder_AsyncioSelectorReactorTests.test_openFileDescriptors.skip = "invalid syntax"'>> src/twisted/internet/test/test_process.py
145 echo 'ProcessTestsBuilder_SelectReactorTests.test_openFileDescriptors.skip = "invalid syntax"'>> src/twisted/internet/test/test_process.py
146 '';
147
148 # Generate Twisted's plug-in cache. Twisted users must do it as well. See
149 # http://twistedmatrix.com/documents/current/core/howto/plugin.html#auto3
150 # and http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=477103 for details.
151 postFixup = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
152 $out/bin/twistd --help > /dev/null
153 '';
154
155 nativeCheckInputs = [
156 cython-test-exception-raiser
157 git
158 glibcLocales
159 hypothesis
160 pyhamcrest
161 ]
162 ++ passthru.optional-dependencies.conch
163 ++ passthru.optional-dependencies.http2
164 ++ passthru.optional-dependencies.serial
165 # not supported on aarch64-darwin: https://github.com/pyca/pyopenssl/issues/873
166 ++ lib.optionals (!(stdenv.isDarwin && stdenv.isAarch64)) passthru.optional-dependencies.tls;
167
168 checkPhase = ''
169 export SOURCE_DATE_EPOCH=315532800
170 export PATH=$out/bin:$PATH
171 # race conditions when running in paralell
172 ${python.interpreter} -m twisted.trial -j1 twisted
173 '';
174
175 passthru = {
176 optional-dependencies = {
177 conch = [ appdirs bcrypt cryptography pyasn1 ];
178 http2 = [ h2 priority ];
179 serial = [ pyserial ];
180 tls = [ idna pyopenssl service-identity ];
181 };
182
183 tests = {
184 inherit
185 cassandra-driver
186 klein
187 magic-wormhole
188 scrapy
189 treq
190 txaio
191 txamqp
192 txrequests
193 txtorcon
194 thrift;
195 inherit (nixosTests) buildbot matrix-synapse;
196 };
197 };
198
199 meta = with lib; {
200 homepage = "https://github.com/twisted/twisted";
201 description = "Asynchronous networking framework written in Python";
202 license = licenses.mit;
203 maintainers = with maintainers; [ ];
204 };
205}