Skip to content

Commit

Permalink
Use pathlib for copy_asset_file (#12908)
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner authored Sep 22, 2024
1 parent 45b7ebd commit de1379e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sphinx/util/fileutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import posixpath
from pathlib import Path
from typing import TYPE_CHECKING, Any

from docutils.utils import relative_path
Expand Down Expand Up @@ -53,11 +54,10 @@ def copy_asset_file(source: str | os.PathLike[str], destination: str | os.PathLi
if not os.path.exists(source):
return

if os.path.isdir(destination):
destination = Path(destination)
if destination.is_dir():
# Use source filename if destination points a directory
destination = os.path.join(destination, os.path.basename(source))
else:
destination = str(destination)
destination /= os.path.basename(source)

if _template_basename(source) and context is not None:
if renderer is None:
Expand All @@ -70,7 +70,7 @@ def copy_asset_file(source: str | os.PathLike[str], destination: str | os.PathLi

if (
not force
and os.path.exists(destination)
and destination.exists()
and template_content != rendered_template
):
msg = __('Aborted attempted copy from rendered template %s to %s '
Expand Down

0 comments on commit de1379e

Please sign in to comment.