mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Improve typing for `_ConfigRebuild
`
This commit is contained in:
parent
bcb1825679
commit
85400a0430
@ -168,7 +168,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
|||||||
self.refnodes: list[dict[str, Any]] = []
|
self.refnodes: list[dict[str, Any]] = []
|
||||||
|
|
||||||
def create_build_info(self) -> BuildInfo:
|
def create_build_info(self) -> BuildInfo:
|
||||||
return BuildInfo(self.config, self.tags, ['html', 'epub'])
|
return BuildInfo(self.config, self.tags, frozenset({'html', 'epub'}))
|
||||||
|
|
||||||
def get_theme_config(self) -> tuple[str, dict]:
|
def get_theme_config(self) -> tuple[str, dict]:
|
||||||
return self.config.epub_theme, self.config.epub_theme_options
|
return self.config.epub_theme, self.config.epub_theme_options
|
||||||
|
@ -50,11 +50,12 @@ from sphinx.writers.html import HTMLWriter
|
|||||||
from sphinx.writers.html5 import HTML5Translator
|
from sphinx.writers.html5 import HTML5Translator
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Iterable, Iterator, Sequence
|
from collections.abc import Iterable, Iterator, Set
|
||||||
|
|
||||||
from docutils.nodes import Node
|
from docutils.nodes import Node
|
||||||
|
|
||||||
from sphinx.application import Sphinx
|
from sphinx.application import Sphinx
|
||||||
|
from sphinx.config import _ConfigRebuild
|
||||||
from sphinx.environment import BuildEnvironment
|
from sphinx.environment import BuildEnvironment
|
||||||
from sphinx.util.tags import Tags
|
from sphinx.util.tags import Tags
|
||||||
|
|
||||||
@ -130,7 +131,7 @@ class BuildInfo:
|
|||||||
self,
|
self,
|
||||||
config: Config | None = None,
|
config: Config | None = None,
|
||||||
tags: Tags | None = None,
|
tags: Tags | None = None,
|
||||||
config_categories: Sequence[str] = (),
|
config_categories: Set[_ConfigRebuild] = frozenset(),
|
||||||
) -> None:
|
) -> None:
|
||||||
self.config_hash = ''
|
self.config_hash = ''
|
||||||
self.tags_hash = ''
|
self.tags_hash = ''
|
||||||
@ -239,7 +240,7 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
self.use_index = self.get_builder_config('use_index', 'html')
|
self.use_index = self.get_builder_config('use_index', 'html')
|
||||||
|
|
||||||
def create_build_info(self) -> BuildInfo:
|
def create_build_info(self) -> BuildInfo:
|
||||||
return BuildInfo(self.config, self.tags, ['html'])
|
return BuildInfo(self.config, self.tags, frozenset({'html'}))
|
||||||
|
|
||||||
def _get_translations_js(self) -> str:
|
def _get_translations_js(self) -> str:
|
||||||
candidates = [path.join(dir, self.config.language,
|
candidates = [path.join(dir, self.config.language,
|
||||||
|
@ -24,7 +24,7 @@ else:
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import os
|
import os
|
||||||
from collections.abc import Collection, Iterator, Sequence
|
from collections.abc import Collection, Iterator, Sequence, Set
|
||||||
|
|
||||||
from sphinx.application import Sphinx
|
from sphinx.application import Sphinx
|
||||||
from sphinx.environment import BuildEnvironment
|
from sphinx.environment import BuildEnvironment
|
||||||
@ -33,7 +33,13 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
_ConfigRebuild = Literal['', 'env', 'epub', 'gettext', 'html']
|
_ConfigRebuild = Literal[
|
||||||
|
'', 'env', 'epub', 'gettext', 'html',
|
||||||
|
# sphinxcontrib-applehelp
|
||||||
|
'applehelp',
|
||||||
|
# sphinxcontrib-devhelp
|
||||||
|
'devhelp',
|
||||||
|
]
|
||||||
|
|
||||||
CONFIG_FILENAME = 'conf.py'
|
CONFIG_FILENAME = 'conf.py'
|
||||||
UNSERIALIZABLE_TYPES = (type, types.ModuleType, types.FunctionType)
|
UNSERIALIZABLE_TYPES = (type, types.ModuleType, types.FunctionType)
|
||||||
@ -423,7 +429,7 @@ class Config:
|
|||||||
valid_types = _validate_valid_types(types)
|
valid_types = _validate_valid_types(types)
|
||||||
self._options[name] = _Opt(default, rebuild, valid_types)
|
self._options[name] = _Opt(default, rebuild, valid_types)
|
||||||
|
|
||||||
def filter(self, rebuild: str | Sequence[str]) -> Iterator[ConfigValue]:
|
def filter(self, rebuild: Set[_ConfigRebuild]) -> Iterator[ConfigValue]:
|
||||||
if isinstance(rebuild, str):
|
if isinstance(rebuild, str):
|
||||||
return (value for value in self if value.rebuild == rebuild)
|
return (value for value in self if value.rebuild == rebuild)
|
||||||
return (value for value in self if value.rebuild in rebuild)
|
return (value for value in self if value.rebuild in rebuild)
|
||||||
|
@ -320,7 +320,7 @@ class BuildEnvironment:
|
|||||||
else:
|
else:
|
||||||
# check if a config value was changed that affects how
|
# check if a config value was changed that affects how
|
||||||
# doctrees are read
|
# doctrees are read
|
||||||
for item in config.filter('env'):
|
for item in config.filter(frozenset({'env'})):
|
||||||
if self.config[item.name] != item.value:
|
if self.config[item.name] != item.value:
|
||||||
self.config_status = CONFIG_CHANGED
|
self.config_status = CONFIG_CHANGED
|
||||||
self.config_status_extra = f' ({item.name!r})'
|
self.config_status_extra = f' ({item.name!r})'
|
||||||
|
Loading…
Reference in New Issue
Block a user