Skip to content

Commit 3c80fef

Browse files
committed
always use own implementation rather than just using shutil.copytree in Python 3.8+
1 parent e086444 commit 3c80fef

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

easybuild/tools/filetools.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,8 +1966,7 @@ def copy_dir(path, target_path, force_in_dry_run=False, dirs_exist_ok=False, **k
19661966
:param force_in_dry_run: force running the command during dry run
19671967
:param dirs_exist_ok: boolean indicating whether it's OK if the target directory already exists
19681968
1969-
On Python >= 3.8 shutil.copytree is always used.
1970-
On Python < 3.8, shutil.copytree is used if the target path does not exist yet;
1969+
shutil.copytree is used if the target path does not exist yet;
19711970
if the target path already exists, the 'copy' function will be used to copy the contents of
19721971
the source path to the target path
19731972
@@ -1980,11 +1979,10 @@ def copy_dir(path, target_path, force_in_dry_run=False, dirs_exist_ok=False, **k
19801979
if not dirs_exist_ok and os.path.exists(target_path):
19811980
raise EasyBuildError("Target location %s to copy %s to already exists", target_path, path)
19821981

1983-
if sys.version_info >= (3, 8):
1984-
# on Python >= 3.8, shutil.copytree works fine, thanks to availability of dirs_exist_ok named argument
1985-
shutil.copytree(path, target_path, dirs_exist_ok=dirs_exist_ok, **kwargs)
1986-
1987-
elif dirs_exist_ok and os.path.exists(target_path):
1982+
# note: in Python >= 3.8 shutil.copytree works just fine thanks to the 'dirs_exist_ok' argument,
1983+
# but since we need to be more careful in earlier Python versions we use our own implementation
1984+
# in case the target directory exists and 'dirs_exist_ok' is enabled
1985+
if dirs_exist_ok and os.path.exists(target_path):
19881986
# if target directory already exists (and that's allowed via dirs_exist_ok),
19891987
# we need to be more careful, since shutil.copytree will fail (in Python < 3.8)
19901988
# if target directory already exists;

0 commit comments

Comments
 (0)