na.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from __future__ import annotations
  2. from contextlib import contextmanager
  3. from typing import TYPE_CHECKING
  4. from .base import AppData, ContentStore
  5. if TYPE_CHECKING:
  6. from collections.abc import Generator
  7. from pathlib import Path
  8. from typing import Any, NoReturn
  9. class AppDataDisabled(AppData):
  10. """No application cache available (most likely as we don't have write permissions)."""
  11. transient = True
  12. can_update = False
  13. def __init__(self) -> None:
  14. pass
  15. error = RuntimeError("no app data folder available, probably no write access to the folder")
  16. def close(self) -> None:
  17. """Do nothing."""
  18. def reset(self) -> None:
  19. """Do nothing."""
  20. def py_info(self, path: Path) -> ContentStoreNA: # noqa: ARG002
  21. return ContentStoreNA()
  22. def embed_update_log(self, distribution: str, for_py_version: str) -> ContentStoreNA: # noqa: ARG002
  23. return ContentStoreNA()
  24. def extract(self, path: Path, to_folder: Path | None) -> NoReturn: # noqa: ARG002
  25. raise self.error
  26. @contextmanager
  27. def locked(self, path: Path) -> Generator[None]: # noqa: ARG002
  28. """Do nothing."""
  29. yield
  30. @property
  31. def house(self) -> NoReturn:
  32. raise self.error
  33. def wheel_image(self, for_py_version: str, name: str) -> NoReturn: # noqa: ARG002
  34. raise self.error
  35. def py_info_clear(self) -> None:
  36. """Nothing to clear."""
  37. class ContentStoreNA(ContentStore):
  38. def exists(self) -> bool:
  39. return False
  40. def read(self) -> None:
  41. """Nothing to read."""
  42. return
  43. def write(self, content: Any) -> None: # noqa: ANN401
  44. """Nothing to write."""
  45. def remove(self) -> None:
  46. """Nothing to remove."""
  47. @contextmanager
  48. def locked(self) -> Generator[None]:
  49. yield
  50. __all__ = [
  51. "AppDataDisabled",
  52. "ContentStoreNA",
  53. ]