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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

26 statements  

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 

11 

12from pip._vendor import platformdirs as _appdirs 

13 

14 

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

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

17 

18 

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

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

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

22 if os.path.isdir(path): 

23 return path 

24 

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

26 linux_like_path = "~/.config/" 

27 if appname: 

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

29 

30 return os.path.expanduser(linux_like_path) 

31 

32 

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

34 if sys.platform == "darwin": 

35 return _macos_user_config_dir(appname, roaming) 

36 

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

38 

39 

40# for the discussion regarding site_config_dir locations 

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

42def site_config_dirs(appname: str) -> list[str]: 

43 if sys.platform == "darwin": 

44 dirval = _appdirs.site_data_dir(appname, appauthor=False, multipath=True) 

45 return dirval.split(os.pathsep) 

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"]