Remove tqdm dependency and TqdmConsole

Might be too aggressive? No deprecation warning....
This commit is contained in:
James R. Barlow 2023-09-17 00:58:27 -07:00
parent ec1c377532
commit de2bb5ce8c
No known key found for this signature in database
GPG Key ID: E54A300D567E1260
4 changed files with 1 additions and 63 deletions

View File

@ -21,7 +21,6 @@ dependencies = [
"pluggy>=0.13.0",
"reportlab>=3.5.66",
"rich>=13",
"tqdm>=4",
"typing-extensions>=4;python_version<'3.10'",
]
authors = [{ name = "James R. Barlow", email = "james@purplerock.ca" }]

View File

@ -6,7 +6,6 @@
from __future__ import annotations
import logging
from contextlib import suppress
from rich.console import Console
from rich.logging import RichHandler
@ -19,7 +18,6 @@ from rich.progress import (
TimeRemainingColumn,
)
from rich.table import Column
from tqdm import tqdm
class PageNumberFilter(logging.Filter):
@ -34,26 +32,6 @@ class PageNumberFilter(logging.Filter):
return True
class TqdmConsole:
"""Wrapper to log messages in a way that is compatible with tqdm progress bar.
This routes log messages through tqdm so that it can print them above the
progress bar, and then refresh the progress bar, rather than overwriting
it which looks messy.
"""
def __init__(self, file):
self.file = file
def write(self, msg):
# When no progress bar is active, tqdm.write() routes to print()
tqdm.write(msg.rstrip(), end='\n', file=self.file)
def flush(self):
with suppress(AttributeError):
self.file.flush()
class RichLoggingHandler(RichHandler):
def __init__(self, console: Console, **kwargs):
super().__init__(

View File

@ -15,7 +15,7 @@ from pathlib import Path
from typing import AnyStr, BinaryIO, Iterable, Union
from warnings import warn
from ocrmypdf._logging import PageNumberFilter, TqdmConsole
from ocrmypdf._logging import PageNumberFilter, RichTqdmProgressAdapter
from ocrmypdf._plugin_manager import get_plugin_manager
from ocrmypdf._sync import run_pipeline
from ocrmypdf._validation import check_options
@ -339,7 +339,6 @@ def ocr( # noqa: ruff: disable=D417
__all__ = [
'PageNumberFilter',
'TqdmConsole',
'Verbosity',
'check_options',
'configure_logging',

View File

@ -7,48 +7,10 @@ import logging
from io import BytesIO, StringIO
import pytest
from tqdm import tqdm
import ocrmypdf
def test_raw_console():
bio = StringIO()
tqconsole = ocrmypdf.api.TqdmConsole(file=bio)
tqconsole.write("Test")
tqconsole.flush()
assert "Test" in bio.getvalue()
def test_tqdm_console():
log = logging.getLogger()
log.setLevel(logging.INFO)
formatter = logging.Formatter('%(message)s')
bio = StringIO()
console = logging.StreamHandler(ocrmypdf.api.TqdmConsole(file=bio))
console.setFormatter(formatter)
log.addHandler(console)
def before_pbar(message):
# Ensure that log messages appear before the progress bar, even when
# printed after the progress bar updates.
v = bio.getvalue()
pbar_start_marker = '|#'
return v.index(message) < v.index(pbar_start_marker)
with tqdm(total=2, file=bio, disable=False) as pbar:
pbar.update()
msg = "1/2 above progress bar"
log.info(msg)
assert before_pbar(msg)
log.info("done")
assert not before_pbar("done")
def test_language_list():
with pytest.raises(
(ocrmypdf.exceptions.InputFileError, ocrmypdf.exceptions.MissingDependencyError)