appdirs.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """
  2. This code wraps the vendored appdirs module to so the return values are
  3. compatible for the current pip code base.
  4. The intention is to rewrite current usages gradually, keeping the tests pass,
  5. and eventually drop this after all usages are changed.
  6. """
  7. from __future__ import absolute_import
  8. import os
  9. from pip._vendor import appdirs as _appdirs
  10. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  11. if MYPY_CHECK_RUNNING:
  12. from typing import List
  13. def user_cache_dir(appname):
  14. # type: (str) -> str
  15. return _appdirs.user_cache_dir(appname, appauthor=False)
  16. def user_config_dir(appname, roaming=True):
  17. # type: (str, bool) -> str
  18. path = _appdirs.user_config_dir(appname, appauthor=False, roaming=roaming)
  19. if _appdirs.system == "darwin" and not os.path.isdir(path):
  20. path = os.path.expanduser('~/.config/')
  21. if appname:
  22. path = os.path.join(path, appname)
  23. return path
  24. # for the discussion regarding site_config_dir locations
  25. # see <https://github.com/pypa/pip/issues/1733>
  26. def site_config_dirs(appname):
  27. # type: (str) -> List[str]
  28. dirval = _appdirs.site_config_dir(appname, appauthor=False, multipath=True)
  29. if _appdirs.system not in ["win32", "darwin"]:
  30. # always look in /etc directly as well
  31. return dirval.split(os.pathsep) + ['/etc']
  32. return [dirval]