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