| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b57586f commit e4ca700
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,8 +61,17 @@ def _which_version(tool: str, version_args: List[str]) -> Optional[str]: | |||
| 61 | 61 | return text[0] if text else path | |
| 62 | 62 | ||
| 63 | 63 | ||
| 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 | + | ||
| 64 | 73 | def check_common() -> List[CheckResult]: | |
| 65 | - """Run platform-agnostic checks (interpreter, Pillow). | ||
| 74 | + """Run platform-agnostic checks (interpreter and optional dependencies). | ||
| 66 | 75 | ||
| 67 | 76 | Returns: | |
| 68 | 77 | Check results for the host Python and optional dependencies. | |
@@ -89,6 +98,17 @@ def check_common() -> List[CheckResult]: | |||
| 89 | 98 | "not installed; run: pip install 'pythonnative[build]'", | |
| 90 | 99 | ) | |
| 91 | 100 | ) | |
| 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 | + ) | ||
| 92 | 112 | return results | |
| 93 | 113 | ||
| 94 | 114 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,7 @@ | |||
| 1 | 1 | from pathlib import Path | |
| 2 | 2 | ||
| 3 | + from pytest import MonkeyPatch | ||
| 4 | + | ||
| 3 | 5 | from pythonnative.project import doctor | |
| 4 | 6 | from pythonnative.project.config import render_default_toml | |
| 5 | 7 | ||
@@ -43,6 +45,22 @@ def test_common_checks_present(tmp_path: Path) -> None: | |||
| 43 | 45 | names = [r.name for r in results] | |
| 44 | 46 | assert any("Python" in n for n in names) | |
| 45 | 47 | 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 | ||
| 46 | 64 | ||
| 47 | 65 | ||
| 48 | 66 | def test_worst_level() -> None: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments