Skip to content

Commit

Permalink
Use absolute import to work around circular builder/tesseract import …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
ddddavidmartin committed Jun 11, 2018
1 parent f5ee17a commit ddfe4dd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/pyocr/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import xml.dom.minidom
import logging

from .tesseract import psm_parameter
import pyocr.tesseract
from .util import to_unicode

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

def __init__(self, tesseract_layout=1):
file_ext = ["html", "hocr"]
tess_flags = [psm_parameter(), str(tesseract_layout)]
tess_flags = [pyocr.tesseract.psm_parameter(), str(tesseract_layout)]
tess_conf = ["hocr"]
cun_args = ["-f", "hocr"]
super(WordBoxBuilder, self).__init__(file_ext, tess_flags, tess_conf,
Expand Down Expand Up @@ -639,7 +639,7 @@ class LineBoxBuilder(BaseBuilder):

def __init__(self, tesseract_layout=1):
file_ext = ["html", "hocr"]
tess_flags = [psm_parameter(), str(tesseract_layout)]
tess_flags = [pyocr.tesseract.psm_parameter(), str(tesseract_layout)]
tess_conf = ["hocr"]
cun_args = ["-f", "hocr"]
super(LineBoxBuilder, self).__init__(file_ext, tess_flags, tess_conf,
Expand Down

0 comments on commit ddfe4dd

Please sign in to comment.