1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 numpy,
9 pybind11,
10 setuptools,
11
12 # dependencies
13 clarabel,
14 cvxopt,
15 osqp,
16 scipy,
17 scs,
18
19 # tests
20 hypothesis,
21 pytestCheckHook,
22
23 useOpenmp ? (!stdenv.hostPlatform.isDarwin),
24}:
25
26buildPythonPackage rec {
27 pname = "cvxpy";
28 version = "1.6.5";
29 pyproject = true;
30
31 src = fetchFromGitHub {
32 owner = "cvxpy";
33 repo = "cvxpy";
34 tag = "v${version}";
35 hash = "sha256-utTd/13RQ3WKWreCKFMqGwPUFbPw3TaKKbS4T1BGGP4=";
36 };
37
38 # we need to patch out numpy version caps from upstream
39 postPatch = ''
40 substituteInPlace pyproject.toml \
41 --replace-fail "numpy >= 2.0.0" "numpy"
42 '';
43
44 build-system = [
45 numpy
46 pybind11
47 setuptools
48 ];
49
50 dependencies = [
51 clarabel
52 cvxopt
53 numpy
54 osqp
55 scipy
56 scs
57 ];
58
59 nativeCheckInputs = [
60 hypothesis
61 pytestCheckHook
62 ];
63
64 # Required flags from https://github.com/cvxpy/cvxpy/releases/tag/v1.1.11
65 preBuild = lib.optionalString useOpenmp ''
66 export CFLAGS="-fopenmp"
67 export LDFLAGS="-lgomp"
68 '';
69
70 pytestFlagsArray = [ "cvxpy" ];
71
72 disabledTests = [
73 # Disable the slowest benchmarking tests, cuts test time in half
74 "test_tv_inpainting"
75 "test_diffcp_sdp_example"
76 "test_huber"
77 "test_partial_problem"
78
79 # cvxpy.error.SolverError: Solver 'CVXOPT' failed. Try another solver, or solve with verbose=True for more information.
80 # https://github.com/cvxpy/cvxpy/issues/1588
81 "test_oprelcone_1_m1_k3_complex"
82 "test_oprelcone_1_m3_k1_complex"
83 "test_oprelcone_2"
84 ];
85
86 pythonImportsCheck = [ "cvxpy" ];
87
88 meta = {
89 description = "Domain-specific language for modeling convex optimization problems in Python";
90 homepage = "https://www.cvxpy.org/";
91 downloadPage = "https://github.com/cvxpy/cvxpy//releases";
92 changelog = "https://github.com/cvxpy/cvxpy/releases/tag/v${version}";
93 license = lib.licenses.asl20;
94 maintainers = with lib.maintainers; [ drewrisinger ];
95 };
96}