mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Prefer using `BuildEnvironment.note_dependency()
`
This commit is contained in:
parent
7801bd77b8
commit
c1172022ed
@ -467,7 +467,7 @@ class BuildEnvironment:
|
||||
for docname in self.found_docs:
|
||||
domain = docname_to_domain(docname, self.config.gettext_compact)
|
||||
if domain in mo_paths:
|
||||
self.dependencies[docname].add(str(mo_paths[domain]))
|
||||
self.note_dependency(mo_paths[domain], docname=docname)
|
||||
except OSError as exc:
|
||||
raise DocumentError(
|
||||
__('Failed to scan documents in %s: %r') % (self.srcdir, exc)
|
||||
@ -585,14 +585,18 @@ class BuildEnvironment:
|
||||
self.temp_data[key] = cur + 1
|
||||
return cur
|
||||
|
||||
def note_dependency(self, filename: str) -> None:
|
||||
def note_dependency(
|
||||
self, filename: str | os.PathLike[str], *, docname: str | None = None
|
||||
) -> None:
|
||||
"""Add *filename* as a dependency of the current document.
|
||||
|
||||
This means that the document will be rebuilt if this file changes.
|
||||
|
||||
*filename* should be absolute or relative to the source directory.
|
||||
"""
|
||||
self.dependencies[self.docname].add(filename)
|
||||
if docname is None:
|
||||
docname = self.docname
|
||||
self.dependencies[docname].add(os.fspath(filename))
|
||||
|
||||
def note_included(self, filename: str) -> None:
|
||||
"""Add *filename* as a included from other document.
|
||||
|
@ -89,7 +89,7 @@ class ImageCollector(EnvironmentCollector):
|
||||
# map image paths to unique image names (so that they can be put
|
||||
# into a single directory)
|
||||
for imgpath in candidates.values():
|
||||
app.env.dependencies[docname].add(imgpath)
|
||||
app.env.note_dependency(imgpath)
|
||||
if not os.access(os.path.join(app.srcdir, imgpath), os.R_OK):
|
||||
logger.warning(
|
||||
__('image file not readable: %s'),
|
||||
@ -154,7 +154,7 @@ class DownloadFileCollector(EnvironmentCollector):
|
||||
node['refuri'] = targetname
|
||||
else:
|
||||
rel_filename, filename = app.env.relfn2path(targetname, app.env.docname)
|
||||
app.env.dependencies[app.env.docname].add(rel_filename)
|
||||
app.env.note_dependency(rel_filename)
|
||||
if not os.access(filename, os.R_OK):
|
||||
logger.warning(
|
||||
__('download file not readable: %s'),
|
||||
|
@ -49,7 +49,7 @@ class DependenciesCollector(EnvironmentCollector):
|
||||
if isinstance(dep, bytes):
|
||||
dep = dep.decode(fs_encoding)
|
||||
relpath = relative_path(frompath, os.path.normpath(os.path.join(cwd, dep)))
|
||||
app.env.dependencies[app.env.docname].add(relpath)
|
||||
app.env.note_dependency(relpath)
|
||||
|
||||
|
||||
def setup(app: Sphinx) -> ExtensionMetadata:
|
||||
|
Loading…
Reference in New Issue
Block a user