appdirs.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. import os
  8. from typing import List
  9. from pip._vendor import appdirs as _appdirs
  10. def user_cache_dir(appname):
  11. # type: (str) -> str
  12. return _appdirs.user_cache_dir(appname, appauthor=False)
  13. def user_config_dir(appname, roaming=True):
  14. # type: (str, bool) -> str
  15. path = _appdirs.user_config_dir(appname, appauthor=False, roaming=roaming)
  16. if _appdirs.system == "darwin" and not os.path.isdir(path):
  17. path = os.path.expanduser("~/.config/")
  18. if appname:
  19. path = os.path.join(path, appname)
  20. return path
  21. # for the discussion regarding site_config_dir locations
  22. # see <https://github.com/pypa/pip/issues/1733>
  23. def site_config_dirs(appname):
  24. # type: (str) -> List[str]
  25. dirval = _appdirs.site_config_dir(appname, appauthor=False, multipath=True)
  26. if _appdirs.system not in ["win32", "darwin"]:
  27. # always look in /etc directly as well
  28. return dirval.split(os.pathsep) + ["/etc"]
  29. return [dirval]