cache_dependencies.py - fix tarfile deprecation warnings in 3.12-3.13

This commit is contained in:
Andrej730
2025-10-24 12:33:44 +05:00
parent de89ab31cf
commit 75135fe45d
+7 -1
View File
@@ -11,6 +11,7 @@ Usage: python cache_dependencies.py [pack|unpack]
import tarfile
import sys
from pathlib import Path
from typing import Literal
CACHE_PREFIX = "cache-"
@@ -38,9 +39,14 @@ def pack_dependencies(install_dir: Path) -> None:
def unpack_dependencies(install_dir: Path) -> None:
# `filter` argument was fully introduced in 3.12
# and results in deprecation warnings in 3.12-3.13, if not provided.
tar_filter: "dict[Literal['filter'], Literal['data']]" = (
{"filter": "data"} if bool(sys.version_info >= (3, 12)) else {}
)
for tar_path in install_dir.glob(f"{CACHE_PREFIX}*.tar.gz"):
with tarfile.open(tar_path, "r:gz") as tar:
tar.extractall(path=install_dir)
tar.extractall(path=install_dir, **tar_filter)
print(f"Extracted cache: '{tar_path.name}'.")