From b8fce6610d0c4d8dfb139f10ace376ceb4275d09 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Mon, 30 Sep 2024 13:25:39 -0600 Subject: [PATCH 1/2] replace distutils (deprecated in python 3.12) --- CIME/utils.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/CIME/utils.py b/CIME/utils.py index e84d614b12b..1e280aa775f 100644 --- a/CIME/utils.py +++ b/CIME/utils.py @@ -12,9 +12,6 @@ from argparse import Action from contextlib import contextmanager -# pylint: disable=deprecated-module -from distutils import file_util - # Return this error code if the scripts worked but tests failed TESTS_FAILED_ERR_CODE = 100 logger = logging.getLogger(__name__) @@ -1412,12 +1409,9 @@ def safe_copy(src_path, tgt_path, preserve_meta=True): if owner_uid == os.getuid(): # I am the owner, copy file contents, permissions, and metadata - file_util.copy_file( + shutil.copy2( src_path, tgt_path, - preserve_mode=preserve_meta, - preserve_times=preserve_meta, - verbose=0, ) else: # I am not the owner, just copy file contents @@ -1426,12 +1420,9 @@ def safe_copy(src_path, tgt_path, preserve_meta=True): else: # We are making a new file, copy file contents, permissions, and metadata. # This can fail if the underlying directory is not writable by current user. - file_util.copy_file( + shutil.copy2( src_path, tgt_path, - preserve_mode=preserve_meta, - preserve_times=preserve_meta, - verbose=0, ) # If src file was executable, then the tgt file should be too From cf996bf00dc344c0254f54735b065414d240d7fd Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Mon, 30 Sep 2024 13:30:14 -0600 Subject: [PATCH 2/2] replace distutils (deprecated in python 3.12) --- CIME/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CIME/utils.py b/CIME/utils.py index 1e280aa775f..59cbf3c7666 100644 --- a/CIME/utils.py +++ b/CIME/utils.py @@ -1417,13 +1417,18 @@ def safe_copy(src_path, tgt_path, preserve_meta=True): # I am not the owner, just copy file contents shutil.copyfile(src_path, tgt_path) - else: + elif preserve_meta: # We are making a new file, copy file contents, permissions, and metadata. # This can fail if the underlying directory is not writable by current user. shutil.copy2( src_path, tgt_path, ) + else: + shutil.copy( + src_path, + tgt_path, + ) # If src file was executable, then the tgt file should be too st = os.stat(tgt_path)