Skip to content

Commit 4b935a3

Browse files
authored
Merge branch 'main' into speed_improvements
2 parents 1ed209e + 4feec6e commit 4b935a3

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

ocr_service/app/app.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import subprocess
55
import time
66
from threading import Event, Thread
7-
from typing import Any
7+
from typing import Any, cast
88

99
import psutil
1010
from fastapi import FastAPI
@@ -30,19 +30,23 @@ def start_office_server(port_num: str) -> dict[str, Any]:
3030
uno_port = str(int(port_num) + 1000) # e.g. XML-RPC 9900, UNO 10900
3131
user_installation = f"{settings.TMP_FILE_DIR}/lo_profile_{port_num}"
3232

33+
lo_python = cast(str, settings.LIBRE_OFFICE_PYTHON_PATH)
34+
lo_exec = cast(str, settings.LIBRE_OFFICE_EXEC_PATH)
35+
3336
loffice_process: dict[str, Any] = {
3437
"process": subprocess.Popen(
3538
args=[
36-
settings.LIBRE_OFFICE_PYTHON_PATH,
39+
lo_python,
3740
"-m",
3841
"unoserver.server",
3942
"--interface", settings.LIBRE_OFFICE_NETWORK_INTERFACE,
4043
"--uno-interface", settings.LIBRE_OFFICE_NETWORK_INTERFACE,
41-
"--executable", settings.LIBRE_OFFICE_EXEC_PATH,
44+
"--executable", lo_exec,
4245
"--port", port_num,
4346
"--uno-port", uno_port,
44-
"--user-installation", user_installation
45-
],
47+
"--user-installation", user_installation,
48+
# "--logfile", f"loffice_{port_num}.log"
49+
], # type: ignore
4650
cwd=settings.TMP_FILE_DIR,
4751
close_fds=True,
4852
shell=False

ocr_service/processor/converter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from io import BytesIO
1010
from subprocess import PIPE, Popen
1111
from threading import Timer
12-
from typing import Any
12+
from typing import Any, cast
1313

1414
import pypdfium2 as pdfium
1515
from bs4 import BeautifulSoup
@@ -181,9 +181,10 @@ def _preprocess_doc(self, stream: bytes, file_name: str) -> bytes:
181181
for port_num, loffice_process in self.loffice_process_list.items():
182182
if loffice_process["used"] is False:
183183
used_port_num = str(port_num)
184+
lo_python = cast(str, settings.LIBRE_OFFICE_PYTHON_PATH)
184185
converter_bootstrap = "from unoserver.client import converter_main; converter_main()"
185186
_args = [
186-
settings.LIBRE_OFFICE_PYTHON_PATH,
187+
lo_python,
187188
"-c",
188189
converter_bootstrap,
189190
doc_file_path,

ocr_service/settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# mypy: disable-error-code=prop-decorator
2+
13
import ast
24
import logging
35
import multiprocessing
@@ -210,4 +212,4 @@ def LIBRE_OFFICE_LISTENER_PORT_RANGE(self) -> range:
210212
return range(start, end)
211213
return range(self.DEFAULT_LIBRE_OFFICE_SERVER_PORT, self.LIBRE_OFFICE_PORT_CAP)
212214

213-
settings = Settings() # type: ignore[call-arg]
215+
settings = Settings() # pyright: ignore[reportCallIssue]

0 commit comments

Comments
 (0)