From d399a3a65bdbe93f6e3ef4fe852fc5a08822a7c7 Mon Sep 17 00:00:00 2001 From: xxyzz Date: Sun, 18 Jun 2023 18:41:53 +0800 Subject: [PATCH] Raise exception if Python can't be found On Windows run unexisting command `python` will get a different error other then the normal `FileNotFoundError`. --- __init__.py | 2 +- data/deps.json | 2 +- deps.py | 6 ++++++ error_dialogs.py | 6 +++--- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/__init__.py b/__init__.py index 518b06b..f3fca60 100644 --- a/__init__.py +++ b/__init__.py @@ -2,7 +2,7 @@ from calibre.customize import InterfaceActionBase -VERSION = (3, 29, 2) +VERSION = (3, 29, 3) class WordDumbDumb(InterfaceActionBase): diff --git a/data/deps.json b/data/deps.json index f76a147..bd16bc7 100644 --- a/data/deps.json +++ b/data/deps.json @@ -3,6 +3,6 @@ "lxml": "4.9.2", "thinc-apple-ops": "0.1.3", "torch": "2.0.1", - "rapidfuzz": "3.0.0", + "rapidfuzz": "3.1.1", "spacy_model": "3.5.0" } diff --git a/deps.py b/deps.py index b523504..59351c0 100644 --- a/deps.py +++ b/deps.py @@ -71,12 +71,18 @@ def install_deps(pkg: str, notif: Any) -> None: def which_python() -> tuple[str, str]: + """ + Return Python command or file path and version string + """ py = "python3" if iswindows: py = "py" if shutil.which("py") else "python" elif ismacos: py = homebrew_mac_bin_path("python3") + if shutil.which(py) is None: + raise Exception("PythonNotFound") + if isfrozen: r = run_subprocess( [ diff --git a/error_dialogs.py b/error_dialogs.py index 18a6b37..5089db6 100644 --- a/error_dialogs.py +++ b/error_dialogs.py @@ -21,11 +21,11 @@ def error_dialog(title: str, message: str, error: str, parent: Any) -> None: def job_failed(job: Any, parent: Any = None) -> bool: if job and job.failed: - if "FileNotFoundError" in job.details and "subprocess.py" in job.details: + if "PythonNotFound" in job.details: error_dialog( "We want... a shrubbery!", _( - "Please read the friendly manual of how to install Python." + "Can't find Python. Please read the document of how to install Python." ).format(INSTALL_PYTHON_DOC), job.details, parent, @@ -34,7 +34,7 @@ def job_failed(job: Any, parent: Any = None) -> bool: error_dialog( "Outdated Python", _( - "Please read the friendly manual of how to install Python." + "Your Python version is too old, please update to a newer version and read the document for more information." ).format(INSTALL_PYTHON_DOC), job.details, parent,