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

feat(cli): check for Tkinter in pn doctor by Zer0codestuff · Pull Request #25 · pythonnative/pythonnative · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
22 changes: 21 additions & 1 deletion src/pythonnative/project/doctor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ def _which_version(tool: str, version_args: List[str]) -> Optional[str]:
return text[0] if text else path


def _tkinter_available() -> bool:
"""Return whether the host Python can import Tkinter."""
try:
import tkinter # noqa: F401
except ImportError:
return False
return True


def check_common() -> List[CheckResult]:
"""Run platform-agnostic checks (interpreter, Pillow).
"""Run platform-agnostic checks (interpreter and optional dependencies).

Returns:
Check results for the host Python and optional dependencies.
Expand All @@ -89,6 +98,17 @@ def check_common() -> List[CheckResult]:
"not installed; run: pip install 'pythonnative[build]'",
)
)
if _tkinter_available():
results.append(CheckResult("Tkinter (desktop preview)", OK))
else:
results.append(
CheckResult(
"Tkinter (desktop preview)",
WARN,
"not installed; macOS: brew install python-tk; Debian/Ubuntu: sudo apt-get install python3-tk; "
"Windows: reinstall Python with the 'tcl/tk' option checked",
)
)
return results


Expand Down
18 changes: 18 additions & 0 deletions tests/project/test_doctor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from pathlib import Path

from pytest import MonkeyPatch

from pythonnative.project import doctor
from pythonnative.project.config import render_default_toml

Expand Down Expand Up @@ -43,6 +45,22 @@ def test_common_checks_present(tmp_path: Path) -> None:
names = [r.name for r in results]
assert any("Python" in n for n in names)
assert any("Pillow" in n for n in names)
assert "Tkinter (desktop preview)" in names


def test_common_check_reports_available_tkinter(monkeypatch: MonkeyPatch) -> None:
monkeypatch.setattr(doctor, "_tkinter_available", lambda: True)
result = next(r for r in doctor.check_common() if r.name == "Tkinter (desktop preview)")
assert result.level == doctor.OK
assert result.detail == ""


def test_common_check_reports_missing_tkinter(monkeypatch: MonkeyPatch) -> None:
monkeypatch.setattr(doctor, "_tkinter_available", lambda: False)
result = next(r for r in doctor.check_common() if r.name == "Tkinter (desktop preview)")
assert result.level == doctor.WARN
assert "python3-tk" in result.detail
assert "tcl/tk" in result.detail


def test_worst_level() -> None:
Expand Down
Loading

Back | FazBrowse Home | New Git URL