Skip to content

Commit ddfe4dd

Browse files
Use absolute import to work around circular builder/tesseract import issues.
Unfortunately builders.py now imports psm_parameter from tesseract.py, and tesseract.py imports DigitBuilder from builders.py. We could move psm_parameter into util.py, but it needs get_version as well and it is very much tesseract specific. I do not see a great solution for this and keeping the circular import seems the least bad solution. We keep it from breaking the program by using an explicit import of the module [0]. [0] https://stackoverflow.com/a/37126790
1 parent f5ee17a commit ddfe4dd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/pyocr/builders.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import xml.dom.minidom
1515
import logging
1616

17-
from .tesseract import psm_parameter
17+
import pyocr.tesseract
1818
from .util import to_unicode
1919

2020
logger = logging.getLogger(__name__)
@@ -306,7 +306,7 @@ class TextBuilder(BaseBuilder):
306306
def __init__(self, tesseract_layout=3, cuneiform_dotmatrix=False,
307307
cuneiform_fax=False, cuneiform_singlecolumn=False):
308308
file_ext = ["txt"]
309-
tess_flags = [psm_parameter(), str(tesseract_layout)]
309+
tess_flags = [pyocr.tesseract.psm_parameter(), str(tesseract_layout)]
310310
cun_args = ["-f", "text"]
311311
# Add custom cuneiform parameters if needed
312312
for par, arg in [(cuneiform_dotmatrix, "--dotmatrix"),
@@ -563,7 +563,7 @@ class WordBoxBuilder(BaseBuilder):
563563

564564
def __init__(self, tesseract_layout=1):
565565
file_ext = ["html", "hocr"]
566-
tess_flags = [psm_parameter(), str(tesseract_layout)]
566+
tess_flags = [pyocr.tesseract.psm_parameter(), str(tesseract_layout)]
567567
tess_conf = ["hocr"]
568568
cun_args = ["-f", "hocr"]
569569
super(WordBoxBuilder, self).__init__(file_ext, tess_flags, tess_conf,
@@ -639,7 +639,7 @@ class LineBoxBuilder(BaseBuilder):
639639

640640
def __init__(self, tesseract_layout=1):
641641
file_ext = ["html", "hocr"]
642-
tess_flags = [psm_parameter(), str(tesseract_layout)]
642+
tess_flags = [pyocr.tesseract.psm_parameter(), str(tesseract_layout)]
643643
tess_conf = ["hocr"]
644644
cun_args = ["-f", "hocr"]
645645
super(LineBoxBuilder, self).__init__(file_ext, tess_flags, tess_conf,

0 commit comments

Comments
 (0)