Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use force=True with copyfile #819

Merged
merged 5 commits into from
Nov 10, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/nbsphinx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,11 @@ def html_page_context(app, pagename, templatename, context, doctree):

def html_collect_pages(app):
"""This event handler is abused to copy local files around."""
# From version 8 of Sphinx, we need to pass force=True to the copyfile
# function but not to older version of the same function.
from inspect import signature
use_force = bool(
signature(sphinx.util.copyfile).parameters.get('force'))
mgeier marked this conversation as resolved.
Show resolved Hide resolved
files = set()
for file_list in app.env.nbsphinx_files.values():
files.update(file_list)
Expand All @@ -1699,7 +1704,11 @@ def html_collect_pages(app):
target = os.path.join(app.builder.outdir, file)
sphinx.util.ensuredir(os.path.dirname(target))
try:
sphinx.util.copyfile(os.path.join(app.env.srcdir, file), target)
kwargs = {"force": True} if use_force else {}
mgeier marked this conversation as resolved.
Show resolved Hide resolved
sphinx.util.copyfile(
os.path.join(app.env.srcdir, file),
target,
**kwargs)
except OSError as err:
logger.warning(
'Cannot copy local file %r: %s', file, err,
Expand All @@ -1708,9 +1717,11 @@ def html_collect_pages(app):
for notebook in status_iterator(
notebooks, 'copying notebooks ... ',
'brown', len(notebooks)):
kwargs = {"force": True} if use_force else {}
sphinx.util.copyfile(
os.path.join(app.env.nbsphinx_auxdir, notebook),
os.path.join(app.builder.outdir, notebook))
os.path.join(app.builder.outdir, notebook),
**kwargs)
return [] # No new HTML pages are created

def env_updated(app, env):
Expand Down
Loading