Skip to content

Commit

Permalink
Raise exception if Python can't be found
Browse files Browse the repository at this point in the history
On Windows run unexisting command `python` will get a different error
other then the normal `FileNotFoundError`.
  • Loading branch information
xxyzz committed Jun 18, 2023
1 parent 0f195cb commit d399a3a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from calibre.customize import InterfaceActionBase

VERSION = (3, 29, 2)
VERSION = (3, 29, 3)


class WordDumbDumb(InterfaceActionBase):
Expand Down
2 changes: 1 addition & 1 deletion data/deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
6 changes: 6 additions & 0 deletions deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down
6 changes: 3 additions & 3 deletions error_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href='{}'>manual</a> of how to install Python."
"Can't find Python. Please read the <a href='{}'>document</a> of how to install Python."
).format(INSTALL_PYTHON_DOC),
job.details,
parent,
Expand All @@ -34,7 +34,7 @@ def job_failed(job: Any, parent: Any = None) -> bool:
error_dialog(
"Outdated Python",
_(
"Please read the friendly <a href='{}'>manual</a> of how to install Python."
"Your Python version is too old, please update to a newer version and read the <a href='{}'>document</a> for more information."
).format(INSTALL_PYTHON_DOC),
job.details,
parent,
Expand Down

0 comments on commit d399a3a

Please sign in to comment.