summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/twisted/default.nix
blob: 316a281a106fbf411ea4e55c3ef4ebbfe3f54800 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
{
  lib,
  stdenv,
  buildPythonPackage,
  pythonAtLeast,
  pythonOlder,
  fetchPypi,
  fetchpatch,
  python,

  # build-system
  hatchling,
  hatch-fancy-pypi-readme,

  # dependencies
  attrs,
  automat,
  constantly,
  hyperlink,
  incremental,
  typing-extensions,
  zope-interface,

  # optional-dependencies
  appdirs,
  bcrypt,
  cryptography,
  h2,
  idna,
  priority,
  pyopenssl,
  pyserial,
  service-identity,

  # tests
  cython-test-exception-raiser,
  gitMinimal,
  glibcLocales,
  pyhamcrest,
  hypothesis,

  # for passthru.tests
  cassandra-driver,
  httpx,
  klein,
  magic-wormhole,
  scrapy,
  treq,
  txaio,
  txamqp,
  txrequests,
  txtorcon,
  thrift,
  nixosTests,
}:

buildPythonPackage rec {
  pname = "twisted";
  version = "25.5.0";
  pyproject = true;

  src = fetchPypi {
    inherit pname version;
    extension = "tar.gz";
    hash = "sha256-HesnI1jLa+Hj6PxvnIs2946w+nwiM9Lb4R7G/uBOoxY=";
  };

  patches = [
    (fetchpatch {
      # https://github.com/twisted/twisted/pull/12508
      url = "https://github.com/twisted/twisted/commit/ef6160aa2595adfba0c71da6db65b7a7252f23e9.patch";
      hash = "sha256-zHkEWT0lvWf86RlkzU5Wx6R5ear04cfpxB7wjgdpw5c=";
    })
    # https://github.com/twisted/twisted/pull/12511
    ./python314-urljoin-compat.patch
    (fetchpatch {
      # https://github.com/twisted/twisted/pull/12551
      url = "https://github.com/twisted/twisted/commit/b1173fa307a9752eedd63890113eb610c3cca4a0.patch";
      hash = "sha256-DWEygdo1b8uQOeFLy0/zcRNuuKJdSsF7cQM7RH04Puw=";
    })
  ];

  __darwinAllowLocalNetworking = true;

  build-system = [
    hatchling
    hatch-fancy-pypi-readme
    incremental
  ];

  dependencies = [
    attrs
    automat
    constantly
    hyperlink
    incremental
    typing-extensions
    zope-interface
  ];

  postPatch =
    let
      skippedTests = {
        "src/twisted/conch/test/test_cftp.py" = [
          # timezone issues
          "ListingTests.test_localeIndependent"
          "ListingTests.test_newSingleDigitDayOfMonth"
          "ListingTests.test_oldFile"
          "ListingTests.test_oldSingleDigitDayOfMonth"
          "ListingTests.test_newFile"
        ];
        "src/twisted/test/test_log.py" = [
          # wrong timezone offset calculation
          "FileObserverTests.test_getTimezoneOffsetEastOfUTC"
          "FileObserverTests.test_getTimezoneOffsetWestOfUTC"
          "FileObserverTests.test_getTimezoneOffsetWithoutDaylightSavingTime"
        ];
        "src/twisted/test/test_udp.py" = [
          # "No such device" (No multicast support in the build sandbox)
          "MulticastTests.test_joinLeave"
          "MulticastTests.test_loopback"
          "MulticastTests.test_multicast"
          "MulticastTests.test_multiListen"
        ];
        "src/twisted/trial/test/test_script.py" = [
          # Fails in LXC containers with less than all cores available (limits.cpu)
          "AutoJobsTests.test_cpuCount"
        ];
        "src/twisted/internet/test/test_unix.py" = [
          # flaky?
          "UNIXTestsBuilder.test_sendFileDescriptorTriggersPauseProducing"
        ];
      }
      // lib.optionalAttrs (pythonAtLeast "3.12") {
        "src/twisted/trial/_dist/test/test_workerreporter.py" = [
          "WorkerReporterTests.test_addSkipPyunit"
        ];
        "src/twisted/trial/_dist/test/test_worker.py" = [
          "LocalWorkerAMPTests.test_runSkip"
        ];
      }
      // lib.optionalAttrs (pythonOlder "3.13") {
        # missing ciphers in the crypt module due to libxcrypt
        "src/twisted/web/test/test_tap.py" = [
          "ServiceTests.test_HTTPSFailureOnMissingSSL"
          "ServiceTests.test_HTTPSFailureOnMissingSSL"
        ];
        "src/twisted/conch/test/test_checkers.py" = [
          "HelperTests.test_refuteCryptedPassword"
          "HelperTests.test_verifyCryptedPassword"
          "HelperTests.test_verifyCryptedPasswordMD5"
          "UNIXPasswordDatabaseTests.test_defaultCheckers"
          "UNIXPasswordDatabaseTests.test_passInCheckers"
        ];
        "src/twisted/cred/test/test_strcred.py" = [
          "UnixCheckerTests.test_isChecker"
          "UnixCheckerTests.test_unixCheckerFailsPassword"
          "UnixCheckerTests.test_unixCheckerFailsPasswordBytes"
          "UnixCheckerTests.test_unixCheckerFailsUsername"
          "UnixCheckerTests.test_unixCheckerFailsUsernameBytes"
          "UnixCheckerTests.test_unixCheckerSucceeds"
          "UnixCheckerTests.test_unixCheckerSucceedsBytes"
          "CryptTests.test_verifyCryptedPassword"
          "CryptTests.test_verifyCryptedPasswordOSError"
        ];
        # dependant on UnixCheckerTests.test_isChecker
        "src/twisted/cred/test/test_cred.py" = [
          "HashedPasswordOnDiskDatabaseTests.testBadCredentials"
          "HashedPasswordOnDiskDatabaseTests.testGoodCredentials"
          "HashedPasswordOnDiskDatabaseTests.testGoodCredentials_login"
          "HashedPasswordOnDiskDatabaseTests.testHashedCredentials"
        ];
      }
      // lib.optionalAttrs (pythonAtLeast "3.13") {
        "src/twisted/web/test/test_flatten.py" = [
          "FlattenerErrorTests.test_asynchronousFlattenError"
          "FlattenerErrorTests.test_cancel"
        ];
      }
      // lib.optionalAttrs stdenv.hostPlatform.isDarwin {
        "src/twisted/internet/test/test_process.py" = [
          # invalid syntaax
          "ProcessTestsBuilder_AsyncioSelectorReactorTests.test_openFileDescriptors"
          "ProcessTestsBuilder_SelectReactorTests.test_openFileDescriptors"
          # exit code 120
          "ProcessTestsBuilder_AsyncioSelectorReactorTests.test_processEnded"
          "ProcessTestsBuilder_SelectReactorTests.test_processEnded"
        ];
        "src/twisted/internet/test/test_tcp.py" = [
          # marked as flaky on macOS by upstream
          # https://github.com/twisted/twisted/blob/twisted-25.5.0/src/twisted/internet/test/test_tcp.py
          "AbortConnectionTests_AsyncioSelectorReactorTests.test_resumeProducingAbort"
          "AbortConnectionTests_AsyncioSelectorReactorTests.test_resumeProducingAbortLater"
        ];
      };
    in
    lib.concatStringsSep "\n" (
      lib.mapAttrsToList (
        file: tests: lib.concatMapStringsSep "\n" (test: ''echo '${test}.skip = ""' >> "${file}"'') tests
      ) skippedTests
    )
    + lib.optionalString stdenv.hostPlatform.isLinux ''
      # Patch t.p._inotify to point to libc. Without this,
      # twisted.python.runtime.platform.supportsINotify() == False
      substituteInPlace src/twisted/python/_inotify.py --replace-fail \
        "ctypes.util.find_library(\"c\")" "'${stdenv.cc.libc}/lib/libc.so.6'"
    '';

  # Generate Twisted's plug-in cache. Twisted users must do it as well. See
  # http://twistedmatrix.com/documents/current/core/howto/plugin.html#auto3
  # and http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=477103 for details.
  postFixup = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
    $out/bin/twistd --help > /dev/null
  '';

  nativeCheckInputs = [
    gitMinimal
    glibcLocales
  ]
  ++ optional-dependencies.test
  ++ optional-dependencies.conch
  ++ optional-dependencies.http2
  ++ optional-dependencies.serial
  ++ optional-dependencies.tls;

  preCheck = ''
    export SOURCE_DATE_EPOCH=315532800
    export PATH=$out/bin:$PATH
  '';

  checkPhase = ''
    runHook preCheck
    # race conditions when running in paralell
    ${python.interpreter} -m twisted.trial -j1 twisted
    runHook postCheck
  '';

  optional-dependencies = {
    conch = [
      appdirs
      bcrypt
      cryptography
    ];
    http2 = [
      h2
      priority
    ];
    serial = [ pyserial ];
    test = [
      cython-test-exception-raiser
      pyhamcrest
      hypothesis
      httpx
    ]
    ++ httpx.optional-dependencies.http2;
    tls = [
      idna
      pyopenssl
      service-identity
    ];
  };

  passthru = {
    tests = {
      inherit
        cassandra-driver
        klein
        magic-wormhole
        scrapy
        treq
        txaio
        txamqp
        txrequests
        txtorcon
        thrift
        ;
      inherit (nixosTests) buildbot matrix-synapse;
    };
  };

  meta = {
    changelog = "https://github.com/twisted/twisted/blob/twisted-${version}/NEWS.rst";
    homepage = "https://github.com/twisted/twisted";
    description = "Asynchronous networking framework written in Python";
    license = lib.licenses.mit;
    maintainers = [ ];
  };
}