1616
1717import importlib .metadata
1818import subprocess
19+ import sys
1920from typing import Any , Dict , List , Optional , Tuple
21+
2022from tpu_info import args_helper
2123from tpu_info import device
2224from tpu_info import metrics
@@ -33,6 +35,38 @@ def _bytes_to_gib(size: int) -> float:
3335 return size / (1 << 30 )
3436
3537
38+ def is_incompatible_python_version () -> bool :
39+ """Checks if the current Python version is 3.12 or newer."""
40+ if sys .version_info < (3 , 12 ):
41+ return False
42+ try :
43+ from packaging .version import parse as parse_version
44+ import libtpu # pytype: disable=import-error
45+
46+ first_compatible_version = parse_version ("3.20" )
47+ current_version = parse_version (libtpu .__version__ )
48+ if current_version < first_compatible_version :
49+ return True
50+ else :
51+ return False
52+ except (ImportError , AttributeError ):
53+ return True
54+
55+
56+ def get_py_compat_warning_panel () -> panel .Panel :
57+ """Returns a Rich Panel with a Python compatibility warning."""
58+ warning_text = (
59+ "Some features are disabled due to an incompatibility between the libtpu"
60+ " SDK and Python 3.12+.\n \n For full functionality, please use a"
61+ " different Python environment."
62+ )
63+ return panel .Panel (
64+ f"[yellow]{ warning_text } [/yellow]" ,
65+ title = "[bold yellow]Compatibility Warning[/bold yellow]" ,
66+ border_style = "yellow" ,
67+ )
68+
69+
3670def fetch_cli_version () -> str :
3771 """Returns the version of the current TPU CLI."""
3872 try :
0 commit comments