Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/platformdirs/macos.py: 0%

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

64 statements  

1"""macOS.""" 

2 

3from __future__ import annotations 

4 

5import os.path 

6import sys 

7 

8from .api import PlatformDirsABC 

9 

10 

11class MacOS(PlatformDirsABC): 

12 """ 

13 Platform directories for the macOS operating system. 

14 

15 Follows the guidance from 

16 `Apple documentation <https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html>`_. 

17 Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>`, 

18 `version <platformdirs.api.PlatformDirsABC.version>`, 

19 `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`. 

20 

21 """ 

22 

23 @property 

24 def user_data_dir(self) -> str: 

25 """:return: data directory tied to the user, e.g. ``~/Library/Application Support/$appname/$version``""" 

26 return self._append_app_name_and_version(os.path.expanduser("~/Library/Application Support")) # noqa: PTH111 

27 

28 @property 

29 def site_data_dir(self) -> str: 

30 """ 

31 :return: data directory shared by users, e.g. ``/Library/Application Support/$appname/$version``. 

32 If we're using a Python binary managed by `Homebrew <https://brew.sh>`_, the directory 

33 will be under the Homebrew prefix, e.g. ``/opt/homebrew/share/$appname/$version``. 

34 If `multipath <platformdirs.api.PlatformDirsABC.multipath>` is enabled, and we're in Homebrew, 

35 the response is a multi-path string separated by ":", e.g. 

36 ``/opt/homebrew/share/$appname/$version:/Library/Application Support/$appname/$version`` 

37 """ 

38 is_homebrew = sys.prefix.startswith("/opt/homebrew") 

39 path_list = [self._append_app_name_and_version("/opt/homebrew/share")] if is_homebrew else [] 

40 path_list.append(self._append_app_name_and_version("/Library/Application Support")) 

41 if self.multipath: 

42 return os.pathsep.join(path_list) 

43 return path_list[0] 

44 

45 @property 

46 def user_config_dir(self) -> str: 

47 """:return: config directory tied to the user, same as `user_data_dir`""" 

48 return self.user_data_dir 

49 

50 @property 

51 def site_config_dir(self) -> str: 

52 """:return: config directory shared by the users, same as `site_data_dir`""" 

53 return self.site_data_dir 

54 

55 @property 

56 def user_cache_dir(self) -> str: 

57 """:return: cache directory tied to the user, e.g. ``~/Library/Caches/$appname/$version``""" 

58 return self._append_app_name_and_version(os.path.expanduser("~/Library/Caches")) # noqa: PTH111 

59 

60 @property 

61 def site_cache_dir(self) -> str: 

62 """ 

63 :return: cache directory shared by users, e.g. ``/Library/Caches/$appname/$version``. 

64 If we're using a Python binary managed by `Homebrew <https://brew.sh>`_, the directory 

65 will be under the Homebrew prefix, e.g. ``/opt/homebrew/var/cache/$appname/$version``. 

66 If `multipath <platformdirs.api.PlatformDirsABC.multipath>` is enabled, and we're in Homebrew, 

67 the response is a multi-path string separated by ":", e.g. 

68 ``/opt/homebrew/var/cache/$appname/$version:/Library/Caches/$appname/$version`` 

69 """ 

70 is_homebrew = sys.prefix.startswith("/opt/homebrew") 

71 path_list = [self._append_app_name_and_version("/opt/homebrew/var/cache")] if is_homebrew else [] 

72 path_list.append(self._append_app_name_and_version("/Library/Caches")) 

73 if self.multipath: 

74 return os.pathsep.join(path_list) 

75 return path_list[0] 

76 

77 @property 

78 def user_state_dir(self) -> str: 

79 """:return: state directory tied to the user, same as `user_data_dir`""" 

80 return self.user_data_dir 

81 

82 @property 

83 def user_log_dir(self) -> str: 

84 """:return: log directory tied to the user, e.g. ``~/Library/Logs/$appname/$version``""" 

85 return self._append_app_name_and_version(os.path.expanduser("~/Library/Logs")) # noqa: PTH111 

86 

87 @property 

88 def user_documents_dir(self) -> str: 

89 """:return: documents directory tied to the user, e.g. ``~/Documents``""" 

90 return os.path.expanduser("~/Documents") # noqa: PTH111 

91 

92 @property 

93 def user_downloads_dir(self) -> str: 

94 """:return: downloads directory tied to the user, e.g. ``~/Downloads``""" 

95 return os.path.expanduser("~/Downloads") # noqa: PTH111 

96 

97 @property 

98 def user_pictures_dir(self) -> str: 

99 """:return: pictures directory tied to the user, e.g. ``~/Pictures``""" 

100 return os.path.expanduser("~/Pictures") # noqa: PTH111 

101 

102 @property 

103 def user_videos_dir(self) -> str: 

104 """:return: videos directory tied to the user, e.g. ``~/Movies``""" 

105 return os.path.expanduser("~/Movies") # noqa: PTH111 

106 

107 @property 

108 def user_music_dir(self) -> str: 

109 """:return: music directory tied to the user, e.g. ``~/Music``""" 

110 return os.path.expanduser("~/Music") # noqa: PTH111 

111 

112 @property 

113 def user_desktop_dir(self) -> str: 

114 """:return: desktop directory tied to the user, e.g. ``~/Desktop``""" 

115 return os.path.expanduser("~/Desktop") # noqa: PTH111 

116 

117 @property 

118 def user_runtime_dir(self) -> str: 

119 """:return: runtime directory tied to the user, e.g. ``~/Library/Caches/TemporaryItems/$appname/$version``""" 

120 return self._append_app_name_and_version(os.path.expanduser("~/Library/Caches/TemporaryItems")) # noqa: PTH111 

121 

122 @property 

123 def site_runtime_dir(self) -> str: 

124 """:return: runtime directory shared by users, same as `user_runtime_dir`""" 

125 return self.user_runtime_dir 

126 

127 

128__all__ = [ 

129 "MacOS", 

130]