homebrew-core/Formula/ocrmypdf.rb

166 lines
6.7 KiB
Ruby

class Ocrmypdf < Formula
include Language::Python::Virtualenv
desc "Adds an OCR text layer to scanned PDF files"
homepage "https://github.com/jbarlow83/OCRmyPDF"
url "https://files.pythonhosted.org/packages/c2/0b/f15c5f5398d40d3d04d93488e8d932d029f9c82f1ae3032c9c54269b4a16/ocrmypdf-12.0.1.tar.gz"
sha256 "c18db17e18984f540eaa774245571e3ec63a74f459b6029de561a06a77e78310"
license "MPL-2.0"
bottle do
sha256 cellar: :any, arm64_big_sur: "d874962c0c0546ff6c7e22cafa6fc52e3d8011a4b5b872bbdc19e617d0d5c153"
sha256 cellar: :any, big_sur: "079ad48ce0fce01857de8148523474f350f58c97d8f6d088a22f40c78b302187"
sha256 cellar: :any, catalina: "7042c307a55bea034ae258834114349b362afc5c102a217fdd2467b2dec21599"
sha256 cellar: :any, mojave: "fb1636a524f37f738026abf6fe2c3101ccaea67989c41ac21413794544527d51"
end
depends_on "pkg-config" => :build
depends_on "rust" => :build
depends_on "freetype"
depends_on "ghostscript"
depends_on "jbig2enc"
depends_on "jpeg"
depends_on "leptonica"
depends_on "libffi"
depends_on "libpng"
depends_on "pngquant"
depends_on "pybind11"
depends_on "python@3.9"
depends_on "qpdf"
depends_on "tcl-tk"
depends_on "tesseract"
depends_on "unpaper"
uses_from_macos "libxml2"
uses_from_macos "libxslt"
uses_from_macos "zlib"
on_linux do
depends_on "gcc"
end
fails_with gcc: "5"
resource "cffi" do
url "https://files.pythonhosted.org/packages/a8/20/025f59f929bbcaa579704f443a438135918484fffaacfaddba776b374563/cffi-1.14.5.tar.gz"
sha256 "fd78e5fee591709f32ef6edb9a015b4aa1a5022598e36227500c8f4e02328d9c"
end
resource "chardet" do
url "https://files.pythonhosted.org/packages/ee/2d/9cdc2b527e127b4c9db64b86647d567985940ac3698eeabc7ffaccb4ea61/chardet-4.0.0.tar.gz"
sha256 "0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa"
end
resource "coloredlogs" do
url "https://files.pythonhosted.org/packages/ce/ef/bfca8e38c1802896f67045a0c9ea0e44fc308b182dbec214b9c2dd54429a/coloredlogs-15.0.tar.gz"
sha256 "5e78691e2673a8e294499e1832bb13efcfb44a86b92e18109fa18951093218ab"
end
resource "cryptography" do
url "https://files.pythonhosted.org/packages/9b/77/461087a514d2e8ece1c975d8216bc03f7048e6090c5166bc34115afdaa53/cryptography-3.4.7.tar.gz"
sha256 "3d10de8116d25649631977cb37da6cbdd2d6fa0e0281d014a5b7d337255ca713"
end
resource "humanfriendly" do
url "https://files.pythonhosted.org/packages/31/0e/a2e882aaaa0a378aa6643f4bbb571399aede7dbb5402d3a1ee27a201f5f3/humanfriendly-9.1.tar.gz"
sha256 "066562956639ab21ff2676d1fda0b5987e985c534fc76700a19bd54bcb81121d"
end
resource "img2pdf" do
url "https://files.pythonhosted.org/packages/80/ed/5167992abaf268f5a5867e974d9d36a8fa4802800898ec711f4e1942b4f5/img2pdf-0.4.0.tar.gz"
sha256 "eaee690ab8403dd1a9cb4db10afee41dd3e6c7ed63bdace02a0121f9feadb0c9"
end
resource "lxml" do
url "https://files.pythonhosted.org/packages/e5/21/a2e4517e3d216f0051687eea3d3317557bde68736f038a3b105ac3809247/lxml-4.6.3.tar.gz"
sha256 "39b78571b3b30645ac77b95f7c69d1bffc4cf8c3b157c435a34da72e78c82468"
end
resource "pdfminer.six" do
url "https://files.pythonhosted.org/packages/d8/bb/45cb24e715d3058f92f703265e6ed396767b19fec6d19d1ea54e04b730b7/pdfminer.six-20201018.tar.gz"
sha256 "b9aac0ebeafb21c08bf65f2039f4b2c5f78a3449d0a41df711d72445649e952a"
end
resource "pikepdf" do
url "https://files.pythonhosted.org/packages/1d/a0/7842cf317a3afa8b7d5b45392e5900d088295ba430434bf93aedae67664f/pikepdf-2.11.2.tar.gz"
sha256 "0958a07ebf12d62427babadd6a922409cb358d0415a5219a9269d8fab2aa487e"
end
resource "Pillow" do
url "https://files.pythonhosted.org/packages/21/23/af6bac2a601be6670064a817273d4190b79df6f74d8012926a39bc7aa77f/Pillow-8.2.0.tar.gz"
sha256 "a787ab10d7bb5494e5f76536ac460741788f1fbce851068d73a87ca7c35fc3e1"
end
resource "pluggy" do
url "https://files.pythonhosted.org/packages/f8/04/7a8542bed4b16a65c2714bf76cf5a0b026157da7f75e87cc88774aa10b14/pluggy-0.13.1.tar.gz"
sha256 "15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"
end
resource "pycparser" do
url "https://files.pythonhosted.org/packages/0f/86/e19659527668d70be91d0369aeaa055b4eb396b0f387a4f92293a20035bd/pycparser-2.20.tar.gz"
sha256 "2d475327684562c3a96cc71adf7dc8c4f0565175cf86b6d7a404ff4c771f15f0"
end
resource "reportlab" do
url "https://files.pythonhosted.org/packages/2a/02/078c875d81f231fc11ecda3158a2e2cfccc390a534c316e2524db007e245/reportlab-3.5.67.tar.gz"
sha256 "0cf2206c73fbca752c8bd39e12bb9ad7f2d01e6fcb2b25b9eaf94ea042fe86c9"
end
resource "sortedcontainers" do
url "https://files.pythonhosted.org/packages/14/10/6a9481890bae97da9edd6e737c9c3dec6aea3fc2fa53b0934037b35c89ea/sortedcontainers-2.3.0.tar.gz"
sha256 "59cc937650cf60d677c16775597c89a960658a09cf7c1a668f86e1e4464b10a1"
end
resource "tqdm" do
url "https://files.pythonhosted.org/packages/35/35/bd5af89c97ad5177ed234d9e79d01a984f8b5226b8ffc8b5d3c4fc8e157d/tqdm-4.60.0.tar.gz"
sha256 "ebdebdb95e3477ceea267decfc0784859aa3df3e27e22d23b83e9b272bf157ae"
end
def install
venv = virtualenv_create(libexec, Formula["python@3.9"].bin/"python3")
resource("Pillow").stage do
inreplace "setup.py" do |s|
on_macos do
sdkprefix = MacOS.sdk_path_if_needed ? MacOS.sdk_path : ""
s.gsub! "openjpeg.h", "probably_not_a_header_called_this_eh.h"
s.gsub! "xcb.h", "probably_not_a_header_called_this_eh.h"
s.gsub! "ZLIB_ROOT = None",
"ZLIB_ROOT = ('#{sdkprefix}/usr/lib', '#{sdkprefix}/usr/include')"
end
on_linux do
s.gsub! "ZLIB_ROOT = None",
"ZLIB_ROOT = ('#{Formula["zlib"].opt_prefix}/lib', '#{Formula["zlib"].opt_prefix}/include')"
end
s.gsub! "JPEG_ROOT = None",
"JPEG_ROOT = ('#{Formula["jpeg"].opt_prefix}/lib', '#{Formula["jpeg"].opt_prefix}/include')"
s.gsub! "FREETYPE_ROOT = None",
"FREETYPE_ROOT = ('#{Formula["freetype"].opt_prefix}/lib', " \
"'#{Formula["freetype"].opt_prefix}/include')"
end
venv.pip_install Pathname.pwd
end
# Fix "ld: file not found: /usr/lib/system/libsystem_darwin.dylib" for lxml
ENV["SDKROOT"] = MacOS.sdk_path if MacOS.version == :sierra
res = resources.map(&:name).to_set - ["Pillow"]
res.each do |r|
venv.pip_install resource(r)
end
venv.pip_install_and_link buildpath
bash_completion.install "misc/completion/ocrmypdf.bash" => "ocrmypdf"
fish_completion.install "misc/completion/ocrmypdf.fish"
end
test do
system "#{bin}/ocrmypdf", "-f", "-q", "--deskew",
test_fixtures("test.pdf"), "ocr.pdf"
assert_predicate testpath/"ocr.pdf", :exist?
end
end