164 lines
6.9 KiB
Ruby
164 lines
6.9 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/2f/5e/f39d0fe72379684a514501509fc086257bcb9bf031d0cdc1a5eced5f6147/ocrmypdf-11.3.3.tar.gz"
|
|
sha256 "20722d89d2f0deeb5b3ffa8622ead59d54af46d44f21848ec0f15ef79ce1a4a3"
|
|
license "MPL-2.0"
|
|
|
|
livecheck do
|
|
url :stable
|
|
end
|
|
|
|
bottle do
|
|
cellar :any
|
|
sha256 "d98cdaf197950917d763a3115cd82412a9f242134b3287efe8e2540f35bf0031" => :big_sur
|
|
sha256 "f709145025e09ca214e13f6b6d6712c7d06a1264fdba42518707c8d1536dae13" => :catalina
|
|
sha256 "22578c653cce0dbd9372f272e6f2021541fea3042e43028741c8188edaa8eb87" => :mojave
|
|
sha256 "642a4b323a20d9f5720cf2202b07eb8b4f866b6fa7cd8d64cbb48db5b3bc0d82" => :high_sierra
|
|
end
|
|
|
|
depends_on "pkg-config" => :build
|
|
depends_on "freetype"
|
|
depends_on "ghostscript"
|
|
depends_on "jbig2enc"
|
|
depends_on "jpeg"
|
|
depends_on "leptonica"
|
|
depends_on "libpng"
|
|
depends_on "pngquant"
|
|
depends_on "pybind11"
|
|
depends_on "python@3.9"
|
|
depends_on "qpdf"
|
|
depends_on "tesseract"
|
|
depends_on "unpaper"
|
|
|
|
uses_from_macos "libffi"
|
|
uses_from_macos "libxml2"
|
|
uses_from_macos "libxslt"
|
|
uses_from_macos "zlib"
|
|
|
|
resource "cffi" do
|
|
url "https://files.pythonhosted.org/packages/cb/ae/380e33d621ae301770358eb11a896a34c34f30db188847a561e8e39ee866/cffi-1.14.3.tar.gz"
|
|
sha256 "f92f789e4f9241cd262ad7a555ca2c648a98178a953af117ef7fad46aa1d5591"
|
|
end
|
|
|
|
resource "chardet" do
|
|
url "https://files.pythonhosted.org/packages/fc/bb/a5768c230f9ddb03acc9ef3f0d4a3cf93462473795d18e9535498c8f929d/chardet-3.0.4.tar.gz"
|
|
sha256 "84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae"
|
|
end
|
|
|
|
resource "coloredlogs" do
|
|
url "https://files.pythonhosted.org/packages/84/1b/1ecdd371fa68839cfbda15cc671d0f6c92d2c42688df995a9bf6e36f3511/coloredlogs-14.0.tar.gz"
|
|
sha256 "a1fab193d2053aa6c0a97608c4342d031f1f93a3d1218432c59322441d31a505"
|
|
end
|
|
|
|
resource "cryptography" do
|
|
url "https://files.pythonhosted.org/packages/94/5c/42de91c7fbdb817b2d9a4e64b067946eb38a4eb36c1a09c96c87a0f86a82/cryptography-3.2.1.tar.gz"
|
|
sha256 "d3d5e10be0cf2a12214ddee45c6bd203dab435e3d83b4560c03066eda600bfe3"
|
|
end
|
|
|
|
resource "humanfriendly" do
|
|
url "https://files.pythonhosted.org/packages/6c/19/8e3b4c6fa7cca4788817db398c05274d98ecc6a35e0eaad2846fde90c863/humanfriendly-8.2.tar.gz"
|
|
sha256 "bf52ec91244819c780341a3438d5d7b09f431d3f113a475147ac9b7b167a3d12"
|
|
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/c5/2f/a0d8aa3eee6d53d5723d89e1fc32eee11e76801b424e30b55c7aa6302b01/lxml-4.6.1.tar.gz"
|
|
sha256 "c152b2e93b639d1f36ec5a8ca24cde4a8eefb2b6b83668fcd8e83a67badcb367"
|
|
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/40/49/e43a11422bb676061c764e21a4e410e3e7b0ef29a1dfe7a36cc52f44dff6/pikepdf-2.0.0.tar.gz"
|
|
sha256 "c539b944234e6f8facaf437f5be259bad6f74b78f1a8e912b430a9474139171d"
|
|
end
|
|
|
|
resource "Pillow" do
|
|
url "https://files.pythonhosted.org/packages/2b/06/93bf1626ef36815010e971a5ce90f49919d84ab5d2fa310329f843a74bc1/Pillow-8.0.1.tar.gz"
|
|
sha256 "11c5c6e9b02c9dac08af04f093eb5a2f84857df70a7d4a6a6ad461aca803fb9e"
|
|
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/bf/2a/c6aa4903a299b8bf1af35e9aca8967615ddc6d8461c2f6b028bf379e0b27/reportlab-3.5.55.tar.gz"
|
|
sha256 "4f307accda32c9f17015ed77c7424f904514e349dff063f78d2462d715963e53"
|
|
end
|
|
|
|
resource "six" do
|
|
url "https://files.pythonhosted.org/packages/6b/34/415834bfdafca3c5f451532e8a8d9ba89a21c9743a0c59fbd0205c7f9426/six-1.15.0.tar.gz"
|
|
sha256 "30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"
|
|
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/88/e6/13dde83089386c9aa200c4539891948094443d4f6fe85fe95c7806c1f3d5/tqdm-4.51.0.tar.gz"
|
|
sha256 "ef54779f1c09f346b2b5a8e5c61f96fbcb639929e640e59f8cf810794f406432"
|
|
end
|
|
|
|
def install
|
|
venv = virtualenv_create(libexec, Formula["python@3.9"].bin/"python3")
|
|
|
|
resource("Pillow").stage do
|
|
inreplace "setup.py" do |s|
|
|
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')"
|
|
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
|
|
|
|
# avoid triggering "helpful" distutils code that doesn't recognize Xcode 7 .tbd stubs
|
|
unless MacOS::CLT.installed?
|
|
ENV.append "CFLAGS", "-I#{MacOS.sdk_path}/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers"
|
|
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
|