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