Merge branch 'fix/extractall_deprecation_v5.2' into 'release/v5.2'

fix(idf_tools): Patch extractall() deprecation warning (v5.2)

See merge request espressif/esp-idf!37885
This commit is contained in:
Roland Dobai
2025-03-21 02:02:02 +08:00

View File

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