MCPcopy Create free account
hub / github.com/unslothai/unsloth / _path_inside_venv

Function _path_inside_venv

studio/install_python_stack.py:285–300  ·  view source on GitHub ↗

True if ``path`` is inside the active venv (sys.prefix). The venv hipInfo.exe (AMD wheel, put on PATH by the bnb fix) is NOT a HIP SDK (_amd_smi_allowed).

(path: str)

Source from the content-addressed store, hash-verified

283
284
285def _path_inside_venv(path: str) -> bool:
286 """True if ``path`` is inside the active venv (sys.prefix).
287
288 The venv hipInfo.exe (AMD wheel, put on PATH by the bnb fix) is NOT a HIP SDK
289 (_amd_smi_allowed)."""
290 try:
291 # realpath (not abspath): resolve symlinks/8.3 names so an aliased venv matches.
292 _root = os.path.normcase(os.path.realpath(sys.prefix))
293 # Guard a root-dir prefix (C:\ or /): commonpath would match every path on
294 # it. A venv is never at root, so treat that as outside.
295 if os.path.dirname(_root) == _root:
296 return False
297 return os.path.normcase(os.path.commonpath([os.path.realpath(path), _root])) == _root
298 except (ValueError, OSError):
299 # Different drive / unresolvable -> treat as outside the venv.
300 return False
301
302
303def _external_hipinfo_on_path() -> bool:

Callers 2

_amd_smi_allowedFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…