You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

virtualenv.py 891B

12345678910111213141516171819202122232425262728293031323334
  1. import os.path
  2. import site
  3. import sys
  4. def running_under_virtualenv():
  5. # type: () -> bool
  6. """
  7. Return True if we're running inside a virtualenv, False otherwise.
  8. """
  9. if hasattr(sys, 'real_prefix'):
  10. # pypa/virtualenv case
  11. return True
  12. elif sys.prefix != getattr(sys, "base_prefix", sys.prefix):
  13. # PEP 405 venv
  14. return True
  15. return False
  16. def virtualenv_no_global():
  17. # type: () -> bool
  18. """
  19. Return True if in a venv and no system site packages.
  20. """
  21. # this mirrors the logic in virtualenv.py for locating the
  22. # no-global-site-packages.txt file
  23. site_mod_dir = os.path.dirname(os.path.abspath(site.__file__))
  24. no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt')
  25. if running_under_virtualenv() and os.path.isfile(no_global_file):
  26. return True
  27. else:
  28. return False