summary refs log tree commit diff
path: root/pkgs/development/tools/poetry2nix/poetry2nix/overrides.nix
blob: 58a634ee86c905f1bc1d88133344adf0cc5e8587 (plain) (blame)
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
{ pkgs ? import <nixpkgs> { }
, lib ? pkgs.lib
, stdenv ? pkgs.stdenv
}:

self: super:

{
  automat = super.automat.overridePythonAttrs (
    old: rec {
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ self.m2r ];
    }
  );

  aiohttp-swagger3 = super.aiohttp-swagger3.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  ansible = super.ansible.overridePythonAttrs (
    old: {

      prePatch = pkgs.python.pkgs.ansible.prePatch or "";

      postInstall = pkgs.python.pkgs.ansible.postInstall or "";

      # Inputs copied from nixpkgs as ansible doesn't specify it's dependencies
      # in a correct manner.
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [
        self.pycrypto
        self.paramiko
        self.jinja2
        self.pyyaml
        self.httplib2
        self.six
        self.netaddr
        self.dnspython
        self.jmespath
        self.dopy
        self.ncclient
      ];
    }
  );

  ansible-lint = super.ansible-lint.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.setuptools-scm-git-archive ];
      preBuild = ''
        export HOME=$(mktemp -d)
      '';
    }
  );

  anyio = super.anyio.overridePythonAttrs (old: {
    postPatch = ''
      substituteInPlace setup.py --replace 'setup()' 'setup(version="${old.version}")'
    '';
  });

  astroid = super.astroid.overridePythonAttrs (
    old: rec {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
      doCheck = false;
    }
  );

  av = super.av.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
        pkgs.pkg-config
      ];
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.ffmpeg_4 ];
    }
  );

  bcrypt = super.bcrypt.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.libffi ];
    }
  );

  cairocffi = super.cairocffi.overridePythonAttrs (
    old: {
      inherit (pkgs.python3.pkgs.cairocffi) patches;
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  cairosvg = super.cairosvg.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  celery = super.celery.overridePythonAttrs (old: {
    propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ self.setuptools ];
  });

  cssselect2 = super.cssselect2.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  cffi =
    # cffi is bundled with pypy
    if self.python.implementation == "pypy" then null else
    (
      super.cffi.overridePythonAttrs (
        old: {
          buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.libffi ];
        }
      )
    );

  cftime = super.cftime.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [
        self.cython
      ];
    }
  );

  colour = super.colour.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.d2to1 ];
    }
  );

  configparser = super.configparser.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [
        self.toml
      ];

      postPatch = ''
        substituteInPlace setup.py --replace 'setuptools.setup()' 'setuptools.setup(version="${old.version}")'
      '';
    }
  );

  cryptography = super.cryptography.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ])
        ++ lib.optional (lib.versionAtLeast old.version "3.4") [ self.setuptools-rust ]
        ++ lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) self.python.pythonForBuild.pkgs.cffi;
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.openssl ];
    } // lib.optionalAttrs (lib.versionAtLeast old.version "3.4" && lib.versionOlder old.version "3.5") {
      CRYPTOGRAPHY_DONT_BUILD_RUST = "1";
    }
  );

  daphne = super.daphne.overridePythonAttrs (old: {
    postPatch = ''
      substituteInPlace setup.py --replace 'setup_requires=["pytest-runner"],' ""
    '';
  });

  datadog-lambda = super.datadog-lambda.overridePythonAttrs (old: {
    postPatch = ''
      substituteInPlace setup.py --replace "setuptools==" "setuptools>="
    '';
    buildInputs = (old.buildInputs or [ ]) ++ [ self.setuptools ];
  });

  dcli = super.dcli.overridePythonAttrs (old: {
    propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ self.setuptools ];
  });

  ddtrace = super.ddtrace.overridePythonAttrs (old: {
    buildInputs = (old.buildInputs or [ ]) ++
      (pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.darwin.IOKit ]) ++ [ self.cython ];
  });

  dictdiffer = super.dictdiffer.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ self.setuptools ];
    }
  );

  django = (
    super.django.overridePythonAttrs (
      old: {
        propagatedNativeBuildInputs = (old.propagatedNativeBuildInputs or [ ])
          ++ [ pkgs.gettext self.pytest-runner ];
      }
    )
  );

  django-bakery = super.django-bakery.overridePythonAttrs (
    old: {
      configurePhase = ''
        if ! test -e LICENSE; then
          touch LICENSE
        fi
      '' + (old.configurePhase or "");
    }
  );

  django-cors-headers = super.django-cors-headers.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  django-hijack = super.django-hijack.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  django-prometheus = super.django-prometheus.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  django-rosetta = super.django-rosetta.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  django-stubs-ext = super.django-stubs-ext.overridePythonAttrs (
    old: {
      prePatch = (old.prePatch or "") + "touch ../LICENSE.txt";
    }
  );

  dlib = super.dlib.overridePythonAttrs (
    old: {
      # Parallel building enabled
      inherit (pkgs.python.pkgs.dlib) patches;

      enableParallelBuilding = true;
      dontUseCmakeConfigure = true;

      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ pkgs.dlib.nativeBuildInputs;
      buildInputs = (old.buildInputs or [ ]) ++ pkgs.dlib.buildInputs;
    }
  );

  # Environment markers are not always included (depending on how a dep was defined)
  enum34 = if self.pythonAtLeast "3.4" then null else super.enum34;

  eth-hash = super.eth-hash.overridePythonAttrs {
    preConfigure = ''
      substituteInPlace setup.py --replace \'setuptools-markdown\' ""
    '';
  };

  eth-keyfile = super.eth-keyfile.overridePythonAttrs {
    preConfigure = ''
      substituteInPlace setup.py --replace \'setuptools-markdown\' ""
    '';
  };

  eth-keys = super.eth-keys.overridePythonAttrs {
    preConfigure = ''
      substituteInPlace setup.py --replace \'setuptools-markdown\' ""
    '';
  };

  # remove eth-hash dependency because eth-hash also depends on eth-utils causing a cycle.
  eth-utils = super.eth-utils.overridePythonAttrs (old: {
    propagatedBuildInputs =
      builtins.filter (i: i.pname != "eth-hash") old.propagatedBuildInputs;
    preConfigure = ''
      ${old.preConfigure or ""}
      sed -i '/eth-hash/d' setup.py
    '';
  });

  faker = super.faker.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
      doCheck = false;
    }
  );

  fancycompleter = super.fancycompleter.overridePythonAttrs (
    old: {
      postPatch = ''
        substituteInPlace setup.py \
          --replace 'setup_requires="setupmeta"' 'setup_requires=[]' \
          --replace 'versioning="devcommit"' 'version="${old.version}"'
      '';
    }
  );

  fastecdsa = super.fastecdsa.overridePythonAttrs (old: {
    buildInputs = old.buildInputs ++ [ pkgs.gmp.dev ];
  });

  fastparquet = super.fastparquet.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  fiona = super.fiona.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.gdal_2 ];
      nativeBuildInputs = [
        pkgs.gdal_2 # for gdal-config
      ];
    }
  );

  gdal = super.gdal.overridePythonAttrs (
    old: {
      preBuild = (old.preBuild or "") + ''
        substituteInPlace setup.cfg \
          --replace "../../apps/gdal-config" '${pkgs.gdal}/bin/gdal-config'
      '';
    }
  );

  grandalf = super.grandalf.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
      doCheck = false;
    }
  );

  grpcio = super.grpcio.overridePythonAttrs (old: {
    nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ self.cython pkgs.pkg-config ];
    buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.c-ares pkgs.openssl pkgs.zlib ];

    outputs = [ "out" "dev" ];

    GRPC_BUILD_WITH_BORING_SSL_ASM = "";
    GRPC_PYTHON_BUILD_SYSTEM_OPENSSL = 1;
    GRPC_PYTHON_BUILD_SYSTEM_ZLIB = 1;
    GRPC_PYTHON_BUILD_SYSTEM_CARES = 1;
    DISABLE_LIBC_COMPATIBILITY = 1;
  });

  grpcio-tools = super.grpcio-tools.overridePythonAttrs (old: {
    outputs = [ "out" "dev" ];
  });

  h3 = super.h3.overridePythonAttrs (
    old: {
      preBuild = (old.preBuild or "") + ''
        substituteInPlace h3/h3.py \
          --replace "'{}/{}'.format(_dirname, libh3_path)" '"${pkgs.h3}/lib/libh3${pkgs.stdenv.hostPlatform.extensions.sharedLibrary}"'
      '';
    }
  );

  h5py = super.h5py.overridePythonAttrs (
    old:
    if old.format != "wheel" then
      (
        let
          mpi = pkgs.hdf5.mpi;
          mpiSupport = pkgs.hdf5.mpiSupport;
        in
        {
          nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.pkg-config ];
          buildInputs =
            (old.buildInputs or [ ])
            ++ [ pkgs.hdf5 self.pkgconfig self.cython ]
            ++ lib.optional mpiSupport mpi
          ;
          propagatedBuildInputs =
            (old.propagatedBuildInputs or [ ])
            ++ lib.optionals mpiSupport [ self.mpi4py self.openssh ]
          ;
          preBuild = if mpiSupport then "export CC=${mpi}/bin/mpicc" else "";
          HDF5_DIR = "${pkgs.hdf5}";
          HDF5_MPI = if mpiSupport then "ON" else "OFF";
          # avoid strict pinning of numpy
          postPatch = ''
            substituteInPlace setup.py \
              --replace "numpy ==" "numpy >="
          '';
          pythonImportsCheck = [ "h5py" ];
        }
      ) else old
  );

  hid = super.hid.overridePythonAttrs (
    old: {
      postPatch = ''
        found=
        for name in libhidapi-hidraw libhidapi-libusb libhidapi-iohidmanager libhidapi; do
          full_path=${pkgs.hidapi.out}/lib/$name${pkgs.stdenv.hostPlatform.extensions.sharedLibrary}
          if test -f $full_path; then
            found=t
            sed -i -e "s|'$name\..*'|'$full_path'|" hid/__init__.py
          fi
        done
        test -n "$found" || { echo "ERROR: No known libraries found in ${pkgs.hidapi.out}/lib, please update/fix this build expression."; exit 1; }
      '';
    }
  );

  horovod = super.horovod.overridePythonAttrs (
    old: {
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ pkgs.mpi ];
    }
  );

  imagecodecs = super.imagecodecs.overridePythonAttrs (
    old: {
      patchPhase = ''
        substituteInPlace setup.py \
          --replace "/usr/include/openjpeg-2.3" \
                    "${pkgs.openjpeg.dev}/include/${pkgs.openjpeg.dev.incDir}
        substituteInPlace setup.py \
          --replace "/usr/include/jxrlib" \
                    "$out/include/libjxr"
        substituteInPlace imagecodecs/_zopfli.c \
          --replace '"zopfli/zopfli.h"' \
                    '<zopfli.h>'
        substituteInPlace imagecodecs/_zopfli.c \
          --replace '"zopfli/zlib_container.h"' \
                    '<zlib_container.h>'
        substituteInPlace imagecodecs/_zopfli.c \
          --replace '"zopfli/gzip_container.h"' \
                    '<gzip_container.h>'
      '';

      preBuild = ''
        mkdir -p $out/include/libjxr
        ln -s ${pkgs.jxrlib}/include/libjxr/**/* $out/include/libjxr

      '';

      buildInputs = (old.buildInputs or [ ]) ++ [
        # Commented out packages are declared required, but not actually
        # needed to build. They are not yet packaged for nixpkgs.
        # bitshuffle
        pkgs.brotli
        # brunsli
        pkgs.bzip2
        pkgs.c-blosc
        # charls
        pkgs.giflib
        pkgs.jxrlib
        pkgs.lcms
        pkgs.libaec
        pkgs.libaec
        pkgs.libjpeg_turbo
        # liblzf
        # liblzma
        pkgs.libpng
        pkgs.libtiff
        pkgs.libwebp
        pkgs.lz4
        pkgs.openjpeg
        pkgs.snappy
        # zfp
        pkgs.zopfli
        pkgs.zstd
        pkgs.zlib
      ];
    }
  );

  # importlib-metadata has an incomplete dependency specification
  importlib-metadata = super.importlib-metadata.overridePythonAttrs (
    old: {
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ lib.optional self.python.isPy2 self.pathlib2;

      # disable the removal of pyproject.toml, required because of setuptools_scm
      dontPreferSetupPy = true;
    }
  );

  intreehooks = super.intreehooks.overridePythonAttrs (
    old: {
      doCheck = false;
    }
  );

  isort = super.isort.overridePythonAttrs (
    old: {
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ self.setuptools ];
    }
  );

  jaraco-functools = super.jaraco-functools.overridePythonAttrs (
    old: {
      # required for the extra "toml" dependency in setuptools_scm[toml]
      buildInputs = (old.buildInputs or [ ]) ++ [
        self.toml
      ];
      # disable the removal of pyproject.toml, required because of setuptools_scm
      dontPreferSetupPy = true;
    }
  );

  jira = super.jira.overridePythonAttrs (
    old: {
      inherit (pkgs.python3Packages.jira) patches;
      buildInputs = (old.buildInputs or [ ]) ++ [
        self.pytest-runner
        self.cryptography
        self.pyjwt
      ];
    }
  );

  jsondiff = super.jsondiff.overridePythonAttrs (
    old: {
      preBuild = (old.preBuild or "") + ''
        substituteInPlace setup.py \
          --replace "'jsondiff=jsondiff.cli:main_deprecated'," ""
      '';
    }
  );

  jsonpickle = super.jsonpickle.overridePythonAttrs (
    old: {
      dontPreferSetupPy = true;
    }
  );

  jsonslicer = super.jsonslicer.overridePythonAttrs (old: {
    nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.pkgconfig ];
    buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.yajl ];
  });

  jupyter = super.jupyter.overridePythonAttrs (
    old: rec {
      # jupyter is a meta-package. Everything relevant comes from the
      # dependencies. It does however have a jupyter.py file that conflicts
      # with jupyter-core so this meta solves this conflict.
      meta.priority = 100;
    }
  );

  keyring = super.keyring.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [
        self.toml
      ];
      postPatch = ''
        substituteInPlace setup.py --replace 'setuptools.setup()' 'setuptools.setup(version="${old.version}")'
      '';
    }
  );

  kiwisolver = super.kiwisolver.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [
        self.cppy
      ];
    }
  );

  lap = super.lap.overridePythonAttrs (
    old: {
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [
        self.numpy
      ];
    }
  );

  libvirt-python = super.libvirt-python.overridePythonAttrs ({ nativeBuildInputs ? [ ], ... }: {
    nativeBuildInputs = nativeBuildInputs ++ [ pkgs.pkg-config ];
    propagatedBuildInputs = [ pkgs.libvirt ];
  });

  llvmlite = super.llvmlite.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.llvm ];

      # Disable static linking
      # https://github.com/numba/llvmlite/issues/93
      postPatch = ''
        substituteInPlace ffi/Makefile.linux --replace "-static-libstdc++" ""

        substituteInPlace llvmlite/tests/test_binding.py --replace "test_linux" "nope"
      '';

      # Set directory containing llvm-config binary
      preConfigure = ''
        export LLVM_CONFIG=${pkgs.llvm}/bin/llvm-config
      '';

      __impureHostDeps = lib.optionals pkgs.stdenv.isDarwin [ "/usr/lib/libm.dylib" ];

      passthru = old.passthru // { llvm = pkgs.llvm; };
    }
  );

  lockfile = super.lockfile.overridePythonAttrs (
    old: {
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ self.pbr ];
    }
  );

  lxml = super.lxml.overridePythonAttrs (
    old: {
      nativeBuildInputs = with pkgs; (old.nativeBuildInputs or [ ]) ++ [ pkg-config libxml2.dev libxslt.dev ] ++ lib.optionals stdenv.isDarwin [ xcodebuild ];
      buildInputs = with pkgs; (old.buildInputs or [ ]) ++ [ libxml2 libxslt ];
    }
  );

  markupsafe = super.markupsafe.overridePythonAttrs (
    old: {
      src = old.src.override { pname = builtins.replaceStrings [ "markupsafe" ] [ "MarkupSafe" ] old.pname; };
    }
  );

  matplotlib = super.matplotlib.overridePythonAttrs (
    old:
    let
      enableGhostscript = old.passthru.enableGhostscript or false;
      enableGtk3 = old.passthru.enableTk or false;
      enableQt = old.passthru.enableQt or false;
      enableTk = old.passthru.enableTk or false;

      inherit (pkgs.darwin.apple_sdk.frameworks) Cocoa;
    in
    {
      NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${pkgs.libcxx}/include/c++/v1";

      XDG_RUNTIME_DIR = "/tmp";

      buildInputs = (old.buildInputs or [ ])
        ++ lib.optional enableGhostscript pkgs.ghostscript
        ++ lib.optional stdenv.isDarwin [ Cocoa ];

      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
        pkgs.pkg-config
      ];

      postPatch = ''
        cat > setup.cfg <<EOF
        [libs]
        system_freetype = True
      '' + lib.optionalString stdenv.isDarwin ''
        # LTO not working in darwin stdenv, see NixOS/nixpkgs/pull/19312
        enable_lto = false
      '' + ''
        EOF
      '';

      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [
        pkgs.libpng
        pkgs.freetype
      ]
        ++ lib.optionals enableGtk3 [ pkgs.cairo self.pycairo pkgs.gtk3 pkgs.gobject-introspection self.pygobject3 ]
        ++ lib.optionals enableTk [ pkgs.tcl pkgs.tk self.tkinter pkgs.libX11 ]
        ++ lib.optionals enableQt [ self.pyqt5 ]
      ;

      inherit (super.matplotlib) patches;
    }
  );

  # Calls Cargo at build time for source builds and is really tricky to package
  maturin = super.maturin.override {
    preferWheel = true;
  };

  mccabe = super.mccabe.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
      doCheck = false;
    }
  );

  mip = super.mip.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.autoPatchelfHook ];

      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.zlib self.cppy ];
    }
  );

  molecule =
    if lib.versionOlder super.molecule.version "3.0.0" then
      (super.molecule.overridePythonAttrs (
        old: {
          patches = (old.patches or [ ]) ++ [
            # Fix build with more recent setuptools versions
            (pkgs.fetchpatch {
              url = "https://github.com/ansible-community/molecule/commit/c9fee498646a702c77b5aecf6497cff324acd056.patch";
              sha256 = "1g1n45izdz0a3c9akgxx14zhdw6c3dkb48j8pq64n82fa6ndl1b7";
              excludes = [ "pyproject.toml" ];
            })
          ];
          buildInputs = (old.buildInputs or [ ]) ++ [ self.setuptools-scm-git-archive ];
        }
      )) else
      super.molecule.overridePythonAttrs (old: {
        buildInputs = (old.buildInputs or [ ]) ++ [ self.setuptools-scm-git-archive ];
      });

  mongomock = super.mongomock.overridePythonAttrs (oa: {
    buildInputs = oa.buildInputs ++ [ self.pbr ];
  });

  moto = super.moto.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++
        [ self.sshpubkeys ];
    }
  );

  mpi4py = super.mpi4py.overridePythonAttrs (
    old:
    let
      cfg = pkgs.writeTextFile {
        name = "mpi.cfg";
        text = (
          lib.generators.toINI
            { }
            {
              mpi = {
                mpicc = "${pkgs.mpi.outPath}/bin/mpicc";
              };
            }
        );
      };
    in
    {
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ pkgs.mpi ];
      enableParallelBuilding = true;
      preBuild = ''
        ln -sf ${cfg} mpi.cfg
      '';
    }
  );

  multiaddr = super.multiaddr.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  munch = super.munch.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pbr ];
    }
  );

  mypy = super.mypy.overridePythonAttrs (
    old: {
      MYPY_USE_MYPYC = pkgs.stdenv.buildPlatform.is64bit;
    }
  );

  mysqlclient = super.mysqlclient.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.libmysqlclient ];
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.libmysqlclient ];
    }
  );

  netcdf4 = super.netcdf4.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [
        self.cython
      ];

      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [
        pkgs.zlib
        pkgs.netcdf
        pkgs.hdf5
        pkgs.curl
        pkgs.libjpeg
      ];

      # Variables used to configure the build process
      USE_NCCONFIG = "0";
      HDF5_DIR = lib.getDev pkgs.hdf5;
      NETCDF4_DIR = pkgs.netcdf;
      CURL_DIR = pkgs.curl.dev;
      JPEG_DIR = pkgs.libjpeg.dev;
    }
  );

  numpy = super.numpy.overridePythonAttrs (
    old:
    let
      blas = old.passthru.args.blas or pkgs.openblasCompat;
      blasImplementation = lib.nameFromURL blas.name "-";
      cfg = pkgs.writeTextFile {
        name = "site.cfg";
        text = (
          lib.generators.toINI
            { }
            {
              ${blasImplementation} = {
                include_dirs = "${blas}/include";
                library_dirs = "${blas}/lib";
              } // lib.optionalAttrs (blasImplementation == "mkl") {
                mkl_libs = "mkl_rt";
                lapack_libs = "";
              };
            }
        );
      };
    in
    {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.gfortran ];
      buildInputs = (old.buildInputs or [ ]) ++ [ blas self.cython ];
      enableParallelBuilding = true;
      preBuild = ''
        ln -s ${cfg} site.cfg
      '';
      passthru = old.passthru // {
        blas = blas;
        inherit blasImplementation cfg;
      };
    }
  );

  openexr = super.openexr.overridePythonAttrs (
    old: rec {
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.openexr pkgs.ilmbase ];
      NIX_CFLAGS_COMPILE = [ "-I${pkgs.openexr.dev}/include/OpenEXR" "-I${pkgs.ilmbase.dev}/include/OpenEXR" ];
    }
  );

  osqp = super.osqp.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.cmake ];
      dontUseCmakeConfigure = true;
    }
  );

  parsel = super.parsel.overridePythonAttrs (
    old: rec {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  pdal = super.pdal.overridePythonAttrs (
    old: {
      PDAL_CONFIG = "${pkgs.pdal}/bin/pdal-config";
    }
  );

  peewee = super.peewee.overridePythonAttrs (
    old:
    let
      withPostgres = old.passthru.withPostgres or false;
      withMysql = old.passthru.withMysql or false;
    in
    {
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.sqlite ];
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ])
        ++ lib.optional withPostgres self.psycopg2
        ++ lib.optional withMysql self.mysql-connector;
    }
  );

  pillow = super.pillow.overridePythonAttrs (
    old: {
      nativeBuildInputs = [ pkgs.pkg-config self.pytest-runner ] ++ (old.nativeBuildInputs or [ ]);
      buildInputs = with pkgs; [ freetype libjpeg zlib libtiff libwebp tcl lcms2 ] ++ (old.buildInputs or [ ]);
    }
  );

  # Work around https://github.com/nix-community/poetry2nix/issues/244
  # where git deps are not picked up as they should
  pip =
    if lib.versionAtLeast super.pip.version "20.3" then
      super.pip.overridePythonAttrs
        (old:
          let
            pname = "pip";
            version = "20.2.4";
          in
          {
            name = pname + "-" + version;
            inherit version;
            src = pkgs.fetchFromGitHub {
              owner = "pypa";
              repo = pname;
              rev = version;
              sha256 = "eMVV4ftgV71HLQsSeaOchYlfaJVgzNrwUynn3SA1/Do=";
              name = "${pname}-${version}-source";
            };
          }) else super.pip;

  poetry-core = super.poetry-core.overridePythonAttrs (old: {
    # "Vendor" dependencies (for build-system support)
    postPatch = ''
      echo "import sys" >> poetry/__init__.py
      for path in $propagatedBuildInputs; do
          echo "sys.path.insert(0, \"$path\")" >> poetry/__init__.py
      done
    '';

    # Propagating dependencies leads to issues downstream
    # We've already patched poetry to prefer "vendored" dependencies
    postFixup = ''
      rm $out/nix-support/propagated-build-inputs
    '';
  });

  portend = super.portend.overridePythonAttrs (
    old: {
      # required for the extra "toml" dependency in setuptools_scm[toml]
      buildInputs = (old.buildInputs or [ ]) ++ [
        self.toml
      ];
      # disable the removal of pyproject.toml, required because of setuptools_scm
      dontPreferSetupPy = true;
    }
  );

  psycopg2 = super.psycopg2.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ])
        ++ lib.optional stdenv.isDarwin pkgs.openssl;
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.postgresql ];
    }
  );

  psycopg2-binary = super.psycopg2-binary.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ])
        ++ lib.optional stdenv.isDarwin pkgs.openssl;
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.postgresql ];
    }
  );

  pyarrow =
    if lib.versionAtLeast super.pyarrow.version "0.16.0" then
      super.pyarrow.overridePythonAttrs
        (
          old:
          let
            parseMinor = drv: lib.concatStringsSep "." (lib.take 2 (lib.splitVersion drv.version));

            # Starting with nixpkgs revision f149c7030a7, pyarrow takes "python3" as an argument
            # instead of "python". Below we inspect function arguments to maintain compatibilitiy.
            _arrow-cpp = pkgs.arrow-cpp.override (
              builtins.intersectAttrs
                (lib.functionArgs pkgs.arrow-cpp.override)
                { python = self.python; python3 = self.python; }
            );

            ARROW_HOME = _arrow-cpp;
            arrowCppVersion = parseMinor pkgs.arrow-cpp;
            pyArrowVersion = parseMinor super.pyarrow;
            errorMessage = "arrow-cpp version (${arrowCppVersion}) mismatches pyarrow version (${pyArrowVersion})";
          in
          if arrowCppVersion != pyArrowVersion then throw errorMessage else {

            nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
              self.cython
              pkgs.pkg-config
              pkgs.cmake
            ];

            preBuild = ''
              export PYARROW_PARALLEL=$NIX_BUILD_CORES
            '';

            PARQUET_HOME = _arrow-cpp;
            inherit ARROW_HOME;

            buildInputs = (old.buildInputs or [ ]) ++ [
              pkgs.arrow-cpp
            ];

            PYARROW_BUILD_TYPE = "release";
            PYARROW_WITH_PARQUET = true;
            PYARROW_CMAKE_OPTIONS = [
              "-DCMAKE_INSTALL_RPATH=${ARROW_HOME}/lib"

              # This doesn't use setup hook to call cmake so we need to workaround #54606
              # ourselves
              "-DCMAKE_POLICY_DEFAULT_CMP0025=NEW"
            ];

            dontUseCmakeConfigure = true;
          }
        ) else
      super.pyarrow.overridePythonAttrs (
        old: {
          nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
            self.cython
          ];
        }
      );

  pycairo = (
    drv: (
      drv.overridePythonAttrs (
        _: {
          format = "other";
        }
      )
    ).overridePythonAttrs (
      old: {

        nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
          pkgs.meson
          pkgs.ninja
          pkgs.pkg-config
        ];

        propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [
          pkgs.cairo
          pkgs.xlibsWrapper
        ];

        mesonFlags = [ "-Dpython=${if self.isPy3k then "python3" else "python"}" ];
      }
    )
  )
    super.pycairo;

  pycocotools = super.pycocotools.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [
        self.cython
        self.numpy
      ];
    }
  );

  pyfuse3 = super.pyfuse3.overridePythonAttrs (old: {
    nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.pkg-config ];
    buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.fuse3 ];
  });

  pygame = super.pygame.overridePythonAttrs (
    old: rec {
      nativeBuildInputs = [
        pkgs.pkg-config
        pkgs.SDL
      ];

      buildInputs = [
        pkgs.SDL
        pkgs.SDL_image
        pkgs.SDL_mixer
        pkgs.SDL_ttf
        pkgs.libpng
        pkgs.libjpeg
        pkgs.portmidi
        pkgs.xorg.libX11
        pkgs.freetype
      ];

      # Tests fail because of no audio device and display.
      doCheck = false;
      preConfigure = ''
                sed \
                  -e "s/origincdirs = .*/origincdirs = []/" \
                  -e "s/origlibdirs = .*/origlibdirs = []/" \
                  -e "/'\/lib\/i386-linux-gnu', '\/lib\/x86_64-linux-gnu']/d" \
                  -e "/\/include\/smpeg/d" \
                  -i buildconfig/config_unix.py
                ${lib.concatMapStrings
        (dep: ''
                  sed \
                    -e "/origincdirs =/a\        origincdirs += ['${lib.getDev dep}/include']" \
                    -e "/origlibdirs =/a\        origlibdirs += ['${lib.getLib dep}/lib']" \
                    -i buildconfig/config_unix.py
                '')
        buildInputs
                }
                LOCALBASE=/ ${self.python.interpreter} buildconfig/config.py
      '';
    }
  );

  pygeos = super.pygeos.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.geos ];
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.geos ];
    }
  );

  pygobject = super.pygobject.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.pkg-config ];
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.glib pkgs.gobject-introspection ];
    }
  );

  pylint = super.pylint.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
      doCheck = false;
    }
  );

  pyopenssl = super.pyopenssl.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.openssl ];
    }
  );

  pyproj = super.pyproj.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++
        [ self.cython ];
      PROJ_DIR = "${pkgs.proj}";
      PROJ_LIBDIR = "${pkgs.proj}/lib";
      PROJ_INCDIR = "${pkgs.proj.dev}/include";
    }
  );

  pyproject-flake8 = super.pyproject-flake8.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.flit-core ];
    }
  );

  pytezos = super.pytezos.override (old: {
    buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.libsodium ];
  });

  python-bugzilla = super.python-bugzilla.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
        self.docutils
      ];
    }
  );

  python-ldap = super.python-ldap.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.openldap pkgs.cyrus_sasl ];
    }
  );

  pytoml = super.pytoml.overridePythonAttrs (
    old: {
      doCheck = false;
    }
  );

  pyqt5 =
    let
      drv = super.pyqt5;
      withConnectivity = drv.passthru.args.withConnectivity or false;
      withMultimedia = drv.passthru.args.withMultimedia or false;
      withWebKit = drv.passthru.args.withWebKit or false;
      withWebSockets = drv.passthru.args.withWebSockets or false;
    in
    super.pyqt5.overridePythonAttrs (
      old: {
        format = "other";

        dontWrapQtApps = true;

        nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
          pkgs.pkg-config
          pkgs.qt5.qmake
          pkgs.xorg.lndir
          pkgs.qt5.qtbase
          pkgs.qt5.qtsvg
          pkgs.qt5.qtdeclarative
          pkgs.qt5.qtwebchannel
          # self.pyqt5-sip
          self.sip
        ]
          ++ lib.optional withConnectivity pkgs.qt5.qtconnectivity
          ++ lib.optional withMultimedia pkgs.qt5.qtmultimedia
          ++ lib.optional withWebKit pkgs.qt5.qtwebkit
          ++ lib.optional withWebSockets pkgs.qt5.qtwebsockets
        ;

        buildInputs = (old.buildInputs or [ ]) ++ [
          pkgs.dbus
          pkgs.qt5.qtbase
          pkgs.qt5.qtsvg
          pkgs.qt5.qtdeclarative
          self.sip
        ]
          ++ lib.optional withConnectivity pkgs.qt5.qtconnectivity
          ++ lib.optional withWebKit pkgs.qt5.qtwebkit
          ++ lib.optional withWebSockets pkgs.qt5.qtwebsockets
        ;

        # Fix dbus mainloop
        patches = pkgs.python3.pkgs.pyqt5.patches or [ ];

        configurePhase = ''
          runHook preConfigure

          export PYTHONPATH=$PYTHONPATH:$out/${self.python.sitePackages}

          mkdir -p $out/${self.python.sitePackages}/dbus/mainloop
          ${self.python.executable} configure.py  -w \
            --confirm-license \
            --no-qml-plugin \
            --bindir=$out/bin \
            --destdir=$out/${self.python.sitePackages} \
            --stubsdir=$out/${self.python.sitePackages}/PyQt5 \
            --sipdir=$out/share/sip/PyQt5 \
            --designer-plugindir=$out/plugins/designer

          runHook postConfigure
        '';

        postInstall = ''
          ln -s ${self.pyqt5-sip}/${self.python.sitePackages}/PyQt5/sip.* $out/${self.python.sitePackages}/PyQt5/
          for i in $out/bin/*; do
            wrapProgram $i --prefix PYTHONPATH : "$PYTHONPATH"
          done

          # Let's make it a namespace package
          cat << EOF > $out/${self.python.sitePackages}/PyQt5/__init__.py
          from pkgutil import extend_path
          __path__ = extend_path(__path__, __name__)
          EOF
        '';

        installCheckPhase =
          let
            modules = [
              "PyQt5"
              "PyQt5.QtCore"
              "PyQt5.QtQml"
              "PyQt5.QtWidgets"
              "PyQt5.QtGui"
            ]
            ++ lib.optional withWebSockets "PyQt5.QtWebSockets"
            ++ lib.optional withWebKit "PyQt5.QtWebKit"
            ++ lib.optional withMultimedia "PyQt5.QtMultimedia"
            ++ lib.optional withConnectivity "PyQt5.QtConnectivity"
            ;
            imports = lib.concatMapStrings (module: "import ${module};") modules;
          in
          ''
            echo "Checking whether modules can be imported..."
            ${self.python.interpreter} -c "${imports}"
          '';

        doCheck = true;

        enableParallelBuilding = true;
      }
    );

  pytest-datadir = super.pytest-datadir.overridePythonAttrs (
    old: {
      postInstall = ''
        rm -f $out/LICENSE
      '';
    }
  );

  pytest = super.pytest.overridePythonAttrs (
    old: {
      # Fixes https://github.com/pytest-dev/pytest/issues/7891
      postPatch = old.postPatch or "" + ''
        sed -i '/\[metadata\]/aversion = ${old.version}' setup.cfg
      '';
      doCheck = false;
    }
  );

  pytest-django = super.pytest-django.overridePythonAttrs (
    old: {
      postPatch = ''
        substituteInPlace setup.py --replace "'pytest>=3.6'," ""
        substituteInPlace setup.py --replace "'pytest>=3.6'" ""
      '';
    }
  );

  pytest-pylint = super.pytest-pylint.overridePythonAttrs (
    old: {
      buildInputs = [ self.pytest-runner ];
    }
  );

  # pytest-splinter seems to put a .marker file in an empty directory
  # presumably so it's tracked by and can be installed with MANIFEST.in, see
  # https://github.com/pytest-dev/pytest-splinter/commit/a48eeef662f66ff9d3772af618748e73211a186b
  #
  # This directory then gets used as an empty initial profile directory and is
  # zipped up. But if the .marker file is in the Nix store, it has the
  # creation date of 1970, and Zip doesn't work with such old files, so it
  # fails at runtime!
  #
  # We fix this here by just removing the file after the installation
  #
  # The error you get without this is:
  #
  # E           ValueError: ZIP does not support timestamps before 1980
  # /nix/store/55b9ip7xkpimaccw9pa0vacy5q94f5xa-python3-3.7.6/lib/python3.7/zipfile.py:357: ValueError
  pytest-splinter = super.pytest-splinter.overrideAttrs (old: {
    postInstall = old.postInstall or "" + ''
      rm $out/${super.python.sitePackages}/pytest_splinter/profiles/firefox/.marker
    '';
  });

  python-jose = super.python-jose.overridePythonAttrs (
    old: {
      buildInputs = [ self.pytest-runner ];
    }
  );

  python-snappy = super.python-snappy.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.snappy ];
    }
  );

  ffmpeg-python = super.ffmpeg-python.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  python-prctl = super.python-prctl.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [
        pkgs.libcap
      ];
    }
  );

  pyusb = super.pyusb.overridePythonAttrs (
    old: {
      postPatch = ''
        libusb=${pkgs.libusb1.out}/lib/libusb-1.0${pkgs.stdenv.hostPlatform.extensions.sharedLibrary}
        test -f $libusb || { echo "ERROR: $libusb doesn't exist, please update/fix this build expression."; exit 1; }
        sed -i -e "s|find_library=None|find_library=lambda _:\"$libusb\"|" usb/backend/libusb1.py
      '';
    }
  );

  pyzmq = super.pyzmq.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.pkg-config ];
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ pkgs.zeromq ];
    }
  );

  rockset = super.rockset.overridePythonAttrs (
    old: rec {
      postPatch = ''
        cp ./setup_rockset.py ./setup.py
      '';
    }
  );

  scaleapi = super.scaleapi.overridePythonAttrs (
    old: {
      postPatch = ''
        substituteInPlace setup.py --replace "install_requires = ['requests>=2.4.2', 'enum34']" "install_requires = ['requests>=2.4.2']" || true
      '';
    }
  );

  pandas = super.pandas.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ self.cython ];
    }
  );

  panel = super.panel.overridePythonAttrs (
    old: {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.nodejs ];
    }
  );

  # Pybind11 is an undeclared dependency of scipy that we need to pick from nixpkgs
  # Make it not fail with infinite recursion
  pybind11 = super.pybind11.overridePythonAttrs (
    old: {
      cmakeFlags = (old.cmakeFlags or [ ]) ++ [
        "-DPYBIND11_TEST=off"
      ];
      doCheck = false; # Circular test dependency
    }
  );

  rlp = super.rlp.overridePythonAttrs {
    preConfigure = ''
      substituteInPlace setup.py --replace \'setuptools-markdown\' ""
    '';
  };


  rmfuse = super.rmfuse.overridePythonAttrs (old: {
    propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ self.setuptools ];
  });

  rtree = super.rtree.overridePythonAttrs (old: {
    propagatedNativeBuildInputs = (old.propagatedNativeBuildInputs or [ ]) ++ [ pkgs.libspatialindex ];
    postPatch = ''
      substituteInPlace rtree/finder.py --replace \
        "find_library('spatialindex_c')" \
        "'${pkgs.libspatialindex}/lib/libspatialindex_c${pkgs.stdenv.hostPlatform.extensions.sharedLibrary}'"
    '';
  });

  scipy = super.scipy.overridePythonAttrs (
    old:
    if old.format != "wheel" then {
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.gfortran ];
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ self.pybind11 ];
      setupPyBuildFlags = [ "--fcompiler='gnu95'" ];
      enableParallelBuilding = true;
      buildInputs = (old.buildInputs or [ ]) ++ [ self.numpy.blas ];
      preConfigure = ''
        sed -i '0,/from numpy.distutils.core/s//import setuptools;from numpy.distutils.core/' setup.py
        export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES
      '';
      preBuild = ''
        ln -s ${self.numpy.cfg} site.cfg
      '';
    } else old
  );

  scikit-learn = super.scikit-learn.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [
        pkgs.gfortran
        pkgs.glibcLocales
      ] ++ lib.optionals stdenv.cc.isClang [
        pkgs.llvmPackages.openmp
      ];

      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
        self.cython
      ];

      enableParallelBuilding = true;
    }
  );

  secp256k1 = super.secp256k1.overridePythonAttrs (old: {
    nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.pkgconfig pkgs.autoconf pkgs.automake pkgs.libtool ];
    buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
    doCheck = false;
    # Local setuptools versions like "x.y.post0" confuse an internal check
    postPatch = ''
      substituteInPlace setup.py \
        --replace 'setuptools_version.' '"${self.setuptools.version}".'
    '';
  });

  shapely = super.shapely.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ pkgs.geos self.cython ];
      inherit (pkgs.python3.pkgs.shapely) patches GEOS_LIBRARY_PATH;
    }
  );

  shellingham =
    if lib.versionAtLeast super.shellingham.version "1.3.2" then
      (
        super.shellingham.overridePythonAttrs (
          old: {
            format = "pyproject";
          }
        )
      ) else super.shellingham;

  tables = super.tables.overridePythonAttrs (
    old: {
      HDF5_DIR = "${pkgs.hdf5}";
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.pkg-config ];
      propagatedBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.hdf5 self.numpy self.numexpr ];
    }
  );

  tempora = super.tempora.overridePythonAttrs (
    old: {
      # required for the extra "toml" dependency in setuptools_scm[toml]
      buildInputs = (old.buildInputs or [ ]) ++ [
        self.toml
      ];
      # disable the removal of pyproject.toml, required because of setuptools_scm
      dontPreferSetupPy = true;
    }
  );

  tensorflow = super.tensorflow.overridePythonAttrs (
    old: {
      postInstall = ''
        rm $out/bin/tensorboard
      '';
    }
  );

  tensorpack = super.tensorpack.overridePythonAttrs (
    old: {
      postPatch = ''
        substituteInPlace setup.cfg --replace "# will call find_packages()" ""
      '';
    }
  );

  tinycss2 = super.tinycss2.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  # The tokenizers build requires a complex rust setup (cf. nixpkgs override)
  #
  # Instead of providing a full source build, we use a wheel to keep
  # the complexity manageable for now.
  tokenizers = super.tokenizers.override {
    preferWheel = true;
  };

  torch = lib.makeOverridable
    ({ enableCuda ? false
     , cudatoolkit ? pkgs.cudatoolkit_10_1
     , pkg ? super.torch
     }: pkg.overrideAttrs (old:
      {
        preConfigure =
          if (!enableCuda) then ''
            export USE_CUDA=0
          '' else ''
            export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${cudatoolkit}/targets/x86_64-linux/lib"
          '';
        preFixup = lib.optionalString (!enableCuda) ''
          # For some reason pytorch retains a reference to libcuda even if it
          # is explicitly disabled with USE_CUDA=0.
          find $out -name "*.so" -exec ${pkgs.patchelf}/bin/patchelf --remove-needed libcuda.so.1 {} \;
        '';
        buildInputs =
          (old.buildInputs or [ ])
          ++ [ self.typing-extensions ]
          ++ lib.optionals enableCuda [
            pkgs.linuxPackages.nvidia_x11
            pkgs.nccl.dev
            pkgs.nccl.out
          ];
        propagatedBuildInputs = [
          self.numpy
          self.future
          self.typing-extensions
        ];
      })
    )
    { };

  torchvision = lib.makeOverridable
    ({ enableCuda ? false
     , cudatoolkit ? pkgs.cudatoolkit_10_1
     , pkg ? super.torchvision
     }: pkg.overrideAttrs (old: {

      # without that autoPatchelfHook will fail because cudatoolkit is not in LD_LIBRARY_PATH
      autoPatchelfIgnoreMissingDeps = true;
      buildInputs = (old.buildInputs or [ ])
        ++ [ self.torch ]
        ++ lib.optionals enableCuda [
        cudatoolkit
      ];
      preConfigure =
        if (enableCuda) then ''
          export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${self.torch}/${self.python.sitePackages}/torch/lib:${lib.makeLibraryPath [ cudatoolkit "${cudatoolkit}" ]}"
        '' else ''
          export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${self.torch}/${self.python.sitePackages}/torch/lib"
        '';
    }))
    { };

  typeguard = super.typeguard.overridePythonAttrs (old: {
    postPatch = ''
      substituteInPlace setup.py \
        --replace 'setup()' 'setup(version="${old.version}")'
    '';
  });

  typed_ast = super.typed-ast.overridePythonAttrs (old: {
    nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
      self.pytest-runner
    ];
  });

  # nix uses a dash, poetry uses an underscore
  typing_extensions = super.typing_extensions or self.typing-extensions;

  urwidtrees = super.urwidtrees.overridePythonAttrs (
    old: {
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [
        self.urwid
      ];
    }
  );

  vose-alias-method = super.vose-alias-method.overridePythonAttrs (
    old: {
      postInstall = ''
        rm -f $out/LICENSE
      '';
    }
  );

  vispy = super.vispy.overrideAttrs (
    old: {
      inherit (pkgs.python3.pkgs.vispy) patches;
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
        self.cython
        self.setuptools-scm-git-archive
      ];
    }
  );

  uvloop = super.uvloop.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ lib.optionals stdenv.isDarwin [
        pkgs.darwin.apple_sdk.frameworks.ApplicationServices
        pkgs.darwin.apple_sdk.frameworks.CoreServices
      ];
    }
  );


  # Stop infinite recursion by using bootstrapped pkg from nixpkgs
  bootstrapped-pip = super.bootstrapped-pip.override {
    wheel = (pkgs.python3.pkgs.override {
      python = self.python;
    }).wheel;
  };

  weasyprint = super.weasyprint.overridePythonAttrs (
    old: {
      inherit (pkgs.python3.pkgs.weasyprint) patches;
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ self.pytest-runner ];
      buildInputs = (old.buildInputs or [ ]) ++ [ self.pytest-runner ];
    }
  );

  web3 = super.web3.overridePythonAttrs {
    preConfigure = ''
      substituteInPlace setup.py --replace \'setuptools-markdown\' ""
    '';
  };

  wheel =
    let
      isWheel = super.wheel.src.isWheel or false;
      # If "wheel" is a pre-built binary wheel
      wheelPackage = super.buildPythonPackage {
        inherit (super.wheel) pname name version src;
        inherit (pkgs.python3.pkgs.wheel) meta;
        format = "wheel";
      };
      # If "wheel" is built from source
      sourcePackage = ((
        pkgs.python3.pkgs.override {
          python = self.python;
        }
      ).wheel.override {
        inherit (self) buildPythonPackage bootstrapped-pip setuptools;
      }).overrideAttrs (old: {
        inherit (super.wheel) pname name version src;
      });
    in
    if isWheel then wheelPackage else sourcePackage;

  zipp = if super.zipp == null then null else
  (
    if lib.versionAtLeast super.zipp.version "2.0.0" then
      (
        super.zipp.overridePythonAttrs (
          old: {
            prePatch = ''
              substituteInPlace setup.py --replace \
              'setuptools.setup()' \
              'setuptools.setup(version="${super.zipp.version}")'
            '';
          }
        )
      ) else super.zipp
  ).overridePythonAttrs (
    old: {
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [
        self.toml
      ];
    }
  );

  credis = super.credis.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.cython ];
    }
  );

  hashids = super.hashids.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++ [ self.flit-core ];
    }
  );

  packaging = super.packaging.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++
        # From 20.5 until 20.7, packaging used flit for packaging (heh)
        # See https://github.com/pypa/packaging/pull/352 and https://github.com/pypa/packaging/pull/367
        lib.optional (lib.versionAtLeast old.version "20.5" && lib.versionOlder old.version "20.8") [ self.flit-core ];
    }
  );

  psutil = super.psutil.overridePythonAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ]) ++
        lib.optional stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.IOKit;
    }
  );

  sentencepiece = super.sentencepiece.overridePythonAttrs (
    old: {
      dontUseCmakeConfigure = true;
      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
        pkgs.pkg-config
        pkgs.cmake
        pkgs.gperftools
      ];
      buildInputs = (old.buildInputs or [ ]) ++ [
        pkgs.sentencepiece
      ];
    }
  );

  sentence-transformers = super.sentence-transformers.overridePythonAttrs (
    old: {
      buildInputs =
        (old.buildInputs or [ ])
        ++ [ self.typing-extensions ];
    }
  );

  supervisor = super.supervisor.overridePythonAttrs (
    old: {
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [
        self.meld3
        self.setuptools
      ];
    }
  );

  cytoolz = super.cytoolz.overridePythonAttrs (
    old: {
      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [ self.toolz ];
    }
  );

  # For some reason the toml dependency of tqdm declared here:
  # https://github.com/tqdm/tqdm/blob/67130a23646ae672836b971e1086b6ae4c77d930/pyproject.toml#L2
  # is not translated correctly to a nix dependency.
  tqdm = super.tqdm.overrideAttrs (
    old: {
      buildInputs = [ super.toml ] ++ (old.buildInputs or [ ]);
    }
  );

  watchdog = super.watchdog.overrideAttrs (
    old: {
      buildInputs = (old.buildInputs or [ ])
        ++ pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.CoreServices;
    }
  );

  # pyee cannot find `vcversioner` and other "setup requirements", so it tries to
  # download them from the internet, which only works when nix sandboxing is disabled.
  # Additionally, since pyee uses vcversioner to specify its version, we need to do this
  # manually specify its version.
  pyee = super.pyee.overrideAttrs (
    old: {
      postPatch = old.postPatch or "" + ''
        sed -i setup.py \
          -e '/setup_requires/,/],/d' \
          -e 's/vcversioner={},/version="${old.version}",/'
      '';
    }
  );

  # nixpkgs has setuptools_scm 4.1.2
  # but newrelic has a seemingly unnecessary version constraint for <4
  # So we patch that out
  newrelic = super.newrelic.overridePythonAttrs (
    old: {
      postPatch = old.postPatch or "" + ''
        substituteInPlace setup.py --replace '"setuptools_scm>=3.2,<4"' '"setuptools_scm"'
      '';
    }
  );

  wxpython = super.wxpython.overridePythonAttrs (old:
    let
      localPython = self.python.withPackages (ps: with ps; [
        setuptools
        numpy
        six
      ]);
    in
    {
      DOXYGEN = "${pkgs.doxygen}/bin/doxygen";

      nativeBuildInputs = with pkgs; [
        which
        doxygen
        gtk3
        pkg-config
        autoPatchelfHook
      ] ++ (old.nativeBuildInputs or [ ]);

      buildInputs = with pkgs; [
        gtk3
        webkitgtk
        ncurses
        SDL2
        xorg.libXinerama
        xorg.libSM
        xorg.libXxf86vm
        xorg.libXtst
        xorg.xorgproto
        gst_all_1.gstreamer
        gst_all_1.gst-plugins-base
        libGLU
        libGL
        libglvnd
        mesa
      ] ++ old.buildInputs;

      buildPhase = ''
        ${localPython.interpreter} build.py -v build_wx
        ${localPython.interpreter} build.py -v dox etg --nodoc sip
        ${localPython.interpreter} build.py -v build_py
      '';

      installPhase = ''
        ${localPython.interpreter} setup.py install --skip-build --prefix=$out
      '';
    });

}