Unverified Commit bfe9c696 authored by Nick Cao's avatar Nick Cao Committed by GitHub
Browse files

python312Packages.pymoo: cleanup, fix build (#400579)

parents 90ef0233 fd303e8e
Loading
Loading
Loading
Loading
+57 −32
Original line number Diff line number Diff line
@@ -2,22 +2,37 @@
  lib,
  buildPythonPackage,
  fetchFromGitHub,

  # build-system
  cython,
  setuptools,
  pytestCheckHook,
  writeText,

  # dependencies
  autograd,
  cma,
  cython,
  deprecated,
  dill,
  matplotlib,
  numpy,
  scipy,

  # tests
  pytestCheckHook,
  nbformat,
  notebook,
  numba,
  numpy,
  scipy,
  pythonAtLeast,
  writeText,
}:

let
  pymoo_data = fetchFromGitHub {
    owner = "anyoptimization";
    repo = "pymoo-data";
    rev = "33f61a78182ceb211b95381dd6d3edee0d2fc0f3";
    hash = "sha256-iGWPepZw3kJzw5HKV09CvemVvkvFQ38GVP+BAryBSs0=";
  };
in
buildPythonPackage rec {
  pname = "pymoo";
  version = "0.6.1.3";
@@ -30,27 +45,32 @@ buildPythonPackage rec {
    hash = "sha256-CbeJwv51lu4cABgGieqy/8DCDJCb8wOPPVqUHk8Jb7E=";
  };

  pymoo_data = fetchFromGitHub {
    owner = "anyoptimization";
    repo = "pymoo-data";
    rev = "33f61a78182ceb211b95381dd6d3edee0d2fc0f3";
    hash = "sha256-iGWPepZw3kJzw5HKV09CvemVvkvFQ38GVP+BAryBSs0=";
  };

  pythonRelaxDeps = [ "cma" ];
  pythonRemoveDeps = [ "alive-progress" ];

  postPatch = ''
    substituteInPlace pymoo/util/display/display.py \
      --replace-fail "from pymoo.util.display.progress import ProgressBar" "" \
      --replace-fail "ProgressBar() if progress else None" \
      --replace-fail \
        "ProgressBar() if progress else None" \
        "print('Missing alive_progress needed for progress=True!') if progress else None"

    substituteInPlace pymoo/algorithms/soo/nonconvex/es.py \
      --replace-fail "np.math.ceil" "np.ceil"
    substituteInPlace pymoo/util/mnn.py \
      --replace-fail "np.product" "np.prod"

    substituteInPlace pymoo/config.py \
      --replace-fail \
        "https://raw.githubusercontent.com/anyoptimization/pymoo-data/main/" \
        "file://${pymoo_data}/"
  '';

  pythonRelaxDeps = [ "cma" ];
  pythonRemoveDeps = [ "alive-progress" ];

  build-system = [
    setuptools
    cython
  ];

  dependencies = [
    autograd
    cma
@@ -62,10 +82,6 @@ buildPythonPackage rec {
  ];

  preCheck = ''
    substituteInPlace pymoo/config.py \
      --replace-fail "https://raw.githubusercontent.com/anyoptimization/pymoo-data/main/" \
                "file://$pymoo_data/"

    # Some tests require a grad backend to be configured, this is a hacky way to do so.
    # The choice must be either "jax.numpy" or "autograd.numpy"
    echo 'from pymoo.gradient import activate; activate("autograd.numpy")' >> tests/conftest.py
@@ -78,7 +94,8 @@ buildPythonPackage rec {
  ];
  # Select some lightweight tests
  pytestFlagsArray = [ "-m 'not long'" ];
  disabledTests = [
  disabledTests =
    [
      # ModuleNotFoundError: No module named 'pymoo.cython.non_dominated_sorting'
      "test_fast_non_dominated_sorting"
      "test_efficient_non_dominated_sort"
@@ -86,6 +103,14 @@ buildPythonPackage rec {

      # sensitive to float precision
      "test_cd_and_pcd"

      # TypeError: 'NoneType' object is not subscriptable
      "test_dascomp"
      "test_mw"
    ]
    ++ lib.optionals (pythonAtLeast "3.13") [
      # AttributeError: 'ZDT3' object has no attribute 'elementwise'
      "test_kktpm_correctness"
    ];
  disabledTestPaths = [
    # sensitive to float precision
@@ -98,10 +123,10 @@ buildPythonPackage rec {

  pythonImportsCheck = [ "pymoo" ];

  meta = with lib; {
  meta = {
    description = "Multi-objective Optimization in Python";
    homepage = "https://pymoo.org/";
    license = licenses.asl20;
    maintainers = with maintainers; [ veprbl ];
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ veprbl ];
  };
}