From e928afbe8b5498279f9b88aeab676a78b2af28fb Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Tue, 21 Nov 2023 01:46:30 +0100 Subject: [PATCH] normcap: refactor, wrap with runtime inputs, enable checks, add maintainer pbsds --- .../applications/graphics/normcap/default.nix | 52 -------- pkgs/by-name/no/normcap/package.nix | 117 ++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 - 3 files changed, 117 insertions(+), 54 deletions(-) delete mode 100644 pkgs/applications/graphics/normcap/default.nix create mode 100644 pkgs/by-name/no/normcap/package.nix diff --git a/pkgs/applications/graphics/normcap/default.nix b/pkgs/applications/graphics/normcap/default.nix deleted file mode 100644 index 820ca9903394..000000000000 --- a/pkgs/applications/graphics/normcap/default.nix +++ /dev/null @@ -1,52 +0,0 @@ -# From NUR https://github.com/nix-community/nur-combined/blob/6bddae47680482383b5769dd3aa7d82b88e6cbc8/repos/renesat/pkgs/normcap/default.nix - -{ - lib, - stdenv, - python3, - fetchFromGitHub, - tesseract4, - leptonica, - wl-clipboard -}: -python3.pkgs.buildPythonApplication rec { - pname = "normcap"; - version = "0.4.4"; - format = "pyproject"; - - src = fetchFromGitHub { - owner = "dynobo"; - repo = "normcap"; - rev = "v${version}"; - hash = "sha256-dShtmoqS9TC3PHuwq24OEOhYfBHGhDCma8Du8QCkFuI="; - }; - - buildInputs = [ - wl-clipboard - ]; - - nativeBuildInputs = with python3.pkgs; [ - poetry-core - ]; - - propagatedBuildInputs = with python3.pkgs; [ - tesseract4 - leptonica - pyside6 - - # Test - toml - pytest-qt - ]; - - postPatch = '' - substituteInPlace pyproject.toml --replace 'PySide6-Essentials = "6.5.1"' "" - ''; - - 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 ]; - }; -} diff --git a/pkgs/by-name/no/normcap/package.nix b/pkgs/by-name/no/normcap/package.nix new file mode 100644 index 000000000000..8db68e9ae7e2 --- /dev/null +++ b/pkgs/by-name/no/normcap/package.nix @@ -0,0 +1,117 @@ +{ 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.4.4"; + format = "pyproject"; + + disabled = ps.pythonOlder "3.9"; + + src = fetchFromGitHub { + owner = "dynobo"; + repo = "normcap"; + rev = "refs/tags/v${version}"; + hash = "sha256-dShtmoqS9TC3PHuwq24OEOhYfBHGhDCma8Du8QCkFuI="; + }; + + pythonRemoveDeps = [ + "PySide6-Essentials" + ]; + + nativeBuildInputs = [ + ps.pythonRelaxDepsHook + ps.poetry-core + ]; + + propagatedBuildInputs = [ + ps.pyside6 + ]; + + 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 + kill $xvfb_pid + ''; + + disabledTests = [ + # requires a wayland session (no xclip support) + "test_wl_copy" + # times out, unknown why + "test_update_checker_triggers_checked_signal" + # touches network + "test_urls_reachable" + # requires xdg + "test_synchronized_capture" + ] ++ lib.optionals stdenv.isDarwin [ + # requires impure pbcopy + "test_get_copy_func_with_pbcopy" + "test_get_copy_func_without_pbcopy" + "test_perform_pbcopy" + ]; + + disabledTestPaths = [ + # touches network + "tests/tests_gui/test_downloader.py" + # fails to import, causes pytest to freeze + "tests/tests_gui/test_language_manager.py" + ] ++ lib.optionals stdenv.isDarwin [ + # requires a display + "tests/integration/test_normcap.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"; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 0a4e6728c301..b45b472a4ab6 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -34370,8 +34370,6 @@ with pkgs; nomacs = libsForQt5.callPackage ../applications/graphics/nomacs { }; - normcap = callPackage ../applications/graphics/normcap { }; - notepad-next = libsForQt5.callPackage ../applications/editors/notepad-next { }; notepadqq = libsForQt5.callPackage ../applications/editors/notepadqq { };