FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(cli): check for Tkinter in pn doctor · pythonnative/pythonnative@e4ca700 · GitHub

Repository navigation

Commit e4ca700

Browse files
committed
feat(cli): check for Tkinter in pn doctor
1 parent b57586f commit e4ca700

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎src/pythonnative/project/doctor.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,17 @@ def _which_version(tool: str, version_args: List[str]) -> Optional[str]:
6161
return text[0] if text else path
6262

6363

64+
def _tkinter_available() -> bool:
65+
"""Return whether the host Python can import Tkinter."""
66+
try:
67+
import tkinter # noqa: F401
68+
except ImportError:
69+
return False
70+
return True
71+
72+
6473
def check_common() -> List[CheckResult]:
65-
"""Run platform-agnostic checks (interpreter, Pillow).
74+
"""Run platform-agnostic checks (interpreter and optional dependencies).
6675
6776
Returns:
6877
Check results for the host Python and optional dependencies.
@@ -89,6 +98,17 @@ def check_common() -> List[CheckResult]:
8998
"not installed; run: pip install 'pythonnative[build]'",
9099
)
91100
)
101+
if _tkinter_available():
102+
results.append(CheckResult("Tkinter (desktop preview)", OK))
103+
else:
104+
results.append(
105+
CheckResult(
106+
"Tkinter (desktop preview)",
107+
WARN,
108+
"not installed; macOS: brew install python-tk; Debian/Ubuntu: sudo apt-get install python3-tk; "
109+
"Windows: reinstall Python with the 'tcl/tk' option checked",
110+
)
111+
)
92112
return results
93113

94114

‎tests/project/test_doctor.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from pathlib import Path
22

3+
from pytest import MonkeyPatch
4+
35
from pythonnative.project import doctor
46
from pythonnative.project.config import render_default_toml
57

@@ -43,6 +45,22 @@ def test_common_checks_present(tmp_path: Path) -> None:
4345
names = [r.name for r in results]
4446
assert any("Python" in n for n in names)
4547
assert any("Pillow" in n for n in names)
48+
assert "Tkinter (desktop preview)" in names
49+
50+
51+
def test_common_check_reports_available_tkinter(monkeypatch: MonkeyPatch) -> None:
52+
monkeypatch.setattr(doctor, "_tkinter_available", lambda: True)
53+
result = next(r for r in doctor.check_common() if r.name == "Tkinter (desktop preview)")
54+
assert result.level == doctor.OK
55+
assert result.detail == ""
56+
57+
58+
def test_common_check_reports_missing_tkinter(monkeypatch: MonkeyPatch) -> None:
59+
monkeypatch.setattr(doctor, "_tkinter_available", lambda: False)
60+
result = next(r for r in doctor.check_common() if r.name == "Tkinter (desktop preview)")
61+
assert result.level == doctor.WARN
62+
assert "python3-tk" in result.detail
63+
assert "tcl/tk" in result.detail
4664

4765

4866
def test_worst_level() -> None:

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL