From fddd11e0022436309a5b225d11772f08d2001c91 Mon Sep 17 00:00:00 2001 From: happysalada Date: Thu, 24 Aug 2023 22:53:13 +0800 Subject: [PATCH] python310Packages.pdf2docx: init at 0.5.6 --- .../python-modules/pdf2docx/default.nix | 70 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 2 + 2 files changed, 72 insertions(+) create mode 100644 pkgs/development/python-modules/pdf2docx/default.nix diff --git a/pkgs/development/python-modules/pdf2docx/default.nix b/pkgs/development/python-modules/pdf2docx/default.nix new file mode 100644 index 000000000000..fc9987d3e903 --- /dev/null +++ b/pkgs/development/python-modules/pdf2docx/default.nix @@ -0,0 +1,70 @@ +{ stdenv +, lib +, fetchFromGitHub +, python +, buildPythonPackage +, pythonRelaxDepsHook +, imagemagick +, pytestCheckHook +, pymupdf +, fire +, fonttools +, numpy +, opencv4 +, tkinter +, python-docx +}: +let + version = "0.5.6"; +in +buildPythonPackage { + pname = "pdf2docx"; + inherit version; + format = "setuptools"; + + src = fetchFromGitHub { + owner = "dothinking"; + repo = "pdf2docx"; + rev = "v${version}"; + hash = "sha256-NrT4GURQIJbqnHstfJrPzwLXT9c2oGBi4QJ6eGIFwu4="; + }; + + nativeBuildInputs = [ pythonRelaxDepsHook imagemagick ]; + pythonRemoveDeps = [ "opencv-python" ]; + + preBuild = "echo '${version}' > version.txt"; + + propagatedBuildInputs = [ + tkinter + pymupdf + fire + fonttools + numpy + opencv4 + python-docx + ]; + + postInstall = lib.optionalString stdenv.isLinux '' + # on linux the icon file can only be xbm format + convert $out/${python.sitePackages}/pdf2docx/gui/icon.ico \ + $out/${python.sitePackages}/pdf2docx/gui/icon.xbm + substituteInPlace $out/${python.sitePackages}/pdf2docx/gui/App.py \ + --replace 'icon.ico' 'icon.xbm' \ + --replace 'iconbitmap(icon_path)' "iconbitmap(f'@{icon_path}')" + ''; + + nativeCheckInputs = [ pytestCheckHook ]; + + pytestFlagsArray = [ "-v" "./test/test.py::TestConversion" ]; + + # Test fails due to "RuntimeError: cannot find builtin font with name 'Arial'": + disabledTests = [ "test_unnamed_fonts" ]; + + meta = with lib; { + description = "Convert PDF to DOCX"; + homepage = "https://github.com/dothinking/pdf2docx"; + changelog = "https://github.com/dothinking/pdf2docx/releases/tag/v${version}"; + license = licenses.gpl3Only; + maintainers = with maintainers; [ happysalada ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 95782fe71c36..d2e1d80be6a3 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -7816,6 +7816,8 @@ self: super: with self; { pdb2pqr = callPackage ../development/python-modules/pdb2pqr { }; + pdf2docx = callPackage ../development/python-modules/pdf2docx { }; + pdf2image = callPackage ../development/python-modules/pdf2image { }; pdfkit = callPackage ../development/python-modules/pdfkit { };