Skip to content

Commit

Permalink
Install lxml on macOS for creating EPUB Word Wise footnotes in CJK …
Browse files Browse the repository at this point in the history
…languages
  • Loading branch information
xxyzz committed Dec 5, 2022
1 parent 2638fa8 commit 03a3700
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 11 additions & 9 deletions deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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"))
Expand Down
14 changes: 7 additions & 7 deletions parse_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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 = [
Expand Down

0 comments on commit 03a3700

Please sign in to comment.