MCPcopy Create free account
hub / github.com/pytorch/executorch / python_is_compatible

Function python_is_compatible

install_utils.py:204–246  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

202
203
204def python_is_compatible():
205 # Scrape the version range from pyproject.toml, which should be in the current directory.
206 version_specifier = None
207 with open("pyproject.toml", "r") as file:
208 for line in file:
209 if line.startswith("requires-python"):
210 match = re.search(r'"([^"]*)"', line)
211 if match:
212 version_specifier = match.group(1)
213 break
214
215 if not version_specifier:
216 print(
217 "WARNING: Skipping python version check: version range not found",
218 file=sys.stderr,
219 )
220 return False
221
222 # Install the packaging module if necessary.
223 try:
224 import packaging
225 except ImportError:
226 subprocess.run(
227 [sys.executable, "-m", "pip", "install", "packaging"], check=True
228 )
229 # Compare the current python version to the range in version_specifier. Exits
230 # with status 1 if the version is not compatible, or with status 0 if the
231 # version is compatible or the logic itself fails.
232 try:
233 import packaging.specifiers
234 import packaging.version
235
236 python_version = packaging.version.parse(platform.python_version())
237 version_range = packaging.specifiers.SpecifierSet(version_specifier)
238 if python_version not in version_range:
239 print(
240 f'ERROR: ExecuTorch does not support python version {python_version}: must satisfy "{version_specifier}"',
241 file=sys.stderr,
242 )
243 return False
244 except Exception as e:
245 print(f"WARNING: Skipping python version check: {e}", file=sys.stderr)
246 return True

Callers 2

mainFunction · 0.85

Calls 1

runMethod · 0.45

Tested by

no test coverage detected