Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions sphinx/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ def __init__(
:param pdb: If true, enable the Python debugger on an exception.
:param exception_on_warning: If true, raise an exception on warnings.
"""
self.phase = BuildPhase.INITIALIZATION
self.verbosity = verbosity
self._fresh_env_used: bool | None = None
self.extensions: dict[str, Extension] = {}
Expand Down Expand Up @@ -340,6 +339,12 @@ def fresh_env_used(self) -> bool | None:
"""
return self._fresh_env_used

@property
def phase(self) -> BuildPhase:
if not hasattr(self, 'builder'):
return BuildPhase.INITIALIZATION
return self.builder.phase

def _init_i18n(self) -> None:
"""Load translated strings from the configured localedirs if enabled in
the configuration.
Expand Down Expand Up @@ -420,7 +425,7 @@ def _init_builder(self) -> None:
# ---- main "build" method -------------------------------------------------

def build(self, force_all: bool = False, filenames: Sequence[Path] = ()) -> None:
self.phase = BuildPhase.READING
self.builder.phase = BuildPhase.READING
try:
if force_all:
self.builder.build_all()
Expand Down
23 changes: 10 additions & 13 deletions sphinx/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class Builder:
#: The file format produced by the builder allows images to be embedded using data-URIs.
supported_data_uri_images: ClassVar[bool] = False

phase: BuildPhase = BuildPhase.INITIALIZATION

srcdir = _StrPathProperty()
confdir = _StrPathProperty()
outdir = _StrPathProperty()
Expand Down Expand Up @@ -431,14 +433,14 @@ def build(
pickle.dump(self.env, f, pickle.HIGHEST_PROTOCOL)

# global actions
self._app.phase = BuildPhase.CONSISTENCY_CHECK
self.phase = BuildPhase.CONSISTENCY_CHECK
with progress_message(__('checking consistency')):
self.env.check_consistency()
else:
if method == 'update' and not docnames:
logger.info(bold(__('no targets are out of date.')))

self._app.phase = BuildPhase.RESOLVING
self.phase = BuildPhase.RESOLVING

# filter "docnames" (list of outdated files) by the updated
# found_docs of the environment; this will remove docs that
Expand Down Expand Up @@ -776,21 +778,17 @@ def _write_serial(self, docnames: Sequence[str]) -> None:
len(docnames),
self._app.verbosity,
):
_write_docname(
docname, app=self._app, env=self.env, builder=self, tags=self.tags
)
_write_docname(docname, env=self.env, builder=self, tags=self.tags)

def _write_parallel(self, docnames: Sequence[str], nproc: int) -> None:
def write_process(docs: list[tuple[str, nodes.document]]) -> None:
self._app.phase = BuildPhase.WRITING
self.phase = BuildPhase.WRITING
for docname, doctree in docs:
self.write_doc(docname, doctree)

# warm up caches/compile templates using the first document
firstname, docnames = docnames[0], docnames[1:]
_write_docname(
firstname, app=self._app, env=self.env, builder=self, tags=self.tags
)
_write_docname(firstname, env=self.env, builder=self, tags=self.tags)

tasks = ParallelTasks(nproc)
chunks = make_chunks(docnames, nproc)
Expand All @@ -808,7 +806,7 @@ def write_process(docs: list[tuple[str, nodes.document]]) -> None:
def on_chunk_done(args: list[tuple[str, nodes.document]], result: None) -> None:
next(progress)

self._app.phase = BuildPhase.RESOLVING
self.phase = BuildPhase.RESOLVING
for chunk in chunks:
arg = []
for docname in chunk:
Expand Down Expand Up @@ -884,15 +882,14 @@ def _write_docname(
docname: str,
/,
*,
app: Sphinx,
env: BuildEnvironment,
builder: Builder,
tags: Tags,
) -> None:
"""Write a single document."""
app.phase = BuildPhase.RESOLVING
builder.phase = BuildPhase.RESOLVING
doctree = env.get_and_resolve_doctree(docname, builder=builder, tags=tags)
app.phase = BuildPhase.WRITING
builder.phase = BuildPhase.WRITING
builder.write_doc_serialized(docname, doctree)
builder.write_doc(docname, doctree)

Expand Down
Loading