@@ -1689,6 +1689,22 @@ def html_page_context(app, pagename, templatename, context, doctree):
1689
1689
app .add_css_file ('nbsphinx-gallery.css' )
1690
1690
1691
1691
1692
+ def backwards_compat_overwrite (copyfile = sphinx .util .copyfile ):
1693
+ """Return kwargs dictionary to pass to copyfile() for consistent behavior
1694
+
1695
+ Before version 8 of Sphinx, the default behavior of the copyfile function
1696
+ was to overwrite the file at the target path if it already existed.
1697
+ Version 8 requires passing force=True.
1698
+
1699
+ Ref: https://github.com/sphinx-doc/sphinx/pull/12647
1700
+ """
1701
+ from inspect import signature
1702
+ if "force" in signature (copyfile ).parameters :
1703
+ return {"force" : True }
1704
+ else :
1705
+ return {}
1706
+
1707
+
1692
1708
def html_collect_pages (app ):
1693
1709
"""This event handler is abused to copy local files around."""
1694
1710
files = set ()
@@ -1699,7 +1715,10 @@ def html_collect_pages(app):
1699
1715
target = os .path .join (app .builder .outdir , file )
1700
1716
sphinx .util .ensuredir (os .path .dirname (target ))
1701
1717
try :
1702
- sphinx .util .copyfile (os .path .join (app .env .srcdir , file ), target )
1718
+ sphinx .util .copyfile (
1719
+ os .path .join (app .env .srcdir , file ),
1720
+ target ,
1721
+ ** backwards_compat_overwrite ())
1703
1722
except OSError as err :
1704
1723
logger .warning (
1705
1724
'Cannot copy local file %r: %s' , file , err ,
@@ -1710,7 +1729,8 @@ def html_collect_pages(app):
1710
1729
'brown' , len (notebooks )):
1711
1730
sphinx .util .copyfile (
1712
1731
os .path .join (app .env .nbsphinx_auxdir , notebook ),
1713
- os .path .join (app .builder .outdir , notebook ))
1732
+ os .path .join (app .builder .outdir , notebook ),
1733
+ ** backwards_compat_overwrite ())
1714
1734
return [] # No new HTML pages are created
1715
1735
1716
1736
def env_updated (app , env ):
0 commit comments