about summary refs log tree commit diff
path: root/pkgs/by-name/no/normcap/package.nix
blob: f6e4af16e6b14a428d546a50f7747df2648957f5 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
{ lib
, stdenv
, python3
, fetchFromGitHub
, tesseract4
, leptonica
, wl-clipboard
, libnotify
, xorg
}:

let

  ps = python3.pkgs;

  wrapperDeps = [
    leptonica
    tesseract4
    libnotify
  ] ++ lib.optionals stdenv.isLinux [
    wl-clipboard
  ];

in

ps.buildPythonApplication rec {
  pname = "normcap";
  version = "0.5.4";
  format = "pyproject";

  disabled = ps.pythonOlder "3.9";

  src = fetchFromGitHub {
    owner = "dynobo";
    repo = "normcap";
    rev = "refs/tags/v${version}";
    hash = "sha256-bYja05U/JBwSij1J2LxN+c5Syrb4qzWSZY5+HNmC9Zo=";
  };

  postPatch = ''
    # disable coverage testing
    substituteInPlace pyproject.toml \
      --replace "addopts = [" "addopts_ = ["
  '';

  pythonRemoveDeps = [
    "pyside6-essentials"
  ];

  pythonRelaxDeps = [
    "shiboken6"
  ];

  nativeBuildInputs = [
    ps.pythonRelaxDepsHook
    ps.hatchling
    ps.babel
  ];

  propagatedBuildInputs = [
    ps.pyside6
    ps.jeepney
  ];

  preFixup = ''
    makeWrapperArgs+=(
      "''${qtWrapperArgs[@]}"
      --set QT_QPA_PLATFORM xcb
      --prefix PATH : ${lib.makeBinPath wrapperDeps}
    )
  '';

  nativeCheckInputs = wrapperDeps ++ [
    ps.pytestCheckHook
    ps.pytest-qt
    ps.toml
  ] ++ lib.optionals stdenv.isLinux [
    ps.pytest-xvfb
    xorg.xorgserver
  ];

  preCheck = ''
    export HOME=$(mktemp -d)
  '' + lib.optionalString stdenv.isLinux ''
    # setup a virtual x11 display
    export DISPLAY=:$((2000 + $RANDOM % 1000))
    Xvfb $DISPLAY -screen 5 1024x768x8 &
    xvfb_pid=$!
  '';

  postCheck = lib.optionalString stdenv.isLinux ''
    # cleanup the virtual x11 display
    sleep 0.5
    kill $xvfb_pid
  '';

  disabledTests = [
    # requires a wayland session (no xclip support)
    "test_wl_copy"
    # RuntimeError: Please destroy the QApplication singleton before creating a new QApplication instance
    "test_get_application"
    # times out, unknown why
    "test_update_checker_triggers_checked_signal"
    # touches network
    "test_urls_reachable"
    # requires xdg
    "test_synchronized_capture"
    # flaky
    "test_normcap_ocr_testcases"
  ] ++ lib.optionals stdenv.isDarwin [
    # requires impure pbcopy
    "test_get_copy_func_with_pbcopy"
    "test_get_copy_func_without_pbcopy"
    "test_perform_pbcopy"
    # NSXPCSharedListener endpointForReply:withListenerName:replyErrorCode:
    # while obtaining endpoint 'ClientCallsAuxiliary': Connection interrupted
    # since v5.0.0
    "test_introduction_initialize_checkbox_state"
    "test_introduction_checkbox_sets_return_code"
    "test_introduction_toggle_checkbox_changes_return_code"
    "test_show_introduction"
  ];

  disabledTestPaths = [
    # touches network
    "tests/tests_gui/test_downloader.py"
    # fails to import, causes pytest to freeze
    "tests/tests_gui/test_language_manager.py"
    # RuntimeError("Internal C++ object (PySide6.QtGui.QHideEvent) already deleted.")
    # AttributeError("'LoadingIndicator' object has no attribute 'timer'")
    "tests/tests_gui/test_loading_indicator.py"
  ] ++ lib.optionals stdenv.isDarwin [
    # requires a display
    "tests/integration/test_normcap.py"
    "tests/integration/test_tray_menu.py"
    # failure unknown, crashes in first test with `.show()`
    "tests/tests_gui/test_loading_indicator.py"
  ];

  meta = with lib; {
    description = "OCR powered screen-capture tool to capture information instead of images";
    homepage = "https://dynobo.github.io/normcap/";
    license = licenses.gpl3Plus;
    maintainers = with maintainers; [ cafkafk pbsds ];
    mainProgram = "normcap";
    broken = stdenv.isDarwin;
  };
}