macos.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from __future__ import annotations
  2. import os
  3. from .api import PlatformDirsABC
  4. class MacOS(PlatformDirsABC):
  5. """
  6. Platform directories for the macOS operating system. Follows the guidance from `Apple documentation
  7. <https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html>`_.
  8. Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>` and
  9. `version <platformdirs.api.PlatformDirsABC.version>`.
  10. """
  11. @property
  12. def user_data_dir(self) -> str:
  13. """:return: data directory tied to the user, e.g. ``~/Library/Application Support/$appname/$version``"""
  14. return self._append_app_name_and_version(os.path.expanduser("~/Library/Application Support/"))
  15. @property
  16. def site_data_dir(self) -> str:
  17. """:return: data directory shared by users, e.g. ``/Library/Application Support/$appname/$version``"""
  18. return self._append_app_name_and_version("/Library/Application Support")
  19. @property
  20. def user_config_dir(self) -> str:
  21. """:return: config directory tied to the user, e.g. ``~/Library/Preferences/$appname/$version``"""
  22. return self._append_app_name_and_version(os.path.expanduser("~/Library/Preferences/"))
  23. @property
  24. def site_config_dir(self) -> str:
  25. """:return: config directory shared by the users, e.g. ``/Library/Preferences/$appname``"""
  26. return self._append_app_name_and_version("/Library/Preferences")
  27. @property
  28. def user_cache_dir(self) -> str:
  29. """:return: cache directory tied to the user, e.g. ``~/Library/Caches/$appname/$version``"""
  30. return self._append_app_name_and_version(os.path.expanduser("~/Library/Caches"))
  31. @property
  32. def user_state_dir(self) -> str:
  33. """:return: state directory tied to the user, same as `user_data_dir`"""
  34. return self.user_data_dir
  35. @property
  36. def user_log_dir(self) -> str:
  37. """:return: log directory tied to the user, e.g. ``~/Library/Logs/$appname/$version``"""
  38. return self._append_app_name_and_version(os.path.expanduser("~/Library/Logs"))
  39. @property
  40. def user_documents_dir(self) -> str:
  41. """:return: documents directory tied to the user, e.g. ``~/Documents``"""
  42. return os.path.expanduser("~/Documents")
  43. @property
  44. def user_runtime_dir(self) -> str:
  45. """:return: runtime directory tied to the user, e.g. ``~/Library/Caches/TemporaryItems/$appname/$version``"""
  46. return self._append_app_name_and_version(os.path.expanduser("~/Library/Caches/TemporaryItems"))
  47. __all__ = [
  48. "MacOS",
  49. ]