summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/layoutparser/default.nix
blob: 8339c38aee193e4ea6231759f98fef8d01ccc1dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
{
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  # build inputs
  numpy,
  opencv-python,
  scipy,
  pandas,
  pillow,
  pyyaml,
  iopath,
  pdfplumber,
  pdf2image,
  google-cloud-vision,
  pytesseract,
  torch,
  torchvision,
  effdet,
  # check inputs
  pytestCheckHook,
}:
let
  pname = "layoutparser";
  version = "0.3.4";
  optional-dependencies = {
    ocr = [
      google-cloud-vision
      pytesseract
    ];
    gcv = [ google-cloud-vision ];
    tesseract = [ pytesseract ];
    layoutmodels = [
      torch
      torchvision
      effdet
    ];
    effdet = [
      torch
      torchvision
      effdet
    ];
    # paddledetection = [ paddlepaddle ]
  };
in
buildPythonPackage {
  inherit pname version;
  format = "setuptools";

  src = fetchFromGitHub {
    owner = "Layout-Parser";
    repo = "layout-parser";
    tag = "v${version}";
    hash = "sha256-qBzcIUmgnGy/Xn/B+7UrLrRhCvCkapL+ymqGS2sMVgA=";
  };

  propagatedBuildInputs = [
    numpy
    opencv-python
    scipy
    pandas
    pillow
    pyyaml
    iopath
    pdfplumber
    pdf2image
  ];

  pythonImportsCheck = [ "layoutparser" ];

  nativeCheckInputs = [ pytestCheckHook ] ++ optional-dependencies.ocr;

  disabledTests = [
    "test_PaddleDetectionModel" # requires paddlepaddle not yet packaged
    # requires detectron2 not yet packaged
    "test_Detectron2Model"
    "test_AutoModel"
    # requires effdet (disable for now until effdet builds on darwin)
    "test_EffDetModel"
    # problems with google-cloud-vision
    # AttributeError: module 'google.cloud.vision' has no attribute 'types'
    "test_gcv_agent"
    "test_viz"
    #  - Failed: DID NOT RAISE <class 'ImportError'>
    "test_when_backends_are_not_loaded"
  ];

  disabledTestPaths = [
    "tests_deps/test_only_detectron2.py" # requires detectron2 not yet packaged
    "tests_deps/test_only_effdet.py" # requires effdet (disable for now until effdet builds on darwin)
    "tests_deps/test_only_paddledetection.py" # requires paddlepaddle not yet packaged
  ];

  optional-dependencies = optional-dependencies;

  meta = {
    description = "Unified toolkit for Deep Learning Based Document Image Analysis";
    homepage = "https://github.com/Layout-Parser/layout-parser";
    changelog = "https://github.com/Layout-Parser/layout-parser/releases/tag/v${version}";
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ happysalada ];
  };
}