base.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. """Application data stored by virtualenv."""
  2. from __future__ import annotations
  3. from abc import ABC, abstractmethod
  4. from contextlib import contextmanager
  5. from virtualenv.info import IS_ZIPAPP
  6. class AppData(ABC):
  7. """Abstract storage interface for the virtualenv application."""
  8. @abstractmethod
  9. def close(self):
  10. """Called before virtualenv exits."""
  11. @abstractmethod
  12. def reset(self):
  13. """Called when the user passes in the reset app data."""
  14. @abstractmethod
  15. def py_info(self, path):
  16. raise NotImplementedError
  17. @abstractmethod
  18. def py_info_clear(self):
  19. raise NotImplementedError
  20. @property
  21. def can_update(self):
  22. raise NotImplementedError
  23. @abstractmethod
  24. def embed_update_log(self, distribution, for_py_version):
  25. raise NotImplementedError
  26. @property
  27. def house(self):
  28. raise NotImplementedError
  29. @property
  30. def transient(self):
  31. raise NotImplementedError
  32. @abstractmethod
  33. def wheel_image(self, for_py_version, name):
  34. raise NotImplementedError
  35. @contextmanager
  36. def ensure_extracted(self, path, to_folder=None):
  37. """Some paths might be within the zipapp, unzip these to a path on the disk."""
  38. if IS_ZIPAPP:
  39. with self.extract(path, to_folder) as result:
  40. yield result
  41. else:
  42. yield path
  43. @abstractmethod
  44. @contextmanager
  45. def extract(self, path, to_folder):
  46. raise NotImplementedError
  47. @abstractmethod
  48. @contextmanager
  49. def locked(self, path):
  50. raise NotImplementedError
  51. class ContentStore(ABC):
  52. @abstractmethod
  53. def exists(self):
  54. raise NotImplementedError
  55. @abstractmethod
  56. def read(self):
  57. raise NotImplementedError
  58. @abstractmethod
  59. def write(self, content):
  60. raise NotImplementedError
  61. @abstractmethod
  62. def remove(self):
  63. raise NotImplementedError
  64. @abstractmethod
  65. @contextmanager
  66. def locked(self):
  67. pass
  68. __all__ = [
  69. "AppData",
  70. "ContentStore",
  71. ]