appdirs.py 1.2 KB

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