python_tracer.py 543 B

1234567891011121314151617181920
  1. import os
  2. import site
  3. import sys
  4. import torch
  5. def _prefix_regex() -> list[str]:
  6. raw_paths = (
  7. site.getsitepackages()
  8. + sys.path
  9. + [site.getuserbase()]
  10. + [site.getusersitepackages()]
  11. + [os.path.dirname(os.path.dirname(torch.__file__))]
  12. )
  13. path_prefixes = sorted({os.path.abspath(i) for i in raw_paths}, reverse=True)
  14. if not all(isinstance(i, str) for i in path_prefixes):
  15. raise AssertionError("all path_prefixes must be strings")
  16. return [i + os.sep for i in path_prefixes]