codekingpro/portable-devtools
114k
1"""Application data stored by virtualenv."""2 3from __future__ import annotations4 5from abc import ABC, abstractmethod6from contextlib import contextmanager7 8from virtualenv.info import IS_ZIPAPP9 10 11class AppData(ABC):12 """Abstract storage interface for the virtualenv application."""13 14 @abstractmethod15 def close(self):16 """Called before virtualenv exits."""17 18 @abstractmethod19 def reset(self):20 """Called when the user passes in the reset app data."""21 22 @abstractmethod23 def py_info(self, path):24 raise NotImplementedError25 26 @abstractmethod27 def py_info_clear(self):28 raise NotImplementedError29 30 @property31 def can_update(self):32 raise NotImplementedError33 34 @abstractmethod35 def embed_update_log(self, distribution, for_py_version):36 raise NotImplementedError37 38 @property39 def house(self):40 raise NotImplementedError41 42 @property43 def transient(self):44 raise NotImplementedError45 46 @abstractmethod47 def wheel_image(self, for_py_version, name):48 raise NotImplementedError49 50 @contextmanager51 def ensure_extracted(self, path, to_folder=None):52 """Some paths might be within the zipapp, unzip these to a path on the disk."""53 if IS_ZIPAPP:54 with self.extract(path, to_folder) as result:55 yield result56 else:57 yield path58 59 @abstractmethod60 @contextmanager61 def extract(self, path, to_folder):62 raise NotImplementedError63 64 @abstractmethod65 @contextmanager66 def locked(self, path):67 raise NotImplementedError68 69 70class ContentStore(ABC):71 @abstractmethod72 def exists(self):73 raise NotImplementedError74 75 @abstractmethod76 def read(self):77 raise NotImplementedError78 79 @abstractmethod80 def write(self, content):81 raise NotImplementedError82 83 @abstractmethod84 def remove(self):85 raise NotImplementedError86 87 @abstractmethod88 @contextmanager89 def locked(self):90 pass91 92 93__all__ = [94 "AppData",95 "ContentStore",96]97 