diff --git a/tools/idf_tools.py b/tools/idf_tools.py index b3c4c9a962..ed2bc5ef82 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -469,10 +469,7 @@ def get_env_for_extra_paths(extra_paths: 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 @@ -526,11 +523,14 @@ def unpack(filename: str, destination: 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): @@ -3229,15 +3229,6 @@ def main(argv: List[str]) -> None: # See https://bugs.python.org/issue22490#msg283859. 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: fatal(f'Platform {PYTHON_PLATFORM} appears to be unsupported') raise SystemExit(1)