@@ -1689,6 +1689,22 @@ def html_page_context(app, pagename, templatename, context, doctree):
16891689 app .add_css_file ('nbsphinx-gallery.css' )
16901690
16911691
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+
16921708def html_collect_pages (app ):
16931709 """This event handler is abused to copy local files around."""
16941710 files = set ()
@@ -1699,7 +1715,10 @@ def html_collect_pages(app):
16991715 target = os .path .join (app .builder .outdir , file )
17001716 sphinx .util .ensuredir (os .path .dirname (target ))
17011717 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 ())
17031722 except OSError as err :
17041723 logger .warning (
17051724 'Cannot copy local file %r: %s' , file , err ,
@@ -1710,7 +1729,8 @@ def html_collect_pages(app):
17101729 'brown' , len (notebooks )):
17111730 sphinx .util .copyfile (
17121731 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 ())
17141734 return [] # No new HTML pages are created
17151735
17161736def env_updated (app , env ):
0 commit comments