repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
OCRmyPDF | misc/synology.py | .py | #!/bin/env python3
# SPDX-FileCopyrightText: 2017 Enantiomerie
# SPDX-License-Identifier: MIT
"""Example OCRmyPDF for Synology NAS."""
from __future__ import annotations
# This script must be edited to meet your needs.
import logging
import os
import shutil
import subprocess
import sys
import time
from pathlib impor... | 78 | 2,278 |
OCRmyPDF | misc/_webservice.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: AGPL-3.0-or-later
"""This is a simple web service/HTTP wrapper for OCRmyPDF.
This may be more convenient than the command line tool for some Docker users.
Note that OCRmyPDF uses Ghostscript, which is licensed under AGPLv3+. While
OCRmyPDF is u... | 241 | 8,541 |
OCRmyPDF | misc/watcher.py | .py | #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2019 Ian Alexander <https://github.com/ianalexander>
# SPDX-FileCopyrightText: 2020 James R Barlow <https://github.com/jbarlow83>
# SPDX-License-Identifier: MIT
"""Watch a directory for new PDFs and OCR them."""
from __future__ import annotations
import datetime as dt... | 383 | 12,854 |
OCRmyPDF | misc/example_plugin.py | .py | # SPDX-FileCopyrightText: 2022 James R Barlow: https://github.com/jbarlow83
# SPDX-License-Identifier: MIT
"""An example of an OCRmyPDF plugin.
This plugin adds two new command line arguments
--grayscale-ocr: converts the image to grayscale before performing OCR on it
(This is occasionally useful for imag... | 69 | 1,732 |
OCRmyPDF | src/ocrmypdf/_jobcontext.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Defines context objects that are passed to child processes/threads."""
from __future__ import annotations
from collections.abc import Iterator
from pathlib import Path
from typing import TYPE_CHECKING
from ocrmypdf._options import ... | 123 | 4,247 |
OCRmyPDF | src/ocrmypdf/_stdoutprotect.py | .py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Protect the real standard output from corruption by stray writes.
When OCRmyPDF writes its final PDF to standard output (``ocrmypdf in.pdf -``),
the bytes on stdout must be exactly the PDF and nothing else. Any accidental
write to fi... | 84 | 3,171 |
OCRmyPDF | src/ocrmypdf/_watcher_security.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Security checks for the watched-folder helper (``misc/watcher.py``).
The watcher exposes three *data* directories -- input, output and archive --
that may be writable by less-privileged users, and it drives OCRmyPDF using
settings (i... | 268 | 11,061 |
OCRmyPDF | src/ocrmypdf/_options.py | .py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Internal options model for OCRmyPDF."""
from __future__ import annotations
import json
import logging
import os
import shlex
import unicodedata
from collections.abc import Sequence
from enum import StrEnum
from io import IOBase
from... | 687 | 25,256 |
OCRmyPDF | src/ocrmypdf/_progressbar.py | .py | # SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Defines progress bar API."""
from __future__ import annotations
from typing import Protocol
from rich.console import Console
from rich.progress import (
BarColumn,
MofNCompleteColumn,
Progress,
TaskProgressColumn,
... | 252 | 9,129 |
OCRmyPDF | src/ocrmypdf/optimize.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Post-processing image optimization of OCR PDFs."""
from __future__ import annotations
import logging
import sys
import tempfile
import threading
from collections.abc import Callable, Iterator, MutableSet, Sequence
from os import fsp... | 800 | 27,471 |
OCRmyPDF | src/ocrmypdf/pdfa.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Utilities for PDF/A production and confirmation with Ghostscript."""
from __future__ import annotations
import base64
import logging
from collections.abc import Iterator
from importlib.resources import files as package_files
from pa... | 327 | 11,805 |
OCRmyPDF | src/ocrmypdf/exceptions.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""OCRmyPDF's exceptions."""
from __future__ import annotations
from enum import IntEnum
from textwrap import dedent
class ExitCode(IntEnum):
"""OCRmyPDF's exit codes."""
# pylint: disable=invalid-name
ok = 0
bad_arg... | 213 | 6,870 |
OCRmyPDF | src/ocrmypdf/languages.py | .py | # SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Language codes and names from ISO 639.
Derived from
https://www.loc.gov/standards/iso639-2/ascii_8bits.html
"""
from __future__ import annotations
from typing import NamedTuple
class ISOCodeData(NamedTuple):
"""Data for a sin... | 854 | 34,396 |
OCRmyPDF | src/ocrmypdf/_version.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
__version__ = "17.10.0"
| 4 | 106 |
OCRmyPDF | src/ocrmypdf/__main__.py | .py | #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""ocrmypdf command line entrypoint."""
from __future__ import annotations
import logging
import multiprocessing
import os
import signal
import sys
from contextlib import suppress
from ocrmypdf import __version_... | 90 | 2,547 |
OCRmyPDF | src/ocrmypdf/__init__.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Adds OCR layer to PDFs."""
from __future__ import annotations
from pluggy import HookimplMarker as _HookimplMarker
from ocrmypdf import helpers, hocrtransform, pdfa, pdfinfo
from ocrmypdf._concurrent import Executor
from ocrmypdf._... | 88 | 1,999 |
OCRmyPDF | src/ocrmypdf/_defaults.py | .py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
# Enforce English hegemony
from __future__ import annotations
DEFAULT_LANGUAGE = 'eng'
# Default rotation threshold
DEFAULT_ROTATE_PAGES_THRESHOLD = 14.0
PROGRAM_NAME = 'OCRmyPDF'
| 13 | 266 |
OCRmyPDF | src/ocrmypdf/_pageboxes.py | .py | # SPDX-FileCopyrightText: 2026 James R. Barlow
# SPDX-FileCopyrightText: 2025 ajdlinux
# SPDX-License-Identifier: MPL-2.0
"""Validate and repair malformed page-boundary boxes.
A page's boundary boxes (``/MediaBox``, ``/CropBox``, ``/TrimBox``, ``/ArtBox``,
``/BleedBox``) are sometimes malformed in ways that PDF reade... | 254 | 9,125 |
OCRmyPDF | src/ocrmypdf/_validation_coordinator.py | .py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Validation coordinator for plugin options and cross-cutting concerns."""
from __future__ import annotations
import logging
import os
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ocrmypdf._options import OcrOptions
... | 148 | 5,750 |
OCRmyPDF | src/ocrmypdf/_graft.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""For grafting text-only PDF pages onto freeform PDF pages."""
from __future__ import annotations
import logging
from collections.abc import Collection
from contextlib import suppress
from dataclasses import dataclass
from enum import... | 726 | 27,520 |
OCRmyPDF | src/ocrmypdf/_logging.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Logging support classes."""
from __future__ import annotations
import logging
from rich.console import Console
from rich.logging import RichHandler
class PageNumberFilter(logging.Filter):
"""Insert PDF page number that emitte... | 31 | 808 |
OCRmyPDF | src/ocrmypdf/_validation.py | .py | #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Validate a work order from API or command line."""
from __future__ import annotations
import logging
import os
import sys
from collections.abc import Sequence
from collections.abc import Set as AbstractSet
fro... | 338 | 12,943 |
OCRmyPDF | src/ocrmypdf/_plugin_manager.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Plugin manager using pluggy with type-safe interface."""
from __future__ import annotations
import importlib
import importlib.util
import pkgutil
import sys
from argparse import ArgumentParser
from collections.abc import Sequence
fr... | 291 | 9,943 |
OCRmyPDF | src/ocrmypdf/_annots.py | .py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""OCRmyPDF PDF annotation cleanup."""
from __future__ import annotations
import logging
from pikepdf import Dictionary, Name, NameTree, Pdf
log = logging.getLogger(__name__)
def remove_broken_goto_annotations(pdf: Pdf) -> bool:
... | 67 | 2,141 |
OCRmyPDF | src/ocrmypdf/quality.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Utilities to measure OCR quality."""
from __future__ import annotations
import re
from collections.abc import Iterable
class OcrQualityDictionary:
"""Manages a dictionary for simple OCR quality checks."""
def __init__(sel... | 45 | 1,460 |
OCRmyPDF | src/ocrmypdf/_concurrent.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""OCRmyPDF concurrency abstractions."""
from __future__ import annotations
import threading
from abc import ABC, abstractmethod
from collections.abc import Callable, Iterable
from typing import Any, TypeVar, cast
from ocrmypdf._progr... | 133 | 4,551 |
OCRmyPDF | src/ocrmypdf/api.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Python API for OCRmyPDF.
This module provides the main Python API for OCRmyPDF, allowing you to perform
OCR operations programmatically without using the command line interface.
Main Functions:
ocr(): The primary function for OC... | 1,033 | 39,231 |
OCRmyPDF | src/ocrmypdf/cli.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Command line interface customization and validation."""
from __future__ import annotations
import argparse
from argparse import ArgumentParser
from collections.abc import Callable, Mapping
from typing import Any, TypeVar
from ocrmy... | 573 | 21,925 |
OCRmyPDF | src/ocrmypdf/helpers.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Support functions."""
from __future__ import annotations
import logging
import multiprocessing
import os
import shutil
import warnings
from collections.abc import Callable, Iterable, Sequence
from contextlib import suppress
from dec... | 379 | 12,537 |
OCRmyPDF | src/ocrmypdf/imageops.py | .py | # SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""OCR-related image manipulation."""
from __future__ import annotations
import logging
from math import floor, sqrt
from PIL import Image
log = logging.getLogger(__name__)
def bytes_per_pixel(mode: str) -> int:
"""Return the n... | 152 | 5,120 |
OCRmyPDF | src/ocrmypdf/_plugin_registry.py | .py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Plugin option registry for dynamic model composition."""
from __future__ import annotations
import logging
from pydantic import BaseModel
log = logging.getLogger(__name__)
class PluginOptionRegistry:
"""Registry for plugin o... | 51 | 1,579 |
OCRmyPDF | src/ocrmypdf/_metadata.py | .py | # SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""OCRmyPDF page processing pipeline functions."""
from __future__ import annotations
import datetime as dt
import logging
from pathlib import Path
from typing import Any
from pikepdf import Dictionary, Name, Pdf
from pikepdf import _... | 217 | 7,791 |
OCRmyPDF | src/ocrmypdf/pluginspec.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""OCRmyPDF pluggy plugin specification."""
from __future__ import annotations
from abc import ABC, abstractmethod
from argparse import ArgumentParser
from collections.abc import Sequence, Set
from enum import StrEnum
from logging impo... | 676 | 25,827 |
OCRmyPDF | src/ocrmypdf/_pipeline.py | .py | # SPDX-FileCopyrightText: 2018-2022 James R. Barlow
# SPDX-FileCopyrightText: 2019 Martin Wind
# SPDX-License-Identifier: MPL-2.0
"""OCRmyPDF page processing pipeline functions."""
from __future__ import annotations
import logging
import os
import re
import sys
from collections.abc import Iterable, Iterator, Sequenc... | 1,365 | 51,758 |
OCRmyPDF | src/ocrmypdf/extra_plugins/semfree.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Semaphore-free alternate executor.
There are two popular environments that do not fully support the standard Python
multiprocessing module: AWS Lambda, and Termux (a terminal emulator for Android).
This alternate executor divvies up ... | 215 | 7,047 |
OCRmyPDF | src/ocrmypdf/builtin_plugins/null_ocr.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Built-in plugin implementing a null OCR engine (no OCR).
This plugin provides an OCR engine that produces no text output. It is useful
when users want OCRmyPDF's image processing, PDF/A conversion, or optimization
features without pe... | 160 | 4,865 |
OCRmyPDF | src/ocrmypdf/builtin_plugins/optimize.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Built-in plugin to implement PDF page optimization."""
from __future__ import annotations
import argparse
import logging
from collections.abc import Sequence
from pathlib import Path
from typing import Annotated
from pydantic import... | 239 | 7,954 |
OCRmyPDF | src/ocrmypdf/builtin_plugins/ghostscript.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Built-in plugin to implement PDF page rasterization and PDF/A production."""
from __future__ import annotations
import logging
from enum import StrEnum
from pathlib import Path
from typing import Annotated
from packaging.version imp... | 462 | 17,400 |
OCRmyPDF | src/ocrmypdf/builtin_plugins/concurrency.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""OCRmyPDF's multiprocessing/multithreading abstraction layer."""
from __future__ import annotations
import logging
import logging.handlers
import multiprocessing
import multiprocessing.queues
import os
import queue
import signal
impor... | 219 | 7,726 |
OCRmyPDF | src/ocrmypdf/builtin_plugins/tesseract_ocr.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Built-in plugin to implement OCR using Tesseract."""
from __future__ import annotations
import argparse
import logging
import os
from typing import Annotated
from PIL import Image
from pydantic import BaseModel, Field, field_validat... | 482 | 18,009 |
OCRmyPDF | src/ocrmypdf/builtin_plugins/default_filters.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""OCRmyPDF automatically installs these filters as plugins."""
from __future__ import annotations
from ocrmypdf import hookimpl
@hookimpl
def filter_pdf_page(page, image_filename, output_pdf): # pylint: disable=unused-argument
r... | 13 | 337 |
OCRmyPDF | src/ocrmypdf/builtin_plugins/pypdfium.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Built-in plugin to implement PDF page rasterization using pypdfium2."""
from __future__ import annotations
import logging
import threading
from contextlib import closing
from pathlib import Path
from typing import TYPE_CHECKING, Lite... | 289 | 10,205 |
OCRmyPDF | src/ocrmypdf/_exec/jbig2enc.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Interface to jbig2 executable."""
from __future__ import annotations
from subprocess import PIPE, CalledProcessError
from packaging.version import Version
from ocrmypdf._exec._probe import ToolProbe
from ocrmypdf.exceptions import... | 42 | 1,111 |
OCRmyPDF | src/ocrmypdf/_exec/ghostscript.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Interface to Ghostscript executable."""
from __future__ import annotations
import logging
import os
import re
from collections import deque
from os import fspath
from pathlib import Path
from subprocess import PIPE, CalledProcessErr... | 454 | 17,280 |
OCRmyPDF | src/ocrmypdf/_exec/tesseract.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Interface to Tesseract executable."""
from __future__ import annotations
import logging
import os
import re
from contextlib import suppress
from enum import IntEnum
from math import pi
from os import fspath
from pathlib import Path
... | 508 | 16,190 |
OCRmyPDF | src/ocrmypdf/_exec/unpaper.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Interface to unpaper executable."""
from __future__ import annotations
import logging
import os
from collections.abc import Iterator
from contextlib import contextmanager
from decimal import Decimal
from pathlib import Path
from sub... | 130 | 4,277 |
OCRmyPDF | src/ocrmypdf/_exec/verapdf.py | .py | # SPDX-FileCopyrightText: 2024 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Interface to verapdf executable."""
from __future__ import annotations
import json
import logging
from pathlib import Path
from subprocess import PIPE
from typing import NamedTuple
from ocrmypdf._exec._probe import ToolProbe
from o... | 103 | 2,819 |
OCRmyPDF | src/ocrmypdf/_exec/_probe.py | .py | # SPDX-FileCopyrightText: 2026 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Probe helper for external executables.
Each ``ocrmypdf._exec.<tool>`` module describes its external program with a
module-level :class:`ToolProbe` and delegates ``version()`` / ``available()``
to it. This separates the "is the tool in... | 73 | 2,634 |
OCRmyPDF | src/ocrmypdf/_exec/pngquant.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Interface to pngquant executable."""
from __future__ import annotations
from pathlib import Path
from subprocess import PIPE
from ocrmypdf._exec._probe import ToolProbe
from ocrmypdf.subprocess import run
PROBE = ToolProbe(program... | 43 | 1,309 |
OCRmyPDF | src/ocrmypdf/pdfinfo/layout.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Detailed text position and layout analysis, building on pdfminer.six."""
from __future__ import annotations
import re
import sys
from collections.abc import Iterator, Mapping
from contextlib import contextmanager
from math import cop... | 396 | 12,479 |
OCRmyPDF | src/ocrmypdf/pdfinfo/_worker.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""PDF page info worker process handling."""
from __future__ import annotations
import atexit
import logging
from collections.abc import Container
from contextlib import contextmanager
from functools import partial
from pathlib import P... | 144 | 4,270 |
OCRmyPDF | src/ocrmypdf/pdfinfo/info.py | .py | #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Extract information about the content of a PDF."""
from __future__ import annotations
import logging
import statistics
from collections.abc import Callable, Container, Iterable, Iterator
from contextlib import... | 561 | 19,041 |
OCRmyPDF | src/ocrmypdf/pdfinfo/_image.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""PDF image analysis."""
from __future__ import annotations
import logging
from collections.abc import Iterator
from decimal import Decimal
from typing import cast
from pikepdf import (
Dictionary,
Matrix,
Name,
Object... | 432 | 15,129 |
OCRmyPDF | src/ocrmypdf/pdfinfo/_contentstream.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""PDF content stream interpretation."""
from __future__ import annotations
import re
from collections import defaultdict
from collections.abc import Mapping
from math import hypot, inf, isclose
from typing import NamedTuple
from warnin... | 328 | 12,692 |
OCRmyPDF | src/ocrmypdf/pdfinfo/_types.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""PDF type definitions and constants."""
from __future__ import annotations
from enum import Enum, auto
class Colorspace(Enum):
"""Description of common image colorspaces in a PDF."""
# pylint: disable=invalid-name
gray ... | 99 | 2,597 |
OCRmyPDF | src/ocrmypdf/fpdf_renderer/renderer.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""fpdf2-based PDF renderer for OCR text layers.
This module provides PDF rendering using fpdf2 for creating searchable
OCR text layers.
"""
from __future__ import annotations
import logging
import unicodedata
from dataclasses import ... | 972 | 36,749 |
OCRmyPDF | src/ocrmypdf/fpdf_renderer/__init__.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""fpdf2-based PDF renderer for OCR text layers.
This module provides the PDF renderer using fpdf2 for creating
searchable OCR text layers.
"""
from __future__ import annotations
from ocrmypdf.fpdf_renderer.renderer import (
Debug... | 23 | 482 |
OCRmyPDF | src/ocrmypdf/subprocess/_windows.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Find Tesseract and Ghostscript binaries on Windows using the registry."""
from __future__ import annotations
import logging
import os
import re
import shutil
import sys
from collections.abc import Callable, Iterable, Iterator
from it... | 210 | 6,227 |
OCRmyPDF | src/ocrmypdf/subprocess/_version.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Extract version strings from external programs."""
from __future__ import annotations
import logging
import re
from subprocess import PIPE, STDOUT, CalledProcessError
from ocrmypdf.exceptions import MissingDependencyError
from ocrmy... | 80 | 2,522 |
OCRmyPDF | src/ocrmypdf/subprocess/__init__.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Wrappers to manage subprocess calls.
This package is split into three private submodules by concern:
- :mod:`ocrmypdf.subprocess._run` - low-level execution wrappers (``run``,
``run_polling_stderr``) that add OCRmyPDF-aware logging... | 32 | 1,097 |
OCRmyPDF | src/ocrmypdf/subprocess/_run.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Low-level wrappers around :py:mod:`subprocess`.
These functions exist to give OCRmyPDF child processes uniform logging
behavior and to route through any platform-specific PATH fix-ups before
invocation. They are intended as drop-in re... | 138 | 5,066 |
OCRmyPDF | src/ocrmypdf/subprocess/_check.py | .py | # SPDX-FileCopyrightText: 2022 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Validate that required external programs are installed and new enough."""
from __future__ import annotations
import logging
import sys
from collections.abc import Callable, Mapping
from subprocess import CalledProcessError
from pack... | 175 | 5,680 |
OCRmyPDF | src/ocrmypdf/font/__init__.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Font management for OCRmyPDF PDF rendering.
This module provides font infrastructure for the fpdf2 PDF renderer. It includes:
- FontManager: Base class for font loading and glyph checking
- FontProvider: Protocol and implementations... | 35 | 1,012 |
OCRmyPDF | src/ocrmypdf/font/system_font_provider.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""System font discovery for PDF rendering.
Provides lazy discovery of Noto fonts installed on the system across
Linux, macOS, and Windows platforms.
"""
from __future__ import annotations
import glob
import logging
import os
import s... | 564 | 21,343 |
OCRmyPDF | src/ocrmypdf/font/font_manager.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Base font management for PDF rendering.
This module provides the base FontManager class that handles font loading
and glyph checking using uharfbuzz.
"""
from __future__ import annotations
from pathlib import Path
import uharfbuzz... | 116 | 3,837 |
OCRmyPDF | src/ocrmypdf/font/multi_font_manager.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Multi-font management for PDF rendering.
Provides automatic font selection for multilingual documents based on
language hints and glyph coverage analysis.
"""
from __future__ import annotations
import logging
import unicodedata
fro... | 464 | 18,318 |
OCRmyPDF | src/ocrmypdf/font/font_provider.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""Font provider protocol and implementations for PDF rendering."""
from __future__ import annotations
import logging
from pathlib import Path
from typing import Protocol, runtime_checkable
from ocrmypdf.font.font_manager import FontM... | 249 | 8,456 |
OCRmyPDF | src/ocrmypdf/hocrtransform/__main__.py | .py | # SPDX-FileCopyrightText: 2023-2025 James R. Barlow
# SPDX-License-Identifier: MIT
"""Simple CLI for testing HOCR to PDF conversion using fpdf2 renderer."""
from __future__ import annotations
import argparse
from pathlib import Path
from ocrmypdf.font import MultiFontManager
from ocrmypdf.fpdf_renderer import Debug... | 72 | 2,223 |
OCRmyPDF | src/ocrmypdf/hocrtransform/__init__.py | .py | # SPDX-FileCopyrightText: 2023-2025 James R. Barlow
# SPDX-License-Identifier: MIT
"""Transform OCR output to text-only PDFs.
This package provides tools for:
1. Parsing OCR output (hOCR format) into generic OcrElement structures
2. Rendering OcrElement structures to searchable PDF text layers
The architecture separ... | 49 | 1,306 |
OCRmyPDF | src/ocrmypdf/hocrtransform/hocr_parser.py | .py | # SPDX-FileCopyrightText: 2010 Jonathan Brinley
# SPDX-FileCopyrightText: 2013-2014 Julien Pfefferkorn
# SPDX-FileCopyrightText: 2023-2025 James R. Barlow
# SPDX-License-Identifier: MIT
"""Parser for hOCR format files.
This module provides functionality to parse hOCR files (HTML-based OCR format)
and convert them to ... | 522 | 14,598 |
OCRmyPDF | src/ocrmypdf/models/ocr_element.py | .py | # SPDX-FileCopyrightText: 2025 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
"""OCR element dataclasses for representing OCR output structure.
This module provides a generic, engine-agnostic representation of OCR output.
The OcrElement dataclass can represent structural units from any OCR source
(hOCR, ALTO, cus... | 268 | 8,319 |
OCRmyPDF | src/ocrmypdf/_pipelines/ocr.py | .py | # SPDX-FileCopyrightText: 2019-2023 James R. Barlow
# SPDX-FileCopyrightText: 2019 Martin Wind
# SPDX-License-Identifier: MPL-2.0
"""Implements the concurrent and page synchronous parts of the pipeline."""
from __future__ import annotations
import logging
import logging.handlers
from collections.abc import Sequence
... | 227 | 7,423 |
OCRmyPDF | src/ocrmypdf/_pipelines/_common.py | .py | # SPDX-FileCopyrightText: 2023 James R. Barlow
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import json
import logging
import logging.handlers
import os
import shutil
import sys
import threading
from collections.abc import Callable, Sequence
from concurrent.futures.process import BrokenProces... | 555 | 19,206 |
OCRmyPDF | src/ocrmypdf/_pipelines/hocr_to_ocr_pdf.py | .py | # SPDX-FileCopyrightText: 2019-2023 James R. Barlow
# SPDX-FileCopyrightText: 2019 Martin Wind
# SPDX-License-Identifier: MPL-2.0
"""Implements the concurrent and page synchronous parts of the pipeline."""
from __future__ import annotations
import logging
import logging.handlers
from collections.abc import Sequence
... | 128 | 4,421 |
OCRmyPDF | src/ocrmypdf/_pipelines/pdf_to_hocr.py | .py | # SPDX-FileCopyrightText: 2019-2023 James R. Barlow
# SPDX-FileCopyrightText: 2019 Martin Wind
# SPDX-License-Identifier: MPL-2.0
"""Implements the concurrent and page synchronous parts of the pipeline."""
from __future__ import annotations
import logging
import logging.handlers
import os
import shutil
from functool... | 111 | 3,632 |
kitty | publish.py | .py | #!/usr/bin/env python
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
import argparse
import base64
import contextlib
import datetime
import glob
import io
import json
import mimetypes
import os
import pprint
import re
import shlex
import shutil
import subprocess
import sys
import tempfile
imp... | 611 | 23,215 |
kitty | benchmark.py | .py | #!./kitty/launcher/kitty +launch
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
import argparse
import fcntl
import os
import select
import signal
import struct
import sys
import termios
import time
from pty import CHILD, fork
from kitty.constants import kitten_exe
from kitty.fast_data_types... | 116 | 3,684 |
kitty | setup.py | .py | #!/usr/bin/env python
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
import argparse
import glob
import json
import os
import platform
import re
import runpy
import shlex
import shutil
import struct
import subprocess
import sys
import sysconfig
import tempfile
import textwrap
import time
from... | 2,532 | 99,459 |
kitty | __main__.py | .py | #!/usr/bin/env python
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
if __name__ == '__main__':
from kitty.entry_points import main
main()
| 9 | 176 |
kitty | test.py | .py | #!./kitty/launcher/kitty +launch
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
import importlib
def main() -> None:
m = importlib.import_module('kitty_tests.main')
getattr(m, 'main')()
if __name__ == '__main__':
main()
| 14 | 263 |
kitty | bypy/init_env.py | .py | #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
import os
import re
import shlex
import shutil
import subprocess
import sys
import tempfile
from contextlib import suppress
from bypy.constants import BIN, LIBDIR, PREFIX, PYTHON, ismacos, worker_env... | 122 | 4,675 |
kitty | bypy/site.py | .py | #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
import _sitebuiltins
import builtins
import sys
def set_quit() -> None:
eof = 'Ctrl-D (i.e. EOF)'
builtins.quit = _sitebuiltins.Quitter('quit', eof)
builtins.exit = _sitebuiltins.Quitter... | 31 | 658 |
kitty | bypy/macos/__main__.py | .py | #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
import glob
import json
import os
import shutil
import stat
import subprocess
import sys
import tempfile
import zipfile
from collections.abc import Iterable
from bypy.constants import BIN, LIBDIR, PR... | 546 | 20,032 |
kitty | bypy/linux/__main__.py | .py | #!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
import errno
import os
import shutil
import stat
import subprocess
import tarfile
import time
from bypy.constants import BIN, LIBDIR, OUTPUT_DIR, PREFIX, python_major_minor_version
from bypy.freeze i... | 276 | 9,484 |
kitty | gen/go_code.py | .py | #!./kitty/launcher/kitty +launch
# License: GPLv3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
import argparse
import bz2
import io
import json
import os
import re
import shlex
import struct
import subprocess
import sys
import tarfile
from collections.abc import Iterator, Sequence
from contextlib import cont... | 1,035 | 37,110 |
kitty | gen/cursors.py | .py | #!/usr/bin/env python
# License: GPLv3 Copyright: 2023, Kovid Goyal <kovid at kovidgoyal.net>
import os
import subprocess
import sys
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
... | 168 | 9,335 |
kitty | gen/key_constants.py | .py | #!/usr/bin/env python
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
import os
import string
import subprocess
import sys
from pprint import pformat
from typing import Any, Union
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
sys.path.... | 505 | 20,131 |
kitty | gen/__main__.py | .py | #!/usr/bin/env python
# License: GPLv3 Copyright: 2023, Kovid Goyal <kovid at kovidgoyal.net>
import os
import sys
def main(args: list[str] = sys.argv) -> None:
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, os.getcwd())
if len(args) == 1:
raise SystemEx... | 54 | 1,202 |
kitty | gen/apc_parsers.py | .py | #!/usr/bin/env python
# License: GPLv3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
import os
import subprocess
import sys
from collections import defaultdict
from typing import Any, DefaultDict, Union
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
s... | 369 | 12,855 |
kitty | gen/color_names.py | .py | #!./kitty/launcher/kitty +launch
# License: GPLv3 Copyright: 2025, Kovid Goyal <kovid at kovidgoyal.net>
import os
import subprocess
import sys
import tempfile
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
sys.path.insert(0, os.path.dirname(os.path.dirname(os... | 803 | 29,907 |
kitty | gen/srgb_lut.py | .py | #!/usr/bin/env python
import os
import sys
from functools import lru_cache
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def to_linear(a: float) -> float:
if a <= 0.04045:
... | 60 | 1,425 |
kitty | gen/bitfields.py | .py | #!/usr/bin/env python
# License: GPLv3 Copyright: 2025, Kovid Goyal <kovid at kovidgoyal.net>
import os
from typing import NamedTuple
class BitField(NamedTuple):
name: str
bits: int
def typename_for_bitsize(bits: int) -> str:
if bits <= 8:
return 'uint8'
if bits <= 16:
return 'uint1... | 65 | 1,924 |
kitty | gen/config.py | .py | #!./kitty/launcher/kitty +launch
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
import os
import re
import subprocess
import sys
import types
from kitty.conf.generate import write_output
if __name__ == '__main__' and not __package__:
import __main__
__main__.__package__ = 'gen'
... | 83 | 2,872 |
kitty | gen/wcwidth.py | .py | #!/usr/bin/env python
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
# Imports {{{
import json
import os
import re
import subprocess
import sys
from collections import defaultdict
from collections.abc import Generator, Hashable, Iterable
from contextlib import contextmanager
from functools im... | 1,248 | 46,263 |
kitty | kittens/runner.py | .py | #!/usr/bin/env python
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
import importlib
import os
import sys
from collections.abc import Callable, Generator
from contextlib import contextmanager
from functools import partial
from typing import TYPE_CHECKING, Any, NamedTuple, cast
from kitty.c... | 239 | 7,374 |
kitty | kittens/choose_files/main.py | .py | #!/usr/bin/env python
# License: GPLv3 Copyright: 2025, Kovid Goyal <kovid at kovidgoyal.net>
import shlex
import sys
from typing import Any
from kitty.conf.types import Definition
from kitty.constants import appname
from kitty.simple_cli_definitions import CONFIG_HELP, CompletionSpec
from kitty.typing_compat import ... | 372 | 12,534 |
kitty | kittens/choose_files/__init__.py | .py | def syntax_aliases(x: str) -> dict[str, str]:
ans = {}
for x in x.split():
k, _, v = x.partition(':')
ans[k] = v
return ans
| 7 | 152 |
kitty | kittens/diff/main.py | .py | #!/usr/bin/env python
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
import sys
from functools import partial
from kitty.conf.types import Definition
from kitty.constants import appname
from kitty.simple_cli_definitions import CONFIG_HELP, CompletionSpec
def main(args: list[str]) -> None:
... | 443 | 12,550 |
kitty | kittens/query_terminal/main.py | .py | #!/usr/bin/env python
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
import re
import sys
from binascii import hexlify, unhexlify
from contextlib import suppress
from typing import get_args
from kitty.conf.utils import OSNames, os_name
from kitty.constants import appname, str_version
from kit... | 304 | 8,922 |
kitty | kittens/themes/main.py | .py | #!/usr/bin/env python
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
import sys
from kitty.conf.types import Definition
from kitty.simple_cli_definitions import CompletionSpec
definition = Definition(
'!kittens.themes',
)
agr = definition.add_group
egr = definition.end_group
map = defin... | 126 | 3,522 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.