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