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/d7/e0/1c3f7b6caa09383a518049249442eec50a5808aef87454c350660d8ce9c5/ocrmypdf-11.3.4.tar.gz" sha256 "91e7394172cedb3be801a229dbd3d308fb5ae80cbc3a77879fa7954beea407b1" license "MPL-2.0" livecheck do url :stable end bottle do cellar :any sha256 "4cb78737841280a6fed3054f18ff415d6368a5c2819c83b7ab2dc569df6a405a" => :big_sur sha256 "283653de1e03eae50b904b6ba2bf8d6f8e4a5cf2ca1d8047b8de9b0b4edcb122" => :catalina sha256 "6e5213d92616203a7fb0dd5543f36d2c42d68c1b0598db793839f11a84005eff" => :mojave 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/66/6a/98e023b3d11537a5521902ac6b50db470c826c682be6a8c661549cb7717a/cffi-1.14.4.tar.gz" sha256 "1a465cbe98a7fd391d47dce4b8f7e5b921e6cd805ef421d04f5f66ba8f06086c" 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/1f/6c/bddbe81bb6b0f03088069ef3a7346be5218cb0689025fa6c6c8dc1886da2/humanfriendly-9.0.tar.gz" sha256 "175ffa628aa76da2c17369a5da5856084562cc66dfe7f82ae93ca3ef175277a6" 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/db/f7/43fecb94d66959c1e23aa53d6161231dca0e93ec500224cf31b3c4073e37/lxml-4.6.2.tar.gz" sha256 "cd11c7e8d21af997ee8079037fff88f16fda188a9776eb4b81c7e4c9c0a7d7fc" 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/cb/28/73d9209d762edfbc5f45c65b662949ad792255d2aec4496fb128d1b21918/pikepdf-2.2.0.tar.gz" sha256 "74300a32c41b3d578772f6933f23a88b19f74484185e71e5225ce2f7ea5aea78" 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/26/ba/02e09b8ab70bb2143d13fc3c674d6c4223bce0817fc7868ffefb528a361c/reportlab-3.5.56.tar.gz" sha256 "51b16e297f7b937fc530dd151e4b38f1d305b01c9aa10657bc32a5d2901b8ad7" 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/3a/76/467422c5a0157c92a8b8e1ffe14411443682e2951e6f6dde3748e47b31ba/tqdm-4.54.0.tar.gz" sha256 "5c0d04e06ccc0da1bd3fa5ae4550effcce42fcad947b4a6cafa77bdc9b09ff22" 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