From c1ed1e3b70609cceaea8557453a12224bea64b77 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Mon, 29 Jul 2024 18:37:14 +0100 Subject: [PATCH] Use ``Path`` objects within ``copyfile`` (#12708) --- sphinx/util/osutil.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index 6c61390f1e8..d5d6ab5bc3f 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -11,12 +11,12 @@ import unicodedata from io import StringIO from os import path +from pathlib import Path from typing import TYPE_CHECKING from sphinx.locale import __ if TYPE_CHECKING: - from pathlib import Path from types import TracebackType from typing import Any @@ -107,12 +107,15 @@ def copyfile( .. note:: :func:`copyfile` is a no-op if *source* and *dest* are identical. """ - if not path.exists(source): - msg = f'{os.fsdecode(source)} does not exist' + # coerce to Path objects + source = Path(source) + dest = Path(dest) + if not source.exists(): + msg = f'{source} does not exist' raise FileNotFoundError(msg) if ( - not (dest_exists := path.exists(dest)) or + not (dest_exists := dest.exists()) or # comparison must be done using shallow=False since # two different files might have the same size not filecmp.cmp(source, dest, shallow=False) @@ -125,7 +128,7 @@ def copyfile( msg = __('Aborted attempted copy from %s to %s ' '(the destination path has existing data).') - logger.warning(msg, os.fsdecode(source), os.fsdecode(dest), + logger.warning(msg, source, dest, type='misc', subtype='copy_overwrite') return