mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-21 13:02:40 +00:00
Chore: import dateparser and zxingcpp lazily in zone OCR
This commit is contained in:
1 parent
0348dc532f
commit
ad64f2a1b1
2 files changed
+5
-3
No files matched your search
@@ -2090,7 +2090,7 @@ class TestApplyTransform:
|
|||||||
THEN:
|
THEN:
|
||||||
- An empty string is returned
|
- An empty string is returned
|
||||||
"""
|
"""
|
||||||
mocker.patch("documents.zone_ocr.dateparser.parse", side_effect=OverflowError)
|
mocker.patch("dateparser.parse", side_effect=OverflowError)
|
||||||
assert (
|
assert (
|
||||||
_apply_transform(
|
_apply_transform(
|
||||||
"unparsable",
|
"unparsable",
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ from typing import NewType
|
|||||||
from typing import TypeAlias
|
from typing import TypeAlias
|
||||||
from typing import assert_never
|
from typing import assert_never
|
||||||
|
|
||||||
import dateparser
|
|
||||||
import zxingcpp
|
|
||||||
from babel import Locale
|
from babel import Locale
|
||||||
from babel import UnknownLocaleError
|
from babel import UnknownLocaleError
|
||||||
from babel.numbers import NumberFormatError
|
from babel.numbers import NumberFormatError
|
||||||
@@ -766,6 +764,8 @@ def _crop_zone(
|
|||||||
|
|
||||||
def _read_barcode(cropped: Image.Image, zone_name: str) -> str | None:
|
def _read_barcode(cropped: Image.Image, zone_name: str) -> str | None:
|
||||||
"""Read QR/barcode from a cropped image using zxingcpp."""
|
"""Read QR/barcode from a cropped image using zxingcpp."""
|
||||||
|
import zxingcpp
|
||||||
|
|
||||||
try:
|
try:
|
||||||
results = zxingcpp.read_barcodes(cropped)
|
results = zxingcpp.read_barcodes(cropped)
|
||||||
return results[0].text if results else None
|
return results[0].text if results else None
|
||||||
@@ -886,6 +886,8 @@ def _date_rules(ocr_language: str, date_format: str = "") -> DateRules:
|
|||||||
|
|
||||||
def _dateparser_date(text: str, rules: DateRules) -> date | None:
|
def _dateparser_date(text: str, rules: DateRules) -> date | None:
|
||||||
"""Read a whole-text absolute date with dateparser in the zone's language."""
|
"""Read a whole-text absolute date with dateparser in the zone's language."""
|
||||||
|
import dateparser
|
||||||
|
|
||||||
# Only absolute dates: dateparser would also read "now" or "yesterday"
|
# Only absolute dates: dateparser would also read "now" or "yesterday"
|
||||||
date_settings: dict[str, Any] = {
|
date_settings: dict[str, Any] = {
|
||||||
"PARSERS": ["custom-formats", "absolute-time"],
|
"PARSERS": ["custom-formats", "absolute-time"],
|
||||||
|
|||||||
Reference in new issue
Block a user