macos.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. """macOS."""
  2. from __future__ import annotations
  3. import os.path
  4. from .api import PlatformDirsABC
  5. class MacOS(PlatformDirsABC):
  6. """
  7. Platform directories for the macOS operating system. Follows the guidance from `Apple documentation
  8. <https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html>`_.
  9. Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>`,
  10. `version <platformdirs.api.PlatformDirsABC.version>`,
  11. `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  12. """
  13. @property
  14. def user_data_dir(self) -> str:
  15. """:return: data directory tied to the user, e.g. ``~/Library/Application Support/$appname/$version``"""
  16. return self._append_app_name_and_version(os.path.expanduser("~/Library/Application Support")) # noqa: PTH111
  17. @property
  18. def site_data_dir(self) -> str:
  19. """:return: data directory shared by users, e.g. ``/Library/Application Support/$appname/$version``"""
  20. return self._append_app_name_and_version("/Library/Application Support")
  21. @property
  22. def user_config_dir(self) -> str:
  23. """:return: config directory tied to the user, same as `user_data_dir`"""
  24. return self.user_data_dir
  25. @property
  26. def site_config_dir(self) -> str:
  27. """:return: config directory shared by the users, same as `site_data_dir`"""
  28. return self.site_data_dir
  29. @property
  30. def user_cache_dir(self) -> str:
  31. """:return: cache directory tied to the user, e.g. ``~/Library/Caches/$appname/$version``"""
  32. return self._append_app_name_and_version(os.path.expanduser("~/Library/Caches")) # noqa: PTH111
  33. @property
  34. def site_cache_dir(self) -> str:
  35. """:return: cache directory shared by users, e.g. ``/Library/Caches/$appname/$version``"""
  36. return self._append_app_name_and_version("/Library/Caches")
  37. @property
  38. def user_state_dir(self) -> str:
  39. """:return: state directory tied to the user, same as `user_data_dir`"""
  40. return self.user_data_dir
  41. @property
  42. def user_log_dir(self) -> str:
  43. """:return: log directory tied to the user, e.g. ``~/Library/Logs/$appname/$version``"""
  44. return self._append_app_name_and_version(os.path.expanduser("~/Library/Logs")) # noqa: PTH111
  45. @property
  46. def user_documents_dir(self) -> str:
  47. """:return: documents directory tied to the user, e.g. ``~/Documents``"""
  48. return os.path.expanduser("~/Documents") # noqa: PTH111
  49. @property
  50. def user_downloads_dir(self) -> str:
  51. """:return: downloads directory tied to the user, e.g. ``~/Downloads``"""
  52. return os.path.expanduser("~/Downloads") # noqa: PTH111
  53. @property
  54. def user_pictures_dir(self) -> str:
  55. """:return: pictures directory tied to the user, e.g. ``~/Pictures``"""
  56. return os.path.expanduser("~/Pictures") # noqa: PTH111
  57. @property
  58. def user_videos_dir(self) -> str:
  59. """:return: videos directory tied to the user, e.g. ``~/Movies``"""
  60. return os.path.expanduser("~/Movies") # noqa: PTH111
  61. @property
  62. def user_music_dir(self) -> str:
  63. """:return: music directory tied to the user, e.g. ``~/Music``"""
  64. return os.path.expanduser("~/Music") # noqa: PTH111
  65. @property
  66. def user_desktop_dir(self) -> str:
  67. """:return: desktop directory tied to the user, e.g. ``~/Desktop``"""
  68. return os.path.expanduser("~/Desktop") # noqa: PTH111
  69. @property
  70. def user_runtime_dir(self) -> str:
  71. """:return: runtime directory tied to the user, e.g. ``~/Library/Caches/TemporaryItems/$appname/$version``"""
  72. return self._append_app_name_and_version(os.path.expanduser("~/Library/Caches/TemporaryItems")) # noqa: PTH111
  73. @property
  74. def site_runtime_dir(self) -> str:
  75. """:return: runtime directory shared by users, same as `user_runtime_dir`"""
  76. return self.user_runtime_dir
  77. __all__ = [
  78. "MacOS",
  79. ]