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