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