1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 gdb,
6 isPyPy,
7 ncurses,
8 numpy,
9 pkg-config,
10 pygame-ce,
11 python,
12 sage, # Reverse dependency
13 setuptools,
14 stdenv,
15}:
16
17buildPythonPackage rec {
18 pname = "cython";
19 version = "3.0.12";
20 pyproject = true;
21
22 src = fetchFromGitHub {
23 owner = "cython";
24 repo = "cython";
25 tag = version;
26 hash = "sha256-clJXjQb6rVECirKRUGX0vD5a6LILzPwNo7+6KKYs2pI=";
27 };
28
29 build-system = [
30 pkg-config
31 setuptools
32 ];
33
34 nativeCheckInputs = [
35 gdb
36 numpy
37 ncurses
38 ];
39
40 env = lib.optionalAttrs (!isPyPy) {
41 LC_ALL = "en_US.UTF-8";
42 };
43
44 # https://github.com/cython/cython/issues/2785
45 # Temporary solution
46 doCheck = false;
47
48 strictDeps = true;
49
50 checkPhase =
51 let
52 excludedTests =
53 [ "reimport_from_subinterpreter" ]
54 # cython's testsuite is not working very well with libc++
55 # We are however optimistic about things outside of testsuite still working
56 ++ lib.optionals (stdenv.cc.isClang or false) [
57 "cpdef_extern_func"
58 "libcpp_algo"
59 ]
60 # Some tests in the test suite aren't working on aarch64.
61 # Disable them for now until upstream finds a workaround.
62 # Upstream issue: https://github.com/cython/cython/issues/2308
63 ++ lib.optionals stdenv.hostPlatform.isAarch64 [ "numpy_memoryview" ]
64 ++ lib.optionals stdenv.hostPlatform.isi686 [
65 "future_division"
66 "overflow_check_longlong"
67 ];
68 commandline = builtins.concatStringsSep " " (
69 [
70 "-j$NIX_BUILD_CORES"
71 "--no-code-style"
72 ]
73 ++ lib.optionals (builtins.length excludedTests != 0) [
74 ''--exclude="(${builtins.concatStringsSep "|" excludedTests})"''
75 ]
76 );
77 in
78 ''
79 runHook preCheck
80 export HOME="$NIX_BUILD_TOP"
81 ${python.interpreter} runtests.py ${commandline}
82 runHook postCheck
83 '';
84
85 passthru.tests = {
86 inherit pygame-ce sage;
87 };
88
89 # Force code regeneration in source distributions
90 # https://github.com/cython/cython/issues/5089
91 setupHook = ./setup-hook.sh;
92
93 meta = {
94 homepage = "https://cython.org";
95 description = "Optimising static compiler for both the Python and the extended Cython programming languages";
96 longDescription = ''
97 Cython is an optimising static compiler for both the Python programming
98 language and the extended Cython programming language (based on Pyrex). It
99 makes writing C extensions for Python as easy as Python itself.
100
101 Cython gives you the combined power of Python and C to let you:
102
103 - write Python code that calls back and forth from and to C or C++ code
104 natively at any point.
105 - easily tune readable Python code into plain C performance by adding
106 static type declarations, also in Python syntax.
107 - use combined source code level debugging to find bugs in your Python,
108 Cython and C code.
109 - interact efficiently with large data sets, e.g. using multi-dimensional
110 NumPy arrays.
111 - quickly build your applications within the large, mature and widely used
112 CPython ecosystem.
113 - integrate natively with existing code and data from legacy, low-level or
114 high-performance libraries and applications.
115
116 The Cython language is a superset of the Python language that additionally
117 supports calling C functions and declaring C types on variables and class
118 attributes. This allows the compiler to generate very efficient C code
119 from Cython code.
120 '';
121 changelog = "https://github.com/cython/cython/blob/${version}/CHANGES.rst";
122 license = lib.licenses.asl20;
123 mainProgram = "cython";
124 maintainers = with lib.maintainers; [ ];
125 };
126}
127# TODO: investigate recursive loop when doCheck is true