Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change PyInfo cache versioning mechanism #2827

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/virtualenv/app_data/via_disk_folder.py
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ def extract(self, path, to_folder):

@property
def py_info_at(self):
return self.lock / "py_info" / "1"
return self.lock / "py_info" / "2"

def py_info(self, path):
return PyInfoStoreDisk(self.py_info_at, path)
11 changes: 2 additions & 9 deletions src/virtualenv/discovery/cached_py_info.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@
_CACHE = OrderedDict()
_CACHE[Path(sys.executable)] = PythonInfo()
LOGGER = logging.getLogger(__name__)
_CACHE_FILE_VERSION = 1


def from_exe(cls, app_data, exe, env=None, raise_on_error=True, ignore_cache=False): # noqa: FBT002, PLR0913
@@ -65,13 +64,8 @@ def _get_via_file_cache(cls, app_data, path, exe, env):
with py_info_store.locked():
if py_info_store.exists(): # if exists and matches load
data = py_info_store.read()
of_path, of_st_mtime, of_content, version = (
data["path"],
data["st_mtime"],
data["content"],
data.get("version"),
)
if of_path == path_text and of_st_mtime == path_modified and version == _CACHE_FILE_VERSION:
of_path, of_st_mtime, of_content = data["path"], data["st_mtime"], data["content"]
if of_path == path_text and of_st_mtime == path_modified:
py_info = cls._from_dict(of_content.copy())
sys_exe = py_info.system_executable
if sys_exe is not None and not os.path.exists(sys_exe):
@@ -86,7 +80,6 @@ def _get_via_file_cache(cls, app_data, path, exe, env):
"st_mtime": path_modified,
"path": path_text,
"content": py_info._to_dict(), # noqa: SLF001
"version": _CACHE_FILE_VERSION,
}
py_info_store.write(data)
else: