evcc: 0.131.4 -> 0.131.5
[NixPkgs.git] / pkgs / development / python-modules / rapidocr-onnxruntime / default.nix
blob49ec5f4a5b8bf6fe813896200ffbddd0b651cdab
2   lib,
3   stdenv,
4   buildPythonPackage,
5   fetchFromGitHub,
7   fetchzip,
8   substitute,
9   pytestCheckHook,
11   setuptools,
12   pyclipper,
13   opencv-python,
14   numpy,
15   six,
16   shapely,
17   pyyaml,
18   pillow,
19   onnxruntime,
21 let
22   version = "1.3.24";
24   src = fetchFromGitHub {
25     owner = "RapidAI";
26     repo = "RapidOCR";
27     rev = "refs/tags/v${version}";
28     hash = "sha256-+iY+/IdOgsn+LPZQ4Kdzxuh31csQ7dyh5Zf552ne3N0=";
29   };
31   models = fetchzip {
32     url = "https://github.com/RapidAI/RapidOCR/releases/download/v1.1.0/required_for_whl_v1.3.0.zip";
33     hash = "sha256-j/0nzyvu/HfNTt5EZ+2Phe5dkyPOdQw/OZTz0yS63aA=";
34     stripRoot = false;
35   } + "/required_for_whl_v1.3.0/resources/models";
37 buildPythonPackage {
38   pname = "rapidocr-onnxruntime";
39   inherit version src;
40   pyproject = true;
42   sourceRoot = "${src.name}/python";
44   # HACK:
45   # Upstream uses a very unconventional structure to organize the packages, and we have to coax the
46   # existing infrastructure to work with it.
47   # See https://github.com/RapidAI/RapidOCR/blob/02829ef986bc2a5c4f33e9c45c9267bcf2d07a1d/.github/workflows/gen_whl_to_pypi_rapidocr_ort.yml#L80-L92
48   # for the "intended" way of building this package.
50   # The setup.py supplied by upstream tries to determine the current version by
51   # fetching the latest version of the package from PyPI, and then bumping the version number.
52   # This is not allowed in the Nix build environment as we do not have internet access,
53   # hence we patch that out and get the version from the build environment directly.
54   patches = [
55     (substitute {
56       src = ./setup-py-override-version-checking.patch;
57       substitutions = [
58         "--subst-var-by"
59         "version"
60         version
61       ];
62     })
63   ];
65   postPatch = ''
66     mv setup_onnxruntime.py setup.py
67     mkdir -p rapidocr_onnxruntime/models
69     ln -s ${models}/* rapidocr_onnxruntime/models
71     # Magic patch from upstream - what does this even do??
72     echo "from .rapidocr_onnxruntime.main import RapidOCR, VisRes" > __init__.py
73   '';
75   # Upstream expects the source files to be under rapidocr_onnxruntime/rapidocr_onnxruntime
76   # instead of rapidocr_onnxruntime for the wheel to build correctly.
77   preBuild = ''
78     mkdir rapidocr_onnxruntime_t
79     mv rapidocr_onnxruntime rapidocr_onnxruntime_t
80     mv rapidocr_onnxruntime_t rapidocr_onnxruntime
81   '';
83   # Revert the above hack
84   postBuild = ''
85     mv rapidocr_onnxruntime rapidocr_onnxruntime_t
86     mv rapidocr_onnxruntime_t/* .
87   '';
89   build-system = [ setuptools ];
91   dependencies = [
92     pyclipper
93     opencv-python
94     numpy
95     six
96     shapely
97     pyyaml
98     pillow
99     onnxruntime
100   ];
102   pythonImportsCheck = [ "rapidocr_onnxruntime" ];
104   nativeCheckInputs = [ pytestCheckHook ];
106   # These are tests for different backends.
107   disabledTestPaths = [
108     "tests/test_vino.py"
109     "tests/test_paddle.py"
110   ];
112   meta = {
113     # This seems to be related to https://github.com/microsoft/onnxruntime/issues/10038
114     # Also some related issue: https://github.com/NixOS/nixpkgs/pull/319053#issuecomment-2167713362
115     broken = (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64);
116     changelog = "https://github.com/RapidAI/RapidOCR/releases/tag/v${version}";
117     description = "Cross platform OCR Library based on OnnxRuntime";
118     homepage = "https://github.com/RapidAI/RapidOCR";
119     license = with lib.licenses; [ asl20 ];
120     maintainers = with lib.maintainers; [ pluiedev ];
121     mainProgram = "rapidocr_onnxruntime";
122   };