Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.
Python agent-skillsai-agentsbook-to-skillcontext-engineeringdocument-processingedtechknowledge-baseknowledge-managementllmpdf-to-markdownragself-studystudy-tools
fix(deps): honor alternative parser availability (#208)
Stamina9ecf99ee36a7b
diff --git a/book_to_skill/dependencies.py b/book_to_skill/dependencies.pyindex 9166eb6..b19db0b 100644--- a/book_to_skill/dependencies.py+++ b/book_to_skill/dependencies.py@@ -157,12 +157,21 @@ def offer_dependency_install(module_names: list[str],fallback: str | None,install_mode: str,+ any_of_modules: bool = False,) -> None:- packages = missing_python_packages(module_names)- if not packages:+ missing_packages = missing_python_packages(module_names)+ if not missing_packages or (+ any_of_modules and len(missing_packages) < len(module_names)+ ):return- message = f"{feature} uses {', '.join(packages)} if installed"+ package_choices = [PYTHON_DEPENDENCIES[name] for name in module_names]+ if any_of_modules:+ message = f"{feature} uses one of {', '.join(package_choices)} if installed"+ packages = missing_packages[:1]+ else:+ message = f"{feature} uses {', '.join(missing_packages)} if installed"+ packages = missing_packagesif fallback:message += f", otherwise {fallback}"message += "."@@ -187,7 +196,12 @@ def offer_dependency_install(if install_python_packages(packages):still_missing = missing_python_packages(module_names)- if not still_missing:+ dependencies_satisfied = (+ len(still_missing) < len(module_names)+ if any_of_modules+ else not still_missing+ )+ if dependencies_satisfied:print("Package installation complete.")returnprint(f"Package installation incomplete; still missing: {', '.join(still_missing)}", file=sys.stderr)@@ -213,6 +227,7 @@ def prepare_dependencies(ext: str, extraction_mode: str, install_mode: str) -> Nmodule_names=["pypdf", "pdfminer"],fallback="any installed Python PDF parser; extraction fails if none are available",install_mode=install_mode,+ any_of_modules=True,)if ext == ".epub":@@ -226,9 +241,10 @@ def prepare_dependencies(ext: str, extraction_mode: str, install_mode: str) -> Nif ext in HTML_EXTENSIONS:offer_dependency_install(feature="HTML extraction",- module_names=["bs4"],+ module_names=["trafilatura", "bs4"],fallback="a stdlib HTML parser",install_mode=install_mode,+ any_of_modules=True,)if ext == ".docx":diff --git a/tests/test_dependency_install_semantics.py b/tests/test_dependency_install_semantics.pynew file mode 100644index 0000000..7453d14--- /dev/null+++ b/tests/test_dependency_install_semantics.py@@ -0,0 +1,69 @@+"""Runtime dependency prompts should match the extractor fallback semantics."""++from book_to_skill import dependencies+++def _fail_install(packages):+ raise AssertionError(f"unexpected dependency installation: {packages}")+++def test_pdf_preflight_accepts_one_available_python_parser(monkeypatch):+ monkeypatch.setattr(dependencies.shutil, "which", lambda _command: None)+ monkeypatch.setattr(+ dependencies,+ "python_module_available",+ lambda module: module == "pypdf",+ )+ monkeypatch.setattr(dependencies, "install_python_packages", _fail_install)++ dependencies.prepare_dependencies(".pdf", "text", "yes")+++def test_html_preflight_accepts_available_trafilatura(monkeypatch):+ monkeypatch.setattr(+ dependencies,+ "python_module_available",+ lambda module: module == "trafilatura",+ )+ monkeypatch.setattr(dependencies, "install_python_packages", _fail_install)++ dependencies.prepare_dependencies(".html", "text", "yes")+++def test_any_of_group_installs_only_the_preferred_parser(monkeypatch):+ installed = []+ monkeypatch.setattr(dependencies, "python_module_available", lambda _module: False)+ monkeypatch.setattr(+ dependencies,+ "install_python_packages",+ lambda packages: installed.append(packages) or False,+ )++ dependencies.offer_dependency_install(+ feature="HTML extraction",+ module_names=["trafilatura", "bs4"],+ fallback="the stdlib HTML parser",+ install_mode="yes",+ any_of_modules=True,+ )++ assert installed == [["trafilatura"]]+++def test_all_required_group_still_installs_every_missing_package(monkeypatch):+ installed = []+ monkeypatch.setattr(dependencies, "python_module_available", lambda _module: False)+ monkeypatch.setattr(+ dependencies,+ "install_python_packages",+ lambda packages: installed.append(packages) or False,+ )++ dependencies.offer_dependency_install(+ feature="EPUB extraction",+ module_names=["ebooklib", "bs4"],+ fallback="a stdlib ZIP/HTML parser",+ install_mode="yes",+ )++ assert installed == [["ebooklib", "beautifulsoup4"]]