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

Allow extensions to detect freshenv builds #12358

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 28 additions & 1 deletion sphinx/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,29 @@ def __init__(self, srcdir: str | os.PathLike[str], confdir: str | os.PathLike[st
tags: list[str] | None = None,
verbosity: int = 0, parallel: int = 0, keep_going: bool = False,
pdb: bool = False) -> None:
"""Initialize the Sphinx application.

:param srcdir: The path to the source directory.
:param confdir: The path to the configuration directory.
If not given, it is assumed to be the same as ``srcdir``.
:param outdir: Directory for storing build documents.
:param doctreedir: Directory for caching pickled doctrees.
:param buildername: The name of the builder to use.
:param confoverrides: A dictionary of configuration settings that override the
settings in the configuration file.
:param status: A file-like object to write status messages to.
:param warning: A file-like object to write warnings to.
:param freshenv: If true, clear the cached environment.
:param warningiserror: If true, warnings become errors.
:param tags: A list of tags to apply.
:param verbosity: The verbosity level.
:param parallel: The number of parallel jobs to use.
picnixz marked this conversation as resolved.
Show resolved Hide resolved
chrisjsewell marked this conversation as resolved.
Show resolved Hide resolved
:param keep_going: If true, continue processing when an error occurs.
:param pdb: If true, enable the Python debugger on an exception.
"""
self.phase = BuildPhase.INITIALIZATION
self.verbosity = verbosity
self._fresh_env_used: bool | None = None
self.extensions: dict[str, Extension] = {}
self.registry = SphinxComponentRegistry()

Expand Down Expand Up @@ -267,6 +288,13 @@ def __init__(self, srcdir: str | os.PathLike[str], confdir: str | os.PathLike[st
# set up the builder
self._init_builder()

@property
def fresh_env_used(self) -> bool | None:
"""True/False as to whether a new environment was created for this build,
or None if the environment has not been initialised yet.
"""
return self._fresh_env_used

def _init_i18n(self) -> None:
"""Load translated strings from the configured localedirs if enabled in
the configuration.
Expand Down Expand Up @@ -322,7 +350,6 @@ def _load_existing_env(self, filename: str) -> BuildEnvironment:
def _post_init_env(self) -> None:
if self._fresh_env_used:
self.env.find_files(self.config, self.builder)
del self._fresh_env_used

def preload_builder(self, name: str) -> None:
self.registry.preload_builder(self, name)
Expand Down