From 75cfb56b380960c9be5ced2adc6aa8fd7a61d09e Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Sat, 1 Mar 2025 16:08:14 -0600 Subject: [PATCH] Remove dependency on distutils Align with devlib and remove dependencies on distutils. [1] https://github.com/ARM-software/devlib/pull/631/ --- wa/commands/create.py | 19 ++++++++++++++++++- wa/utils/misc.py | 6 +++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/wa/commands/create.py b/wa/commands/create.py index 28935615..85b4c6cc 100644 --- a/wa/commands/create.py +++ b/wa/commands/create.py @@ -23,7 +23,6 @@ import re import uuid import getpass from collections import OrderedDict -from distutils.dir_util import copy_tree # pylint: disable=no-name-in-module, import-error from devlib.utils.types import identifier try: @@ -43,6 +42,24 @@ from wa.utils.misc import (ensure_directory_exists as _d, capitalize, from wa.utils.postgres import get_schema, POSTGRES_SCHEMA_DIR from wa.utils.serializer import yaml +if sys.version_info >= (3, 8): + def copy_tree(src, dst): + from shutil import copy, copytree # pylint: disable=import-outside-toplevel + copytree( + src, + dst, + # dirs_exist_ok=True only exists in Python >= 3.8 + dirs_exist_ok=True, + # Align with devlib and only copy the content without metadata + copy_function=copy + ) +else: + def copy_tree(src, dst): + # pylint: disable=import-outside-toplevel, redefined-outer-name + from distutils.dir_util import copy_tree + # Align with devlib and only copy the content without metadata + copy_tree(src, dst, preserve_mode=False, preserve_times=False) + TEMPLATES_DIR = os.path.join(os.path.dirname(__file__), 'templates') diff --git a/wa/utils/misc.py b/wa/utils/misc.py index 079b4847..75cc3b89 100644 --- a/wa/utils/misc.py +++ b/wa/utils/misc.py @@ -44,7 +44,11 @@ from time import sleep from io import StringIO # pylint: disable=wrong-import-position,unused-import from itertools import chain, cycle -from distutils.spawn import find_executable # pylint: disable=no-name-in-module, import-error + +try: + from shutil import which as find_executable +except ImportError: + from distutils.spawn import find_executable # pylint: disable=no-name-in-module, import-error from dateutil import tz