1{ lib 2, buildPythonPackage 3, fetchFromGitHub 4# build inputs 5, numpy 6, opencv4 7, scipy 8, pandas 9, pillow 10, pyyaml 11, iopath 12, pdfplumber 13, pdf2image 14, google-cloud-vision 15, pytesseract 16, torch 17, torchvision 18, effdet 19# check inputs 20, pytestCheckHook 21}: 22let 23 pname = "layoutparser"; 24 version = "0.3.4"; 25 optional-dependencies = { 26 ocr = [ google-cloud-vision pytesseract ]; 27 gcv = [ google-cloud-vision ]; 28 tesseract = [ pytesseract ]; 29 layoutmodels = [ torch torchvision effdet ]; 30 effdet = [ torch torchvision effdet ]; 31 # paddledetection = [ paddlepaddle ] 32 }; 33in 34buildPythonPackage { 35 inherit pname version; 36 format = "setuptools"; 37 38 src = fetchFromGitHub { 39 owner = "Layout-Parser"; 40 repo = "layout-parser"; 41 rev = "refs/tags/v${version}"; 42 hash = "sha256-qBzcIUmgnGy/Xn/B+7UrLrRhCvCkapL+ymqGS2sMVgA="; 43 }; 44 45 postPatch = '' 46 substituteInPlace setup.py \ 47 --replace "opencv-python" "opencv" 48 ''; 49 50 propagatedBuildInputs = [ 51 numpy 52 opencv4 53 scipy 54 pandas 55 pillow 56 pyyaml 57 iopath 58 pdfplumber 59 pdf2image 60 ]; 61 62 pythonImportsCheck = [ 63 "layoutparser" 64 ]; 65 66 nativeCheckInputs = [ 67 pytestCheckHook 68 ] ++ optional-dependencies.ocr; 69 70 disabledTests = [ 71 "test_PaddleDetectionModel" # requires paddlepaddle not yet packaged 72 # requires detectron2 not yet packaged 73 "test_Detectron2Model" 74 "test_AutoModel" 75 # requires effdet (disable for now until effdet builds on darwin) 76 "test_EffDetModel" 77 # problems with google-cloud-vision 78 # AttributeError: module 'google.cloud.vision' has no attribute 'types' 79 "test_gcv_agent" 80 "test_viz" 81 # - Failed: DID NOT RAISE <class 'ImportError'> 82 "test_when_backends_are_not_loaded" 83 ]; 84 85 disabledTestPaths = [ 86 "tests_deps/test_only_detectron2.py" # requires detectron2 not yet packaged 87 "tests_deps/test_only_effdet.py" # requires effdet (disable for now until effdet builds on darwin) 88 "tests_deps/test_only_paddledetection.py" # requires paddlepaddle not yet packaged 89 ]; 90 91 passthru.optional-dependencies = optional-dependencies; 92 93 meta = with lib; { 94 description = "A unified toolkit for Deep Learning Based Document Image Analysis"; 95 homepage = "https://github.com/Layout-Parser/layout-parser"; 96 changelog = "https://github.com/Layout-Parser/layout-parser/releases/tag/v${version}"; 97 license = licenses.asl20; 98 maintainers = with maintainers; [ happysalada ]; 99 }; 100}