summary refs log tree commit diff
path: root/pkgs/applications/misc/ocropus/default.nix
blob: ef371dc59fff98ebda4409f54a176174b945f767 (plain) (blame)
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
{ stdenv, fetchFromGitHub, fetchurl, pythonPackages, curl }:

let
  getmodel = name: sha256: {
    inherit name;
    src = fetchurl {
      url = "http://www.tmbdev.net/ocropy/${name}";
      inherit sha256;
    };
  };

  models = [
    (getmodel "en-default.pyrnn.gz"
      "1xyi3k3p81mfw0491gb1haisazfyi2i18f1wjs1m34ak39qfqjdp")
    (getmodel "fraktur.pyrnn.gz"
      "1wlwvxn91ilgmlri1hj81arl3mbzxc24ycdnkf5icq4hdi4c6y8b")
  ];

in
pythonPackages.buildPythonApplication rec {
  pname = "ocropus";
  version = "1.3.3";

  src = fetchFromGitHub {
    sha256 = "02p1334mic5cfhvpfphfrbim4036yfd8s2zzpwm0xmm829z71nr7";
    rev = "v${version}";
    repo = "ocropy";
    owner = "tmbdev";
  };

  propagatedBuildInputs = with pythonPackages; [ curl numpy scipy pillow
    matplotlib beautifulsoup4 pygtk lxml ];

  enableParallelBuilding = true;

  preConfigure = with stdenv.lib; ''
    ${concatStrings (map (x: "cp -R ${x.src} models/`basename ${x.name}`;")
      models)}

    substituteInPlace ocrolib/common.py --replace /usr/local $out
    substituteInPlace ocrolib/default.py --replace /usr/local $out
  '';

  doCheck = false;  # fails
  checkPhase = ''
    patchShebangs .
    substituteInPlace ./run-test \
      --replace 'ocropus-rpred' 'ocropus-rpred -Q $NIX_BUILD_CORES'
    PATH=".:$PATH" ./run-test
  '';

  meta = with stdenv.lib; {
    description = "Open source document analysis and OCR system";
    license = licenses.asl20;
    homepage = "https://github.com/tmbdev/ocropy/";
    maintainers = with maintainers; [ domenkozar ];
    platforms = platforms.linux;
  };
}