2022-12-28 21:21:41 +00:00
|
|
|
{ lib
|
|
|
|
, buildPythonPackage
|
|
|
|
, cffi
|
|
|
|
, dos2unix
|
|
|
|
, fetchPypi
|
|
|
|
, matplotlib
|
|
|
|
, networkx
|
|
|
|
, numpy
|
|
|
|
, pytestCheckHook
|
|
|
|
, pythonOlder
|
|
|
|
, gurobi
|
|
|
|
, gurobipy
|
|
|
|
# Enable support for the commercial Gurobi solver (requires a license)
|
|
|
|
, gurobiSupport ? false
|
|
|
|
# If Gurobi has already been installed outside of the Nix store, specify its
|
|
|
|
# installation directory here
|
|
|
|
, gurobiHome ? null
|
|
|
|
}:
|
|
|
|
|
|
|
|
buildPythonPackage rec {
|
|
|
|
pname = "mip";
|
2023-03-15 16:39:30 +00:00
|
|
|
version = "1.15.0";
|
2022-12-28 21:21:41 +00:00
|
|
|
|
|
|
|
disabled = pythonOlder "3.7";
|
|
|
|
format = "pyproject";
|
|
|
|
|
|
|
|
src = fetchPypi {
|
|
|
|
inherit pname version;
|
2023-03-15 16:39:30 +00:00
|
|
|
hash = "sha256-f28Dgc/ixSwbhkAgPaLLVpdLJuI5UN37GnazfZFvGX4=";
|
2022-12-28 21:21:41 +00:00
|
|
|
};
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [ matplotlib networkx numpy pytestCheckHook ];
|
2022-12-28 21:21:41 +00:00
|
|
|
nativeBuildInputs = [ dos2unix ];
|
|
|
|
propagatedBuildInputs = [
|
|
|
|
cffi
|
|
|
|
] ++ lib.optionals gurobiSupport ([
|
|
|
|
gurobipy
|
2023-03-24 00:07:29 +00:00
|
|
|
] ++ lib.optional (gurobiHome == null) gurobi);
|
2022-12-28 21:21:41 +00:00
|
|
|
|
|
|
|
# Source files have CRLF terminators, which make patch error out when supplied
|
|
|
|
# with diffs made on *nix machines
|
|
|
|
prePatch = ''
|
|
|
|
find . -type f -exec ${dos2unix}/bin/dos2unix {} \;
|
|
|
|
'';
|
|
|
|
|
|
|
|
patches = [
|
|
|
|
# Some tests try to be smart and dynamically construct a path to their test
|
|
|
|
# inputs. Unfortunately, since the test phase is run after installation,
|
|
|
|
# those paths point to the Nix store, which no longer contains the test
|
|
|
|
# data. This patch hardcodes the data path to point to the source directory.
|
|
|
|
./test-data-path.patch
|
|
|
|
];
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
# Allow cffi versions with a different patch level to be used
|
|
|
|
substituteInPlace pyproject.toml --replace "cffi==1.15.0" "cffi==1.15.*"
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Make MIP use the Gurobi solver, if configured to do so
|
|
|
|
makeWrapperArgs = lib.optional gurobiSupport
|
2023-03-24 00:07:29 +00:00
|
|
|
"--set GUROBI_HOME ${if gurobiHome == null then gurobi.outPath else gurobiHome}";
|
2022-12-28 21:21:41 +00:00
|
|
|
|
|
|
|
# Tests that rely on Gurobi are activated only when Gurobi support is enabled
|
|
|
|
disabledTests = lib.optional (!gurobiSupport) "gurobi";
|
|
|
|
|
|
|
|
passthru.optional-dependencies = {
|
|
|
|
inherit gurobipy numpy;
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = with lib; {
|
2023-02-02 18:25:31 +00:00
|
|
|
homepage = "https://python-mip.com/";
|
2022-12-28 21:21:41 +00:00
|
|
|
description = "A collection of Python tools for the modeling and solution of Mixed-Integer Linear programs (MIPs)";
|
|
|
|
downloadPage = "https://github.com/coin-or/python-mip/releases";
|
|
|
|
changelog = "https://github.com/coin-or/python-mip/releases/tag/${version}";
|
|
|
|
license = licenses.epl20;
|
|
|
|
maintainers = with maintainers; [ nessdoor ];
|
|
|
|
};
|
|
|
|
}
|