24 src = fetchFromGitHub {
27 rev = "refs/tags/v${version}";
28 hash = "sha256-+iY+/IdOgsn+LPZQ4Kdzxuh31csQ7dyh5Zf552ne3N0=";
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=";
35 } + "/required_for_whl_v1.3.0/resources/models";
38 pname = "rapidocr-onnxruntime";
42 sourceRoot = "${src.name}/python";
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.
56 src = ./setup-py-override-version-checking.patch;
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
75 # Upstream expects the source files to be under rapidocr_onnxruntime/rapidocr_onnxruntime
76 # instead of rapidocr_onnxruntime for the wheel to build correctly.
78 mkdir rapidocr_onnxruntime_t
79 mv rapidocr_onnxruntime rapidocr_onnxruntime_t
80 mv rapidocr_onnxruntime_t rapidocr_onnxruntime
83 # Revert the above hack
85 mv rapidocr_onnxruntime rapidocr_onnxruntime_t
86 mv rapidocr_onnxruntime_t/* .
89 build-system = [ setuptools ];
102 pythonImportsCheck = [ "rapidocr_onnxruntime" ];
104 nativeCheckInputs = [ pytestCheckHook ];
106 # These are tests for different backends.
107 disabledTestPaths = [
109 "tests/test_paddle.py"
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";