Skip to content

Commit

Permalink
Unconditionally copy static assets in Builder (#13236)
Browse files Browse the repository at this point in the history
Remove an early exit check for when ``docnames`` is empty.
Previously,  when building in incremental mode, static assets
(for example from HTML themes) would only be copied
when at least one document had been modified.
  • Loading branch information
AA-Turner authored Jan 14, 2025
1 parent b064ef3 commit 501b825
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Bugs fixed
Patch by Ben Egan and Adam Turner.
* #13188: autodoc: fix detection of class methods implemented in C.
Patch by Bénédikt Tran.
* #1810: Always copy static files when building, regardless of whether
any documents have changed since the previous build.
Patch by Adam Turner.

Testing
-------
Expand Down
38 changes: 22 additions & 16 deletions sphinx/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ def build_specific(self, filenames: list[str]) -> None:

self.build(
docnames,
method='specific',
summary=__('%d source files given on command line') % len(docnames),
method='specific',
)

@final
Expand All @@ -366,13 +366,14 @@ def build_update(self) -> None:

to_build = self.get_outdated_docs()
if isinstance(to_build, str):
self.build(['__all__'], to_build)
self.build(['__all__'], summary=to_build, method='update')
else:
to_build = list(to_build)
to_build = set(to_build)
self.build(
to_build,
summary=__('targets for %d source files that are out of date')
% len(to_build),
method='update',
)

@final
Expand Down Expand Up @@ -424,7 +425,6 @@ def build(
else:
if method == 'update' and not docnames:
logger.info(bold(__('no targets are out of date.')))
return

self.app.phase = BuildPhase.RESOLVING

Expand All @@ -448,7 +448,7 @@ def build(
self.finish_tasks = SerialTasks()

# write all "normal" documents (or everything for some builders)
self.write(docnames, list(updated_docnames), method)
self.write(docnames, updated_docnames, method)

# finish (write static files etc.)
self.finish()
Expand Down Expand Up @@ -689,41 +689,47 @@ def write_doctree(
def write(
self,
build_docnames: Iterable[str] | None,
updated_docnames: Sequence[str],
updated_docnames: Iterable[str],
method: Literal['all', 'specific', 'update'] = 'update',
) -> None:
"""Write builder specific output files."""
env = self.env

# Allow any extensions to perform setup for writing
self.events.emit('write-started', self)

if build_docnames is None or build_docnames == ['__all__']:
# build_all
build_docnames = self.env.found_docs
build_docnames = env.found_docs
if method == 'update':
# build updated ones as well
docnames = set(build_docnames) | set(updated_docnames)
else:
docnames = set(build_docnames)
logger.debug(__('docnames to write: %s'), ', '.join(sorted(docnames)))
if docnames:
logger.debug(__('docnames to write: %s'), ', '.join(sorted(docnames)))
else:
logger.debug(__('no docnames to write!'))

# add all toctree-containing files that may have changed
extra = {self.config.root_doc}
for docname in docnames:
for tocdocname in self.env.files_to_rebuild.get(docname, set()):
if tocdocname in self.env.found_docs:
extra.add(tocdocname)
docnames |= extra
docnames |= {
toc_docname
for docname in docnames
for toc_docname in env.files_to_rebuild.get(docname, ())
if toc_docname in env.found_docs
}

# sort to ensure deterministic toctree generation
self.env.toctree_includes = dict(sorted(self.env.toctree_includes.items()))
env.toctree_includes = dict(sorted(env.toctree_includes.items()))

with progress_message(__('preparing documents')):
self.prepare_writing(docnames)

with progress_message(__('copying assets'), nonl=False):
self.copy_assets()

self.write_documents(docnames)
if docnames:
self.write_documents(docnames)

def write_documents(self, docnames: Set[str]) -> None:
"""Write all documents in *docnames*.
Expand Down

0 comments on commit 501b825

Please sign in to comment.