1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 fetchpatch,
7 setuptools,
8 python,
9 pkg-config,
10 pythonAtLeast,
11 gdb,
12 numpy,
13 ncurses,
14}:
15
16let
17 excludedTests = [
18 "reimport_from_subinterpreter"
19 ]
20 # cython's testsuite is not working very well with libc++
21 # We are however optimistic about things outside of testsuite still working
22 ++ lib.optionals (stdenv.cc.isClang or false) [
23 "cpdef_extern_func"
24 "libcpp_algo"
25 ]
26 # Some tests in the test suite isn't working on aarch64. Disable them for
27 # now until upstream finds a workaround.
28 # Upstream issue here: https://github.com/cython/cython/issues/2308
29 ++ lib.optionals stdenv.hostPlatform.isAarch64 [ "numpy_memoryview" ]
30 ++ lib.optionals stdenv.hostPlatform.isi686 [
31 "future_division"
32 "overflow_check_longlong"
33 ];
34in
35buildPythonPackage rec {
36 pname = "cython";
37 version = "0.29.37.1";
38 pyproject = true;
39
40 # error: too few arguments to function '_PyLong_AsByteArray'
41 disabled = pythonAtLeast "3.13";
42
43 src = fetchFromGitHub {
44 owner = "cython";
45 repo = "cython";
46 rev = "refs/tags/${version}";
47 hash = "sha256-XsEy2NrG7hq+VXRCRbD4BRaBieU6mVoE0GT52L3mMhs=";
48 };
49
50 nativeBuildInputs = [
51 pkg-config
52 setuptools
53 ];
54
55 nativeCheckInputs = [
56 gdb
57 numpy
58 ncurses
59 ];
60
61 LC_ALL = "en_US.UTF-8";
62
63 patches = [
64 # backport Cython 3.0 trashcan support (https://github.com/cython/cython/pull/2842) to 0.X series.
65 # it does not affect Python code unless the code explicitly uses the feature.
66 # trashcan support is needed to avoid stack overflows during object deallocation in sage (https://trac.sagemath.org/ticket/27267)
67 ./trashcan.patch
68 # The above commit introduces custom trashcan macros, as well as
69 # compiler changes to use them in Cython-emitted code. The latter
70 # change is still useful, but the former has been upstreamed as of
71 # Python 3.8, and the patch below makes Cython use the upstream
72 # trashcan macros whenever available. This is needed for Python
73 # 3.11 support, because the API used in Cython's implementation
74 # changed: https://github.com/cython/cython/pull/4475
75 (fetchpatch {
76 name = "disable-trashcan.patch";
77 url = "https://github.com/cython/cython/commit/e337825cdcf5e94d38ba06a0cb0188e99ce0cc92.patch";
78 hash = "sha256-q0f63eetKrDpmP5Z4v8EuGxg26heSyp/62OYqhRoSso=";
79 })
80 ];
81
82 checkPhase = ''
83 export HOME="$NIX_BUILD_TOP"
84 ${python.interpreter} runtests.py -j$NIX_BUILD_CORES \
85 --no-code-style \
86 ${lib.optionalString (
87 builtins.length excludedTests != 0
88 ) ''--exclude="(${builtins.concatStringsSep "|" excludedTests})"''}
89 '';
90
91 # https://github.com/cython/cython/issues/2785
92 # Temporary solution
93 doCheck = false;
94 # doCheck = !stdenv.hostPlatform.isDarwin;
95
96 # force regeneration of generated code in source distributions
97 # https://github.com/cython/cython/issues/5089
98 setupHook = ./setup-hook.sh;
99
100 meta = {
101 changelog = "https://github.com/cython/cython/blob/${version}/CHANGES.rst";
102 description = "Optimising static compiler for both the Python programming language and the extended Cython programming language";
103 homepage = "https://cython.org";
104 license = lib.licenses.asl20;
105 };
106}