homebrew-core/Formula/ocrmypdf.rb

142 lines
6.3 KiB
Ruby

class Ocrmypdf < Formula
include Language::Python::Virtualenv
desc "Adds an OCR text layer to scanned PDF files"
homepage "https://ocrmypdf.readthedocs.io/en/latest/"
url "https://files.pythonhosted.org/packages/33/84/eda42f333d0a0d7111ba73fa7c83d931222a8ae24bce051a2dcf42ae808a/ocrmypdf-14.0.1.tar.gz"
sha256 "77fdd52cb925bb94291ae62d22f2cb8253fb4199d0bf33b43e7fb7f078cac51c"
license "MPL-2.0"
bottle do
sha256 cellar: :any, arm64_monterey: "ad68c95dde311e0cd98fbdccff1122a2f82f54a176b4a7d9844cef74c7bfe2e6"
sha256 cellar: :any, arm64_big_sur: "f738d5205a18bf9a5a91613c2922a24049fe37db38175c882942312b9bf30c20"
sha256 cellar: :any, monterey: "5ee482841861f096e51417c042cca6e4d77fb9669b16a25611b19abc6c55aa14"
sha256 cellar: :any, big_sur: "c2c13315fa9acc24e876601d1273133ac410710f62887567bf2ff7f385985419"
sha256 cellar: :any, catalina: "95ab975af5160b9f2dfd2a92c0e519c2fc17ee0143164026876ddb10a17218a6"
sha256 cellar: :any_skip_relocation, x86_64_linux: "5aa6a32acaa09315707d7081d9824d8d7ab1f32357b080596ca2492cac2bbd66"
end
depends_on "pkg-config" => :build
depends_on "rust" => :build
depends_on "freetype"
depends_on "ghostscript"
depends_on "jbig2enc"
depends_on "libpng"
depends_on "pillow"
depends_on "pngquant"
depends_on "pybind11"
depends_on "python@3.10"
depends_on "qpdf"
depends_on "tesseract"
depends_on "unpaper"
uses_from_macos "libffi", since: :catalina
uses_from_macos "libxml2"
uses_from_macos "libxslt"
fails_with gcc: "5"
resource "cffi" do
url "https://files.pythonhosted.org/packages/2b/a8/050ab4f0c3d4c1b8aaa805f70e26e84d0e27004907c5b8ecc1d31815f92a/cffi-1.15.1.tar.gz"
sha256 "d400bfb9a37b1351253cb402671cea7e89bdecc294e8016a707f6d1d8ac934f9"
end
resource "charset-normalizer" do
url "https://files.pythonhosted.org/packages/a1/34/44964211e5410b051e4b8d2869c470ae8a68ae274953b1c7de6d98bbcf94/charset-normalizer-2.1.1.tar.gz"
sha256 "5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845"
end
resource "coloredlogs" do
url "https://files.pythonhosted.org/packages/cc/c7/eed8f27100517e8c0e6b923d5f0845d0cb99763da6fdee00478f91db7325/coloredlogs-15.0.1.tar.gz"
sha256 "7c991aa71a4577af2f82600d8f8f3a89f936baeaf9b50a9c197da014e5bf16b0"
end
resource "cryptography" do
url "https://files.pythonhosted.org/packages/6d/0c/5e67831007ba6cd7e52c4095f053cf45c357739b0a7c46a45ddd50049019/cryptography-38.0.1.tar.gz"
sha256 "1db3d807a14931fa317f96435695d9ec386be7b84b618cc61cfa5d08b0ae33d7"
end
resource "deprecation" do
url "https://files.pythonhosted.org/packages/5a/d3/8ae2869247df154b64c1884d7346d412fed0c49df84db635aab2d1c40e62/deprecation-2.1.0.tar.gz"
sha256 "72b3bde64e5d778694b0cf68178aed03d15e15477116add3fb773e581f9518ff"
end
resource "humanfriendly" do
url "https://files.pythonhosted.org/packages/cc/3f/2c29224acb2e2df4d2046e4c73ee2662023c58ff5b113c4c1adac0886c43/humanfriendly-10.0.tar.gz"
sha256 "6b0b831ce8f15f7300721aa49829fc4e83921a9a301cc7f606be6686a2288ddc"
end
resource "img2pdf" do
url "https://files.pythonhosted.org/packages/95/b5/f933f482a811fb9a7b3707f60e28f2925fed84726e5a6283ba07fdd54f49/img2pdf-0.4.4.tar.gz"
sha256 "8ec898a9646523fd3862b154f3f47cd52609c24cc3e2dc1fb5f0168f0cbe793c"
end
resource "lxml" do
url "https://files.pythonhosted.org/packages/70/bb/7a2c7b4f8f434aa1ee801704bf08f1e53d7b5feba3d5313ab17003477808/lxml-4.9.1.tar.gz"
sha256 "fe749b052bb7233fe5d072fcb549221a8cb1a16725c47c37e42b0b9cb3ff2c3f"
end
resource "packaging" do
url "https://files.pythonhosted.org/packages/df/9e/d1a7217f69310c1db8fdf8ab396229f55a699ce34a203691794c5d1cad0c/packaging-21.3.tar.gz"
sha256 "dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"
end
resource "pdfminer.six" do
url "https://files.pythonhosted.org/packages/73/42/b6b37b4d70c68dcf8f33a9858a02685f8ca5b42312e276fab56c1299967e/pdfminer.six-20220524.tar.gz"
sha256 "5a64c924410ac48501d6060b21638bf401db69f5b1bd57207df7fbc070ac8ae2"
end
resource "pikepdf" do
url "https://files.pythonhosted.org/packages/a2/e7/e52fe97fff88d002d054b4e31198d1e5de52b33508e594fa2dc2d067510d/pikepdf-6.1.0.tar.gz"
sha256 "d140fa7c6ef4b8c91fa1ee360628110cd3e636d0f85717da22f2d772d509a3ed"
end
resource "pluggy" do
url "https://files.pythonhosted.org/packages/a1/16/db2d7de3474b6e37cbb9c008965ee63835bba517e22cdb8c35b5116b5ce1/pluggy-1.0.0.tar.gz"
sha256 "4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"
end
resource "pycparser" do
url "https://files.pythonhosted.org/packages/5e/0b/95d387f5f4433cb0f53ff7ad859bd2c6051051cebbb564f139a999ab46de/pycparser-2.21.tar.gz"
sha256 "e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206"
end
resource "pyparsing" do
url "https://files.pythonhosted.org/packages/71/22/207523d16464c40a0310d2d4d8926daffa00ac1f5b1576170a32db749636/pyparsing-3.0.9.tar.gz"
sha256 "2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb"
end
resource "reportlab" do
url "https://files.pythonhosted.org/packages/a6/d0/bdee3e8a7ba5f2dc8bacea10f4fdd1264b1dd9e53d96d318773180634a00/reportlab-3.6.11.tar.gz"
sha256 "04fc4420f0548815d0623e031c86a1f7f3f3003e699d9af7148742e2d72b024a"
end
resource "tqdm" do
url "https://files.pythonhosted.org/packages/c1/c2/d8a40e5363fb01806870e444fc1d066282743292ff32a9da54af51ce36a2/tqdm-4.64.1.tar.gz"
sha256 "5f4f682a004951c1b450bc753c710e9280c5746ce6ffedee253ddbcbf54cf1e4"
end
def install
venv = virtualenv_create(libexec, "python3.10")
resource("reportlab").stage do
(Pathname.pwd/"local-setup.cfg").write <<~EOS
[FREETYPE_PATHS]
lib=#{Formula["freetype"].opt_lib}
inc=#{Formula["freetype"].opt_include}
EOS
venv.pip_install Pathname.pwd
end
venv.pip_install resources.reject { |r| r.name == "reportlab" }
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