From 0d31674eb2344bd0421a41a8eb25369a9be95012 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Mon, 7 Jul 2025 12:45:33 -0500 Subject: [PATCH] auxiliary: use shutil instead of distutils for recursiveCopy distutils does not exist in Pythons >= 3.12, so the program does not work since the import fails. Instead, when possible, use shutil to provide a tree copy function. The relevant difference between the two implementations is that distutils' version does not raise an error if the destination directory exists. Unfortunately, the flag to match this behavior, only exists in shutil's implementation on Pythons >= 3.8. Therefore, we fall back on distutils to preserve compatibility with these EOL versions. Tested that elf_diff now starts and works on Python 3.12 using the `html_dir` exporter. --- src/elf_diff/auxiliary.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/elf_diff/auxiliary.py b/src/elf_diff/auxiliary.py index e7811ccc..c5c30669 100644 --- a/src/elf_diff/auxiliary.py +++ b/src/elf_diff/auxiliary.py @@ -21,9 +21,24 @@ import inspect import os import re -from distutils import dir_util from typing import List, Set +import sys + +if sys.version_info >= (3, 8): + import shutil + + def _do_copy(source_dir: str, target_dir: str) -> None: + # don't have dirs_exist_ok before 3.8 + shutil.copytree(source_dir, target_dir, dirs_exist_ok=True) + +else: + # don't have distutils after 3.11 + from distutils import dir_util + + def _do_copy(source_dir: str, target_dir: str) -> None: + dir_util.copy_tree(source_dir, target_dir) + def setIntersection(l1: Set, l2: Set) -> List: """Return a list that is a sorted set intersection of two sets""" @@ -62,7 +77,7 @@ def getRelpath(html_output_file: str, target_dir: str) -> str: def recursiveCopy(source_dir: str, target_dir: str) -> None: """Copy the content of a source directory recursively (including subdirectories) to a target directory""" - dir_util.copy_tree(source_dir, target_dir) + _do_copy(source_dir, target_dir) def isNameToken(str_: str) -> bool: