Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix(mineru): include CLI worker dependencies and update parser test seam

Bingxi Zhao (Frank)8e67802b11d9
diff --git a/packaging/deeptutor-cli/pyproject.toml b/packaging/deeptutor-cli/pyproject.toml
index d710746a8..518b4421b 100644
--- a/packaging/deeptutor-cli/pyproject.toml
+++ b/packaging/deeptutor-cli/pyproject.toml
@@ -12,6 +12,8 @@ requires-python = ">=3.11,<3.15"
readme = "README.md"
license = {text = "Apache-2.0"}
dependencies = [
+ "psutil>=5.9.0,<8.0.0",
+ "pywin32; sys_platform == 'win32'", # MinerU Job Object ownership
"PyYAML>=6.0",
"jinja2>=3.1.0",
"openai>=1.30.0",
diff --git a/pyproject.toml b/pyproject.toml
index 40c3aa510..2ab4f1834 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -92,9 +92,7 @@ dependencies = [
"loguru>=0.7.3,<1.0.0",
"json-repair>=0.57.0,<1.0.0",
"croniter>=6.0.0,<7.0.0",
- # Process-tree memory readings for /api/system/memory. Soft dependency:
- # deeptutor.runtime.memory_probe imports it lazily and falls back to /proc,
- # so a missing wheel costs the settings strip, not the app.
+ # Process-tree memory readings and Windows MinerU worker ownership.
"psutil>=5.9.0,<8.0.0",
"pywin32; sys_platform == 'win32'", # MinerU Job Object ownership
]
@@ -115,6 +113,8 @@ translation = "deeptutor.reading.translation:TranslationExtension"
# already included in the public `deeptutor` wheel; the local CLI-only project
# under `packaging/deeptutor-cli` uses the same list without Web assets/server deps.
cli = [
+ "psutil>=5.9.0,<8.0.0",
+ "pywin32; sys_platform == 'win32'", # MinerU Job Object ownership
"packaging>=24.2",
# LLM provider SDKs
"anthropic>=0.30.0",
diff --git a/tests/test_packaging_metadata.py b/tests/test_packaging_metadata.py
index 8ccb820b4..a6a638858 100644
--- a/tests/test_packaging_metadata.py
+++ b/tests/test_packaging_metadata.py
@@ -229,3 +229,27 @@ def test_timezone_database_is_installed_on_every_install_surface() -> None:
assert root["dependencies"].count(expected) == 1
assert cli_package["dependencies"].count(expected) == 1
assert _cli_requirement_lines().count(expected) == 1
+
+
+def test_windows_mineru_worker_dependencies_match_every_install_surface() -> None:
+ from packaging.requirements import Requirement
+
+ root = _project(REPOSITORY_ROOT / "pyproject.toml")
+ cli_package = _project(REPOSITORY_ROOT / "packaging" / "deeptutor-cli" / "pyproject.toml")
+ for dependencies in (
+ root["dependencies"],
+ root["optional-dependencies"]["cli"],
+ cli_package["dependencies"],
+ _cli_requirement_lines(),
+ ):
+ requirements = {
+ requirement.name: requirement
+ for line in dependencies
+ if not line.startswith("-")
+ for requirement in [Requirement(line)]
+ }
+ assert "psutil" in requirements
+ win32 = requirements["pywin32"]
+ assert win32.marker.evaluate({"sys_platform": "win32"})
+ assert not win32.marker.evaluate({"sys_platform": "linux"})
+ assert not win32.marker.evaluate({"sys_platform": "darwin"})
diff --git a/tests/tools/test_mineru.py b/tests/tools/test_mineru.py
index d6cf03d54..025114487 100644
--- a/tests/tools/test_mineru.py
+++ b/tests/tools/test_mineru.py
@@ -1,8 +1,10 @@
from __future__ import annotations
+from contextlib import contextmanager
import io
import json
from pathlib import Path
+from types import SimpleNamespace
import zipfile
import httpx as real_httpx
@@ -258,19 +260,16 @@ def test_pdf_parser_streams_output_lines(tmp_path: Path, monkeypatch: pytest.Mon
pdf.write_bytes(b"%PDF-1.4")
out = tmp_path / "out"
- class FakeProcess:
- def __init__(self, cmd, **kwargs): # noqa: ANN002, ANN003
- # Simulate the CLI writing its artifacts under the -o directory.
- target = Path(cmd[cmd.index("-o") + 1]) / "exam"
- (target / "auto").mkdir(parents=True, exist_ok=True)
- (target / "auto" / "exam.md").write_text("# parsed", encoding="utf-8")
- self.stdout = iter(["downloading model...\n", "\n", "parsing page 1/3\n"])
-
- def wait(self):
- return 0
+ @contextmanager
+ def fake_cli_process(cmd, log_path, env):
+ target = Path(cmd[cmd.index("-o") + 1]) / "exam"
+ (target / "auto").mkdir(parents=True, exist_ok=True)
+ (target / "auto" / "exam.md").write_text("# parsed", encoding="utf-8")
+ log_path.write_text("downloading model...\n\nparsing page 1/3\n", encoding="utf-8")
+ yield SimpleNamespace(poll=lambda: 0)
monkeypatch.setattr(pdf_parser, "check_mineru_installed", lambda: "mineru")
- monkeypatch.setattr(pdf_parser.subprocess, "Popen", FakeProcess)
+ monkeypatch.setattr(pdf_parser, "cli_process", fake_cli_process)
seen: list[str] = []
ok = pdf_parser.parse_pdf_with_mineru(str(pdf), str(out), on_output=seen.append)
@@ -291,18 +290,16 @@ def test_document_parser_passes_docx_to_current_mineru_cli(
out = tmp_path / "out"
captured: dict[str, list[str]] = {}
- class FakeProcess:
- def __init__(self, cmd, **_kwargs): # noqa: ANN001
- captured["cmd"] = cmd
- target = Path(cmd[cmd.index("-o") + 1]) / "lesson"
- target.mkdir(parents=True, exist_ok=True)
- (target / "lesson.md").write_text("# parsed", encoding="utf-8")
- self.stdout = iter([])
-
- def wait(self):
- return 0
+ @contextmanager
+ def fake_cli_process(cmd, log_path, env):
+ captured["cmd"] = cmd
+ target = Path(cmd[cmd.index("-o") + 1]) / "lesson"
+ target.mkdir(parents=True, exist_ok=True)
+ (target / "lesson.md").write_text("# parsed", encoding="utf-8")
+ log_path.write_text("", encoding="utf-8")
+ yield SimpleNamespace(poll=lambda: 0)
- monkeypatch.setattr(local_parser.subprocess, "Popen", FakeProcess)
+ monkeypatch.setattr(local_parser, "cli_process", fake_cli_process)
assert local_parser.parse_document_with_mineru(str(source), str(out), cli_command="mineru")
assert captured["cmd"][:3] == ["mineru", "-p", str(source.resolve())]