1{ lib
2, stdenv
3, buildPythonPackage
4, fetchPypi
5, fetchpatch
6, python
7, glibcLocales
8, pkg-config
9, gdb
10, numpy
11, ncurses
12}:
13
14let
15 excludedTests = []
16 ++ [ "reimport_from_subinterpreter" ]
17 # cython's testsuite is not working very well with libc++
18 # We are however optimistic about things outside of testsuite still working
19 ++ lib.optionals (stdenv.cc.isClang or false) [ "cpdef_extern_func" "libcpp_algo" ]
20 # Some tests in the test suite isn't working on aarch64. Disable them for
21 # now until upstream finds a workaround.
22 # Upstream issue here: https://github.com/cython/cython/issues/2308
23 ++ lib.optionals stdenv.isAarch64 [ "numpy_memoryview" ]
24 ++ lib.optionals stdenv.isi686 [ "future_division" "overflow_check_longlong" ]
25 ;
26
27in buildPythonPackage rec {
28 pname = "Cython";
29 version = "0.29.22";
30
31 src = fetchPypi {
32 inherit pname version;
33 sha256 = "sha256-32uDx6bR2WfqiaKQPkqTE3djSil0WWUuRVFzTEgZVAY=";
34 };
35
36 nativeBuildInputs = [
37 pkg-config
38 ];
39 checkInputs = [
40 numpy ncurses
41 ];
42 buildInputs = [ glibcLocales gdb ];
43 LC_ALL = "en_US.UTF-8";
44
45 patches = [
46 # https://github.com/cython/cython/issues/2752, needed by sage (https://trac.sagemath.org/ticket/26855) and up to be included in 0.30
47 (fetchpatch {
48 name = "non-int-conversion-to-pyhash.patch";
49 url = "https://github.com/cython/cython/commit/28251032f86c266065e4976080230481b1a1bb29.patch";
50 sha256 = "19rg7xs8gr90k3ya5c634bs8gww1sxyhdavv07cyd2k71afr83gy";
51 })
52
53 # backport Cython 3.0 trashcan support (https://github.com/cython/cython/pull/2842) to 0.X series.
54 # it does not affect Python code unless the code explicitly uses the feature.
55 # trashcan support is needed to avoid stack overflows during object deallocation in sage (https://trac.sagemath.org/ticket/27267)
56 (fetchpatch {
57 name = "trashcan.patch";
58 url = "https://git.sagemath.org/sage.git/plain/build/pkgs/cython/patches/trashcan.patch?id=4569a839f070a1a38d5dbce2a4d19233d25aeed2";
59 sha256 = "sha256-+pOF1XNTEtNseLpqPzrc1Jfwt5hGx7doUoccIhNneYY=";
60 })
61 ];
62
63 checkPhase = ''
64 export HOME="$NIX_BUILD_TOP"
65 ${python.interpreter} runtests.py -j$NIX_BUILD_CORES \
66 --no-code-style \
67 ${lib.optionalString (builtins.length excludedTests != 0)
68 ''--exclude="(${builtins.concatStringsSep "|" excludedTests})"''}
69 '';
70
71 # https://github.com/cython/cython/issues/2785
72 # Temporary solution
73 doCheck = false;
74
75# doCheck = !stdenv.isDarwin;
76
77
78 meta = {
79 description = "An optimising static compiler for both the Python programming language and the extended Cython programming language";
80 homepage = "https://cython.org";
81 license = lib.licenses.asl20;
82 maintainers = with lib.maintainers; [ fridh ];
83 };
84}