btrbk: add mainProgram (#356350)
[NixPkgs.git] / pkgs / by-name / no / normcap / package.nix
blob8404231fa3921f92f6765d40b87021a993b4e266
1 { lib
2 , stdenv
3 , python3
4 , fetchFromGitHub
5 , tesseract4
6 , leptonica
7 , wl-clipboard
8 , libnotify
9 , xorg
10 , makeDesktopItem
11 , copyDesktopItems
14 let
16   ps = python3.pkgs;
18   wrapperDeps = [
19     leptonica
20     tesseract4
21     libnotify
22   ] ++ lib.optionals stdenv.hostPlatform.isLinux [
23     wl-clipboard
24   ];
28 ps.buildPythonApplication rec {
29   pname = "normcap";
30   version = "0.5.8";
31   format = "pyproject";
33   disabled = ps.pythonOlder "3.9";
35   src = fetchFromGitHub {
36     owner = "dynobo";
37     repo = "normcap";
38     rev = "refs/tags/v${version}";
39     hash = "sha256-iMlW8oEt4OSipJaQ2XzBZeBVqiZP/C1sM0f5LYjv7/A=";
40   };
42   pythonRemoveDeps = [
43     "pyside6-essentials"
44   ];
46   pythonRelaxDeps = [
47     "shiboken6"
48   ];
50   build-system = [
51     ps.hatchling
52     ps.babel
53   ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
54     ps.toml
55   ];
57   nativeBuildInputs = [
58     copyDesktopItems
59   ];
61   dependencies = [
62     ps.pyside6
63     ps.jeepney
64   ];
66   preFixup = ''
67     makeWrapperArgs+=(
68       "''${qtWrapperArgs[@]}"
69       --set QT_QPA_PLATFORM xcb
70       --prefix PATH : ${lib.makeBinPath wrapperDeps}
71     )
72   '';
74   postInstall = lib.optionalString stdenv.hostPlatform.isLinux ''
75     mkdir -p $out/share/pixmaps
76     ln -s $out/${python3.sitePackages}/normcap/resources/icons/normcap.png $out/share/pixmaps/
77   '';
79   nativeCheckInputs = wrapperDeps ++ [
80     ps.pytestCheckHook
81     ps.pytest-cov-stub
82     ps.pytest-instafail
83     ps.pytest-qt
84     ps.toml
85   ] ++ lib.optionals stdenv.hostPlatform.isLinux [
86     ps.pytest-xvfb
87     xorg.xvfb
88   ];
90   preCheck = ''
91     export HOME=$(mktemp -d)
92   '' + lib.optionalString stdenv.hostPlatform.isLinux ''
93     # setup a virtual x11 display
94     export DISPLAY=:$((2000 + $RANDOM % 1000))
95     Xvfb $DISPLAY -screen 5 1024x768x8 &
96     xvfb_pid=$!
97   '';
99   postCheck = lib.optionalString stdenv.hostPlatform.isLinux ''
100     # cleanup the virtual x11 display
101     sleep 0.5
102     kill $xvfb_pid
103   '';
105   disabledTests = [
106     # requires a wayland session (no xclip support)
107     "test_wl_copy"
108     # RuntimeError: Please destroy the QApplication singleton before creating a new QApplication instance
109     "test_get_application"
110     # times out, unknown why
111     "test_update_checker_triggers_checked_signal"
112     # touches network
113     "test_urls_reachable"
114     # requires xdg
115     "test_synchronized_capture"
116     # flaky
117     "test_normcap_ocr_testcases"
118   ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
119     # requires display
120     "test_send_via_qt_tray"
121     "test_screens"
122     # requires impure pbcopy
123     "test_get_copy_func_with_pbcopy"
124     "test_get_copy_func_without_pbcopy"
125     "test_perform_pbcopy"
126     "test_pbcopy"
127     "test_copy"
128     # NSXPCSharedListener endpointForReply:withListenerName:replyErrorCode:
129     # while obtaining endpoint 'ClientCallsAuxiliary': Connection interrupted
130     # since v5.0.0
131     "test_introduction_initialize_checkbox_state"
132     "test_introduction_checkbox_sets_return_code"
133     "test_introduction_toggle_checkbox_changes_return_code"
134     "test_show_introduction"
135   ];
137   disabledTestPaths = [
138     # touches network
139     "tests/tests_gui/test_downloader.py"
140     # fails to import, causes pytest to freeze
141     "tests/tests_gui/test_language_manager.py"
142     # RuntimeError("Internal C++ object (PySide6.QtGui.QHideEvent) already deleted.")
143     # AttributeError("'LoadingIndicator' object has no attribute 'timer'")
144     "tests/tests_gui/test_loading_indicator.py"
145   ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
146     # requires a display
147     "tests/integration/test_normcap.py"
148     "tests/integration/test_tray_menu.py"
149     "tests/integration/test_settings_menu.py"
150     "tests/tests_clipboard/test_handlers/test_qtclipboard.py"
151     "tests/tests_gui/test_tray.py"
152     "tests/tests_gui/test_window.py"
153     "tests/tests_screengrab/"
154     # failure unknown, crashes in first test with `.show()`
155     "tests/tests_gui/test_loading_indicator.py"
156     "tests/tests_gui/test_menu_button.py"
157     "tests/tests_gui/test_resources.py"
158     "tests/tests_gui/test_update_check.py"
159   ];
161   desktopItems = [
162     (makeDesktopItem {
163       name = "com.github.dynobo.normcap";
164       desktopName = "NormCap";
165       genericName = "OCR powered screen-capture tool";
166       comment = "Extract text from an image directly into clipboard";
167       exec = "normcap";
168       icon = "normcap";
169       terminal = false;
170       categories = ["Utility" "Office"];
171       keywords = ["Text" "Extraction" "OCR"];
172     })
173   ];
175   meta = with lib; {
176     description = "OCR powered screen-capture tool to capture information instead of images";
177     homepage = "https://dynobo.github.io/normcap/";
178     license = licenses.gpl3Plus;
179     maintainers = with maintainers; [ cafkafk pbsds ];
180     mainProgram = "normcap";
181   };