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

64 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-05 06:26 +0000

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. Follows the guidance from `Apple documentation 

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

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

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

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

18 """ 

19 

20 @property 

21 def user_data_dir(self) -> str: 

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

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

24 

25 @property 

26 def site_data_dir(self) -> str: 

27 """ 

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

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

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

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

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

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

34 """ 

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

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

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

38 if self.multipath: 

39 return os.pathsep.join(path_list) 

40 return path_list[0] 

41 

42 @property 

43 def user_config_dir(self) -> str: 

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

45 return self.user_data_dir 

46 

47 @property 

48 def site_config_dir(self) -> str: 

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

50 return self.site_data_dir 

51 

52 @property 

53 def user_cache_dir(self) -> str: 

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

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

56 

57 @property 

58 def site_cache_dir(self) -> str: 

59 """ 

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

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

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

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

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

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

66 """ 

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

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

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

70 if self.multipath: 

71 return os.pathsep.join(path_list) 

72 return path_list[0] 

73 

74 @property 

75 def user_state_dir(self) -> str: 

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

77 return self.user_data_dir 

78 

79 @property 

80 def user_log_dir(self) -> str: 

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

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

83 

84 @property 

85 def user_documents_dir(self) -> str: 

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

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

88 

89 @property 

90 def user_downloads_dir(self) -> str: 

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

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

93 

94 @property 

95 def user_pictures_dir(self) -> str: 

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

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

98 

99 @property 

100 def user_videos_dir(self) -> str: 

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

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

103 

104 @property 

105 def user_music_dir(self) -> str: 

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

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

108 

109 @property 

110 def user_desktop_dir(self) -> str: 

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

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

113 

114 @property 

115 def user_runtime_dir(self) -> str: 

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

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

118 

119 @property 

120 def site_runtime_dir(self) -> str: 

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

122 return self.user_runtime_dir 

123 

124 

125__all__ = [ 

126 "MacOS", 

127]