45 lines
1.3 KiB
Python
Raw Normal View History

2022-08-10 20:32:35 -04:00
"""
2022-08-12 01:34:18 -04:00
This code wraps the vendored appdirs module to so the return values are
compatible for the current pip code base.
The intention is to rewrite current usages gradually, keeping the tests pass,
and eventually drop this after all usages are changed.
2022-08-10 20:32:35 -04:00
"""
2022-08-12 01:34:18 -04:00
2022-08-10 20:32:35 -04:00
from __future__ import absolute_import
import os
2022-08-12 01:34:18 -04:00
from pip._vendor import appdirs as _appdirs
2022-08-10 20:32:35 -04:00
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
if MYPY_CHECK_RUNNING:
from typing import List
def user_cache_dir(appname):
# type: (str) -> str
2022-08-12 01:34:18 -04:00
return _appdirs.user_cache_dir(appname, appauthor=False)
2022-08-10 20:32:35 -04:00
def user_config_dir(appname, roaming=True):
# type: (str, bool) -> str
2022-08-12 01:34:18 -04:00
path = _appdirs.user_config_dir(appname, appauthor=False, roaming=roaming)
if _appdirs.system == "darwin" and not os.path.isdir(path):
path = os.path.expanduser('~/.config/')
if appname:
path = os.path.join(path, appname)
2022-08-10 20:32:35 -04:00
return path
2022-08-12 01:34:18 -04:00
# for the discussion regarding site_config_dir locations
2022-08-10 20:32:35 -04:00
# see <https://github.com/pypa/pip/issues/1733>
def site_config_dirs(appname):
# type: (str) -> List[str]
2022-08-12 01:34:18 -04:00
dirval = _appdirs.site_config_dir(appname, appauthor=False, multipath=True)
if _appdirs.system not in ["win32", "darwin"]:
2022-08-10 20:32:35 -04:00
# always look in /etc directly as well
2022-08-12 01:34:18 -04:00
return dirval.split(os.pathsep) + ['/etc']
return [dirval]