fix(idf_tools): Patch extractall() deprecation warning

This commit is contained in:
Radim Karniš
2025-03-18 13:18:56 +01:00
parent 8bb65e6d85
commit 61f3968e91

View File

@ -469,10 +469,7 @@ def get_env_for_extra_paths(extra_paths: List[str]) -> Dict[str, str]:
""" """
env_arg = os.environ.copy() env_arg = os.environ.copy()
new_path = os.pathsep.join(extra_paths) + os.pathsep + env_arg['PATH'] new_path = os.pathsep.join(extra_paths) + os.pathsep + env_arg['PATH']
if sys.version_info.major == 2: env_arg['PATH'] = new_path
env_arg['PATH'] = new_path.encode('utf8') # type: ignore
else:
env_arg['PATH'] = new_path
return env_arg return env_arg
@ -526,11 +523,14 @@ def unpack(filename: str, destination: str) -> None:
archive_obj = ZipFile(filename) archive_obj = ZipFile(filename)
else: else:
raise NotImplementedError('Unsupported archive type') raise NotImplementedError('Unsupported archive type')
if sys.version_info.major == 2:
# This is a workaround for the issue that unicode destination is not handled: # Handle tar/zip extraction with backward compatibility
# https://bugs.python.org/issue17153 if isinstance(archive_obj, tarfile.TarFile) and sys.version_info[:2] >= (3, 12):
destination = str(destination) # Use the tar filter argument for Python 3.12 and later
archive_obj.extractall(destination) archive_obj.extractall(destination, filter='tar')
else:
archive_obj.extractall(destination)
# ZipFile on Unix systems does not preserve file permissions while extracting it # ZipFile on Unix systems does not preserve file permissions while extracting it
# We need to reset the permissions afterward # We need to reset the permissions afterward
if sys.platform != 'win32' and filename.endswith('zip') and isinstance(archive_obj, ZipFile): if sys.platform != 'win32' and filename.endswith('zip') and isinstance(archive_obj, ZipFile):
@ -3213,15 +3213,6 @@ def main(argv: List[str]) -> None:
# See https://bugs.python.org/issue22490#msg283859. # See https://bugs.python.org/issue22490#msg283859.
os.environ.pop('__PYVENV_LAUNCHER__', None) os.environ.pop('__PYVENV_LAUNCHER__', None)
if sys.version_info.major == 2:
try:
g.idf_tools_path.decode('ascii') # type: ignore
except UnicodeDecodeError:
fatal(f'IDF_TOOLS_PATH contains non-ASCII characters: {g.idf_tools_path}'
'\nThis is not supported yet with Python 2. '
'Please set IDF_TOOLS_PATH to a directory with an ASCII name, or switch to Python 3.')
raise SystemExit(1)
if CURRENT_PLATFORM is None: if CURRENT_PLATFORM is None:
fatal(f'Platform {PYTHON_PLATFORM} appears to be unsupported') fatal(f'Platform {PYTHON_PLATFORM} appears to be unsupported')
raise SystemExit(1) raise SystemExit(1)