Commit c2526df7 authored by Gaetan Lepage's avatar Gaetan Lepage
Browse files
parent fb1d8dc0
Loading
Loading
Loading
Loading
+37 −16
Original line number Diff line number Diff line
@@ -2,16 +2,15 @@
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  setuptools,
  wheel,
  versionCheckHook,
  withCli ? false,

  # build-system
  poetry-core,
  poetry-dynamic-versioning,

  # dependencies
  jsonschema,
  numpy,
  onnxruntime,
  opencv-python-headless,
  pillow,
  pooch,
  pymatting,
@@ -27,31 +26,44 @@
  filetype,
  gradio,
  python-multipart,
  sniffio,
  uvicorn,
  watchdog,

  # tests
  versionCheckHook,

  withCli ? false,
}:

buildPythonPackage rec {
buildPythonPackage (finalAttrs: {
  pname = "rembg";
  version = "2.0.69";
  version = "2.0.72";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "danielgatis";
    repo = "rembg";
    tag = "v${version}";
    hash = "sha256-9Ncs1DHPG3ouU5yFyeH0M2ZCQ9yHqJhVjkDO8fNSqIg=";
    tag = "v${finalAttrs.version}";
    hash = "sha256-KYpqRuC7EjgH0UqgIoMaeHF3oQSI87j6J3bcqU+43Wo=";
  };

  env.POETRY_DYNAMIC_VERSIONING_BYPASS = finalAttrs.version;

  build-system = [
    setuptools
    wheel
    poetry-core
    poetry-dynamic-versioning
  ];

  pythonRelaxDeps = [
    "jsonschema"
    "pillow"
    "pymatting"
    "scikit-image"
  ];
  dependencies = [
    jsonschema
    numpy
    opencv-python-headless
    onnxruntime
    pillow
    pooch
@@ -60,7 +72,7 @@ buildPythonPackage rec {
    scipy
    tqdm
  ]
  ++ lib.optionals withCli optional-dependencies.cli;
  ++ lib.optionals withCli finalAttrs.passthru.optional-dependencies.cli;

  optional-dependencies = {
    cli = [
@@ -71,6 +83,7 @@ buildPythonPackage rec {
      filetype
      gradio
      python-multipart
      sniffio
      uvicorn
      watchdog
    ];
@@ -83,16 +96,24 @@ buildPythonPackage rec {
  postInstall = lib.optionalString (!withCli) "rm -r $out/bin";

  # not running python tests, as they require network access
  nativeCheckInputs = lib.optionals withCli [ versionCheckHook ];
  nativeCheckInputs = lib.optionals withCli [
    versionCheckHook
  ];
  versionCheckKeepEnvironment = [
    # Otherwise, fail with:
    # RuntimeError: cannot cache function '_make_tree': no locator available for file
    # '{{storeDir}}/lib/python3.13/site-packages/pymatting/util/kdtree.py'
    "NUMBA_CACHE_DIR"
  ];

  pythonImportsCheck = [ "rembg" ];

  meta = {
    description = "Tool to remove background from images";
    homepage = "https://github.com/danielgatis/rembg";
    changelog = "https://github.com/danielgatis/rembg/releases/tag/${src.tag}";
    changelog = "https://github.com/danielgatis/rembg/releases/tag/${finalAttrs.src.tag}";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ defelo ];
    mainProgram = "rembg";
  };
}
})