1{ lib, stdenv
2, buildPythonPackage
3, cffi
4, dos2unix
5, fetchPypi
6, matplotlib
7, networkx
8, numpy
9, pytestCheckHook
10, pythonOlder
11, gurobi
12, gurobipy
13# Enable support for the commercial Gurobi solver (requires a license)
14, gurobiSupport ? false
15# If Gurobi has already been installed outside of the Nix store, specify its
16# installation directory here
17, gurobiHome ? null
18}:
19
20buildPythonPackage rec {
21 pname = "mip";
22 version = "1.15.0";
23
24 disabled = pythonOlder "3.7";
25 format = "pyproject";
26
27 src = fetchPypi {
28 inherit pname version;
29 hash = "sha256-f28Dgc/ixSwbhkAgPaLLVpdLJuI5UN37GnazfZFvGX4=";
30 };
31
32 nativeCheckInputs = [ matplotlib networkx numpy pytestCheckHook ];
33 nativeBuildInputs = [ dos2unix ];
34 propagatedBuildInputs = [
35 cffi
36 ] ++ lib.optionals gurobiSupport ([
37 gurobipy
38 ] ++ lib.optional (gurobiHome == null) gurobi);
39
40 # Source files have CRLF terminators, which make patch error out when supplied
41 # with diffs made on *nix machines
42 prePatch = ''
43 find . -type f -exec ${dos2unix}/bin/dos2unix {} \;
44 '';
45
46 patches = [
47 # Some tests try to be smart and dynamically construct a path to their test
48 # inputs. Unfortunately, since the test phase is run after installation,
49 # those paths point to the Nix store, which no longer contains the test
50 # data. This patch hardcodes the data path to point to the source directory.
51 ./test-data-path.patch
52 ];
53
54 postPatch = ''
55 # Allow cffi versions with a different patch level to be used
56 substituteInPlace pyproject.toml --replace "cffi==1.15.0" "cffi==1.15.*"
57 '';
58
59 # Make MIP use the Gurobi solver, if configured to do so
60 makeWrapperArgs = lib.optional gurobiSupport
61 "--set GUROBI_HOME ${if gurobiHome == null then gurobi.outPath else gurobiHome}";
62
63 # Tests that rely on Gurobi are activated only when Gurobi support is enabled
64 disabledTests = lib.optional (!gurobiSupport) "gurobi";
65
66 passthru.optional-dependencies = {
67 inherit gurobipy numpy;
68 };
69
70 meta = with lib; {
71 homepage = "https://python-mip.com/";
72 description = "A collection of Python tools for the modeling and solution of Mixed-Integer Linear programs (MIPs)";
73 downloadPage = "https://github.com/coin-or/python-mip/releases";
74 changelog = "https://github.com/coin-or/python-mip/releases/tag/${version}";
75 license = licenses.epl20;
76 broken = stdenv.isAarch64;
77 maintainers = with maintainers; [ nessdoor ];
78 };
79}