1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonAtLeast,
6 pythonOlder,
7 fetchPypi,
8 python,
9
10 # build-system
11 hatchling,
12 hatch-fancy-pypi-readme,
13
14 # dependencies
15 attrs,
16 automat,
17 constantly,
18 hyperlink,
19 incremental,
20 typing-extensions,
21 zope-interface,
22
23 # optional-dependencies
24 appdirs,
25 bcrypt,
26 cryptography,
27 h2,
28 idna,
29 priority,
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 httpx,
44 klein,
45 magic-wormhole,
46 scrapy,
47 treq,
48 txaio,
49 txamqp,
50 txrequests,
51 txtorcon,
52 thrift,
53 nixosTests,
54}:
55
56buildPythonPackage rec {
57 pname = "twisted";
58 version = "24.11.0";
59 format = "pyproject";
60
61 disabled = pythonOlder "3.6";
62
63 src = fetchPypi {
64 inherit pname version;
65 extension = "tar.gz";
66 hash = "sha256-aV0FVtXsV53MRk0oVrY0iA7RMZ9FsQ0ZBD8rV+sBFbU=";
67 };
68
69 __darwinAllowLocalNetworking = true;
70
71 nativeBuildInputs = [
72 hatchling
73 hatch-fancy-pypi-readme
74 incremental
75 ];
76
77 propagatedBuildInputs = [
78 attrs
79 automat
80 constantly
81 hyperlink
82 incremental
83 typing-extensions
84 zope-interface
85 ];
86
87 postPatch =
88 let
89 skippedTests =
90 {
91 "src/twisted/conch/test/test_cftp.py" = [
92 # timezone issues
93 "ListingTests.test_localeIndependent"
94 "ListingTests.test_newSingleDigitDayOfMonth"
95 "ListingTests.test_oldFile"
96 "ListingTests.test_oldSingleDigitDayOfMonth"
97 "ListingTests.test_newFile"
98 ];
99 "src/twisted/test/test_log.py" = [
100 # wrong timezone offset calculation
101 "FileObserverTests.test_getTimezoneOffsetEastOfUTC"
102 "FileObserverTests.test_getTimezoneOffsetWestOfUTC"
103 "FileObserverTests.test_getTimezoneOffsetWithoutDaylightSavingTime"
104 ];
105 "src/twisted/test/test_udp.py" = [
106 # "No such device" (No multicast support in the build sandbox)
107 "MulticastTests.test_joinLeave"
108 "MulticastTests.test_loopback"
109 "MulticastTests.test_multicast"
110 "MulticastTests.test_multiListen"
111 ];
112 "src/twisted/trial/test/test_script.py" = [
113 # Fails in LXC containers with less than all cores availaible (limits.cpu)
114 "AutoJobsTests.test_cpuCount"
115 ];
116 "src/twisted/internet/test/test_unix.py" = [
117 # flaky?
118 "UNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing"
119 ];
120 }
121 // lib.optionalAttrs (pythonAtLeast "3.12") {
122 "src/twisted/trial/_dist/test/test_workerreporter.py" = [
123 "WorkerReporterTests.test_addSkipPyunit"
124 ];
125 "src/twisted/trial/_dist/test/test_worker.py" = [
126 "LocalWorkerAMPTests.test_runSkip"
127 ];
128 }
129 // lib.optionalAttrs (pythonOlder "3.13") {
130 # missing ciphers in the crypt module due to libxcrypt
131 "src/twisted/web/test/test_tap.py" = [
132 "ServiceTests.test_HTTPSFailureOnMissingSSL"
133 "ServiceTests.test_HTTPSFailureOnMissingSSL"
134 ];
135 "src/twisted/conch/test/test_checkers.py" = [
136 "HelperTests.test_refuteCryptedPassword"
137 "HelperTests.test_verifyCryptedPassword"
138 "HelperTests.test_verifyCryptedPasswordMD5"
139 "UNIXPasswordDatabaseTests.test_defaultCheckers"
140 "UNIXPasswordDatabaseTests.test_passInCheckers"
141 ];
142 "src/twisted/cred/test/test_strcred.py" = [
143 "UnixCheckerTests.test_isChecker"
144 "UnixCheckerTests.test_unixCheckerFailsPassword"
145 "UnixCheckerTests.test_unixCheckerFailsPasswordBytes"
146 "UnixCheckerTests.test_unixCheckerFailsUsername"
147 "UnixCheckerTests.test_unixCheckerFailsUsernameBytes"
148 "UnixCheckerTests.test_unixCheckerSucceeds"
149 "UnixCheckerTests.test_unixCheckerSucceedsBytes"
150 "CryptTests.test_verifyCryptedPassword"
151 "CryptTests.test_verifyCryptedPasswordOSError"
152 ];
153 # dependant on UnixCheckerTests.test_isChecker
154 "src/twisted/cred/test/test_cred.py" = [
155 "HashedPasswordOnDiskDatabaseTests.testBadCredentials"
156 "HashedPasswordOnDiskDatabaseTests.testGoodCredentials"
157 "HashedPasswordOnDiskDatabaseTests.testGoodCredentials_login"
158 "HashedPasswordOnDiskDatabaseTests.testHashedCredentials"
159 ];
160 }
161 // lib.optionalAttrs (pythonAtLeast "3.13") {
162 "src/twisted/web/test/test_flatten.py" = [
163 "FlattenerErrorTests.test_asynchronousFlattenError"
164 "FlattenerErrorTests.test_cancel"
165 ];
166 }
167 // lib.optionalAttrs stdenv.hostPlatform.isDarwin {
168 "src/twisted/internet/test/test_process.py" = [
169 # invalid syntaax
170 "ProcessTestsBuilder_AsyncioSelectorReactorTests.test_openFileDescriptors"
171 "ProcessTestsBuilder_SelectReactorTests.test_openFileDescriptors"
172 # exit code 120
173 "ProcessTestsBuilder_AsyncioSelectorReactorTests.test_processEnded"
174 "ProcessTestsBuilder_SelectReactorTests.test_processEnded"
175 ];
176 };
177 in
178 lib.concatStringsSep "\n" (
179 lib.mapAttrsToList (
180 file: tests: lib.concatMapStringsSep "\n" (test: ''echo '${test}.skip = ""' >> "${file}"'') tests
181 ) skippedTests
182 )
183 + lib.optionalString stdenv.hostPlatform.isLinux ''
184 # Patch t.p._inotify to point to libc. Without this,
185 # twisted.python.runtime.platform.supportsINotify() == False
186 substituteInPlace src/twisted/python/_inotify.py --replace-fail \
187 "ctypes.util.find_library(\"c\")" "'${stdenv.cc.libc}/lib/libc.so.6'"
188 '';
189
190 # Generate Twisted's plug-in cache. Twisted users must do it as well. See
191 # http://twistedmatrix.com/documents/current/core/howto/plugin.html#auto3
192 # and http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=477103 for details.
193 postFixup = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
194 $out/bin/twistd --help > /dev/null
195 '';
196
197 nativeCheckInputs =
198 [
199 git
200 glibcLocales
201 ]
202 ++ optional-dependencies.test
203 ++ optional-dependencies.conch
204 ++ optional-dependencies.http2
205 ++ optional-dependencies.serial
206 ++ optional-dependencies.tls;
207
208 preCheck = ''
209 export SOURCE_DATE_EPOCH=315532800
210 export PATH=$out/bin:$PATH
211 '';
212
213 checkPhase = ''
214 runHook preCheck
215 # race conditions when running in paralell
216 ${python.interpreter} -m twisted.trial -j1 twisted
217 runHook postCheck
218 '';
219
220 optional-dependencies = {
221 conch = [
222 appdirs
223 bcrypt
224 cryptography
225 ];
226 http2 = [
227 h2
228 priority
229 ];
230 serial = [ pyserial ];
231 test = [
232 cython-test-exception-raiser
233 pyhamcrest
234 hypothesis
235 httpx
236 ] ++ httpx.optional-dependencies.http2;
237 tls = [
238 idna
239 pyopenssl
240 service-identity
241 ];
242 };
243
244 passthru = {
245 tests = {
246 inherit
247 cassandra-driver
248 klein
249 magic-wormhole
250 scrapy
251 treq
252 txaio
253 txamqp
254 txrequests
255 txtorcon
256 thrift
257 ;
258 inherit (nixosTests) buildbot matrix-synapse;
259 };
260 };
261
262 meta = with lib; {
263 changelog = "https://github.com/twisted/twisted/blob/twisted-${version}/NEWS.rst";
264 homepage = "https://github.com/twisted/twisted";
265 description = "Asynchronous networking framework written in Python";
266 license = licenses.mit;
267 maintainers = [ ];
268 };
269}