diff --git a/config.py b/config.py index 1bb03d9..8235991 100644 --- a/config.py +++ b/config.py @@ -249,7 +249,7 @@ def open_kindle_lemmas_dialog(self) -> None: gui.job_manager.run_threaded_job(job) def save_kindle_lemmas(self, lemmas, abort=None, log=None, notifications=None): - install_deps("lemminflect", None, notifications) + install_deps("lemminflect", notifications) notifications.put((0, _("Saving customized lemmas"))) custom_path = custom_kindle_dump_path(self.plugin_path) if ismacos: diff --git a/deps.py b/deps.py index 8761d27..c9732a7 100644 --- a/deps.py +++ b/deps.py @@ -26,10 +26,10 @@ USE_SYSTEM_PYTHON = False -def install_deps(model: str, book_fmt: str | None, notif: Any) -> None: +def install_deps(pkg: str, notif: Any) -> None: global PY_PATH, LIBS_PATH, CALIBRE_DEBUG_PATH, RUNNABLE_PIP, USE_SYSTEM_PYTHON plugin_path = get_plugin_path() - USE_SYSTEM_PYTHON = ismacos or (isfrozen and model.endswith("_trf")) + USE_SYSTEM_PYTHON = ismacos or (isfrozen and pkg.endswith("_trf")) if PY_PATH is None: PY_PATH, py_version = which_python(USE_SYSTEM_PYTHON) @@ -39,18 +39,20 @@ def install_deps(model: str, book_fmt: str | None, notif: Any) -> None: RUNNABLE_PIP = get_runnable_pip(PY_PATH) dep_versions = load_json_or_pickle(plugin_path, "data/deps.json") - if model == "lemminflect": + if pkg == "lemminflect": pip_install("lemminflect", dep_versions["lemminflect"], notif=notif) - elif model == "wiktionary_cjk": + elif pkg == "pyahocorasick": pip_install("pyahocorasick", dep_versions["pyahocorasick"], notif=notif) + elif pkg == "lxml": + pip_install("lxml", dep_versions["lxml"], notif=notif) else: # Install X-Ray dependencies pip_install("rapidfuzz", dep_versions["rapidfuzz"], notif=notif) - spacy_model_version = "3.4.1" if model.startswith("en") else "3.4.0" - url = f"https://github.com/explosion/spacy-models/releases/download/{model}-{spacy_model_version}/{model}-{spacy_model_version}-py3-none-any.whl" - pip_install(model, spacy_model_version, url=url, notif=notif) - if model.endswith("_trf"): + spacy_model_version = "3.4.1" if pkg.startswith("en") else "3.4.0" + url = f"https://github.com/explosion/spacy-models/releases/download/{pkg}-{spacy_model_version}/{pkg}-{spacy_model_version}-py3-none-any.whl" + pip_install(pkg, spacy_model_version, url=url, notif=notif) + if pkg.endswith("_trf"): from .config import prefs pip_install("cupy-wheel", dep_versions["cupy"], notif=notif) @@ -185,7 +187,7 @@ def download_wiktionary( lemma_lang: str, gloss_lang: str, abort=None, log=None, notifications=None ) -> None: if lemma_lang in CJK_LANGS: - install_deps("wiktionary_cjk", None, notifications) + install_deps("pyahocorasick", notifications) if notifications: notifications.put((0, f"Downloading {lemma_lang}-{gloss_lang} Wiktionary file")) diff --git a/parse_job.py b/parse_job.py index d1e017e..6dcec01 100644 --- a/parse_job.py +++ b/parse_job.py @@ -112,8 +112,11 @@ def do_job( if not create_ww and not create_x: return return_values + cjk_epub_ww = book_fmt == "EPUB" and create_ww and lang["wiki"] in CJK_LANGS + if ismacos and cjk_epub_ww: + install_deps("lxml", notifications) if create_x: - install_deps(model, book_fmt, notifications) + install_deps(model, notifications) if notifications: notifications.put((0, "Creating files")) @@ -122,12 +125,9 @@ def do_job( # macOS: bypass library validation # official calibre build: calibre's optimize level is 2 which removes docstring, # but the "transformers" package formats docstrings in their code - if ( - ismacos - and ( - create_x or (book_fmt == "EPUB" and create_ww and lang["wiki"] in CJK_LANGS) - ) - ) or (create_x and isfrozen and model.endswith("_trf")): + if (ismacos and (create_x or cjk_epub_ww)) or ( + create_x and isfrozen and model.endswith("_trf") + ): plugin_path = str(plugin_path) py_path, _ = which_python(True) args = [