Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pip/_internal/utils/appdirs.py: 36%

25 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:48 +0000

1""" 

2This code wraps the vendored appdirs module to so the return values are 

3compatible for the current pip code base. 

4 

5The intention is to rewrite current usages gradually, keeping the tests pass, 

6and eventually drop this after all usages are changed. 

7""" 

8 

9import os 

10import sys 

11from typing import List 

12 

13from pip._vendor import platformdirs as _appdirs 

14 

15 

16def user_cache_dir(appname: str) -> str: 

17 return _appdirs.user_cache_dir(appname, appauthor=False) 

18 

19 

20def _macos_user_config_dir(appname: str, roaming: bool = True) -> str: 

21 # Use ~/Application Support/pip, if the directory exists. 

22 path = _appdirs.user_data_dir(appname, appauthor=False, roaming=roaming) 

23 if os.path.isdir(path): 

24 return path 

25 

26 # Use a Linux-like ~/.config/pip, by default. 

27 linux_like_path = "~/.config/" 

28 if appname: 

29 linux_like_path = os.path.join(linux_like_path, appname) 

30 

31 return os.path.expanduser(linux_like_path) 

32 

33 

34def user_config_dir(appname: str, roaming: bool = True) -> str: 

35 if sys.platform == "darwin": 

36 return _macos_user_config_dir(appname, roaming) 

37 

38 return _appdirs.user_config_dir(appname, appauthor=False, roaming=roaming) 

39 

40 

41# for the discussion regarding site_config_dir locations 

42# see <https://github.com/pypa/pip/issues/1733> 

43def site_config_dirs(appname: str) -> List[str]: 

44 if sys.platform == "darwin": 

45 return [_appdirs.site_data_dir(appname, appauthor=False, multipath=True)] 

46 

47 dirval = _appdirs.site_config_dir(appname, appauthor=False, multipath=True) 

48 if sys.platform == "win32": 

49 return [dirval] 

50 

51 # Unix-y system. Look in /etc as well. 

52 return dirval.split(os.pathsep) + ["/etc"]