diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-03-09 13:43:08 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-03-17 07:55:02 +0300 |
commit | 23f7b3a6e7fb0f17c4c62ddf1e2ef8078e0e679e (patch) | |
tree | 85a5ba0fc70cb34acd311786cbd3903c3011a9c2 /sphinx | |
parent | 783d077dc81bebd4e0e7dba04e3a1fa6e589ffe0 (diff) |
refactor: Remove lists of transforms from SphinxStandalonReader
Diffstat (limited to 'sphinx')
-rw-r--r-- | sphinx/application.py | 5 | ||||
-rw-r--r-- | sphinx/io.py | 33 | ||||
-rw-r--r-- | sphinx/transforms/__init__.py | 28 | ||||
-rw-r--r-- | sphinx/transforms/compact_bullet_list.py | 14 | ||||
-rw-r--r-- | sphinx/transforms/i18n.py | 13 | ||||
-rw-r--r-- | sphinx/transforms/references.py | 15 | ||||
-rw-r--r-- | sphinx/versioning.py | 14 |
7 files changed, 98 insertions, 24 deletions
diff --git a/sphinx/application.py b/sphinx/application.py index 887eae86c..dcd143712 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -91,11 +91,16 @@ builtin_extensions = ( 'sphinx.parsers', 'sphinx.registry', 'sphinx.roles', + 'sphinx.transforms', + 'sphinx.transforms.compact_bullet_list', + 'sphinx.transforms.i18n', + 'sphinx.transforms.references', 'sphinx.transforms.post_transforms', 'sphinx.transforms.post_transforms.code', 'sphinx.transforms.post_transforms.images', 'sphinx.transforms.post_transforms.compat', 'sphinx.util.compat', + 'sphinx.versioning', # collectors should be loaded by specific order 'sphinx.environment.collectors.dependencies', 'sphinx.environment.collectors.asset', diff --git a/sphinx/io.py b/sphinx/io.py index 00fc2bf1a..f6162b024 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -20,17 +20,12 @@ from docutils.writers import UnfilteredWriter from sphinx.deprecation import RemovedInSphinx30Warning from sphinx.transforms import ( - ApplySourceWorkaround, ExtraTranslatableNodes, SmartQuotesSkipper, CitationReferences, - DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks, SortIds, FigureAligner, - AutoNumbering, AutoIndexUpgrader, FilterSystemMessages, - UnreferencedFootnotesDetector, SphinxSmartQuotes, DoctreeReadEvent, ManpageLink + AutoIndexUpgrader, DoctreeReadEvent, FigureAligner, SphinxTransformer ) -from sphinx.transforms import SphinxTransformer -from sphinx.transforms.compact_bullet_list import RefOnlyBulletListTransform from sphinx.transforms.i18n import ( PreserveTranslatableMessages, Locale, RemoveTranslatableInline, ) -from sphinx.transforms.references import SphinxDomains, SubstitutionDefinitionsRemover +from sphinx.transforms.references import SphinxDomains from sphinx.util import logging from sphinx.util import UnicodeDecodeErrorHandler from sphinx.util.docutils import LoggingReporter @@ -93,13 +88,6 @@ class SphinxStandaloneReader(SphinxBaseReader): """ A basic document reader for Sphinx. """ - transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, PreserveTranslatableMessages, - Locale, CitationReferences, DefaultSubstitutions, MoveModuleTargets, - HandleCodeBlocks, AutoNumbering, AutoIndexUpgrader, SortIds, FigureAligner, - RemoveTranslatableInline, FilterSystemMessages, RefOnlyBulletListTransform, - UnreferencedFootnotesDetector, SphinxSmartQuotes, ManpageLink, - SphinxDomains, SubstitutionDefinitionsRemover, DoctreeReadEvent, - UIDTransform, SmartQuotesSkipper] def __init__(self, app, *args, **kwargs): # type: (Sphinx, Any, Any) -> None @@ -136,12 +124,17 @@ class SphinxI18nReader(SphinxBaseReader): Because the translated texts are partial and they don't have correct line numbers. """ - transforms = [ApplySourceWorkaround, ExtraTranslatableNodes, CitationReferences, - DefaultSubstitutions, MoveModuleTargets, HandleCodeBlocks, - AutoNumbering, SortIds, RemoveTranslatableInline, - FilterSystemMessages, RefOnlyBulletListTransform, - UnreferencedFootnotesDetector, SphinxSmartQuotes, ManpageLink, - SubstitutionDefinitionsRemover, SmartQuotesSkipper] + def __init__(self, app, *args, **kwargs): + # type: (Sphinx, Any, Any) -> None + self.transforms = self.transforms + app.registry.get_transforms() + unused = [PreserveTranslatableMessages, Locale, RemoveTranslatableInline, + AutoIndexUpgrader, FigureAligner, SphinxDomains, DoctreeReadEvent, + UIDTransform] + for transform in unused: + if transform in self.transforms: + self.transforms.remove(transform) + + super().__init__(app, *args, **kwargs) def set_lineno_for_reporter(self, lineno): # type: (int) -> None diff --git a/sphinx/transforms/__init__.py b/sphinx/transforms/__init__.py index dd7a4c04f..158feafcb 100644 --- a/sphinx/transforms/__init__.py +++ b/sphinx/transforms/__init__.py @@ -29,7 +29,7 @@ from sphinx.util.nodes import ( if False: # For type annotation - from typing import Any, Generator, List, Tuple # NOQA + from typing import Any, Dict, Generator, List, Tuple # NOQA from sphinx.application import Sphinx # NOQA from sphinx.config import Config # NOQA from sphinx.domain.std import StandardDomain # NOQA @@ -438,3 +438,29 @@ class ManpageLink(SphinxTransform): if r: info = r.groupdict() node.attributes.update(info) + + +def setup(app): + # type: (Sphinx) -> Dict[str, Any] + app.add_transform(ApplySourceWorkaround) + app.add_transform(ExtraTranslatableNodes) + app.add_transform(SmartQuotesSkipper) + app.add_transform(CitationReferences) + app.add_transform(DefaultSubstitutions) + app.add_transform(MoveModuleTargets) + app.add_transform(HandleCodeBlocks) + app.add_transform(SortIds) + app.add_transform(FigureAligner) + app.add_transform(AutoNumbering) + app.add_transform(AutoIndexUpgrader) + app.add_transform(FilterSystemMessages) + app.add_transform(UnreferencedFootnotesDetector) + app.add_transform(SphinxSmartQuotes) + app.add_transform(DoctreeReadEvent) + app.add_transform(ManpageLink) + + return { + 'version': 'builtin', + 'parallel_read_safe': True, + 'parallel_write_safe': True, + } diff --git a/sphinx/transforms/compact_bullet_list.py b/sphinx/transforms/compact_bullet_list.py index 7f7db5c40..e118e6a84 100644 --- a/sphinx/transforms/compact_bullet_list.py +++ b/sphinx/transforms/compact_bullet_list.py @@ -17,7 +17,8 @@ from sphinx.transforms import SphinxTransform if False: # For type annotation - from typing import Any, List # NOQA + from typing import Any, Dict, List # NOQA + from sphinx.application import Sphinx # NOQA class RefOnlyListChecker(nodes.GenericNodeVisitor): @@ -90,3 +91,14 @@ class RefOnlyBulletListTransform(SphinxTransform): compact_para = addnodes.compact_paragraph() compact_para += ref item.replace(para, compact_para) + + +def setup(app): + # type: (Sphinx) -> Dict[str, Any] + app.add_transform(RefOnlyBulletListTransform) + + return { + 'version': 'builtin', + 'parallel_read_safe': True, + 'parallel_write_safe': True, + } diff --git a/sphinx/transforms/i18n.py b/sphinx/transforms/i18n.py index c8628c318..c884bb89d 100644 --- a/sphinx/transforms/i18n.py +++ b/sphinx/transforms/i18n.py @@ -483,3 +483,16 @@ class RemoveTranslatableInline(SphinxTransform): for inline in self.document.traverse(matcher): # type: nodes.inline inline.parent.remove(inline) inline.parent += inline.children + + +def setup(app): + # type: (Sphinx) -> Dict[str, Any] + app.add_transform(PreserveTranslatableMessages) + app.add_transform(Locale) + app.add_transform(RemoveTranslatableInline) + + return { + 'version': 'builtin', + 'parallel_read_safe': True, + 'parallel_write_safe': True, + } diff --git a/sphinx/transforms/references.py b/sphinx/transforms/references.py index fd7e71779..de512f437 100644 --- a/sphinx/transforms/references.py +++ b/sphinx/transforms/references.py @@ -15,7 +15,8 @@ from sphinx.transforms import SphinxTransform if False: # For type annotation - from typing import Any # NOQA + from typing import Any, Dict # NOQA + from sphinx.application import Sphinx # NOQA class SubstitutionDefinitionsRemover(SphinxTransform): @@ -38,3 +39,15 @@ class SphinxDomains(SphinxTransform): # type: (Any) -> None for domain in self.env.domains.values(): domain.process_doc(self.env, self.env.docname, self.document) + + +def setup(app): + # type: (Sphinx) -> Dict[str, Any] + app.add_transform(SubstitutionDefinitionsRemover) + app.add_transform(SphinxDomains) + + return { + 'version': 'builtin', + 'parallel_read_safe': True, + 'parallel_write_safe': True, + } diff --git a/sphinx/versioning.py b/sphinx/versioning.py index d69720c57..c98d166bc 100644 --- a/sphinx/versioning.py +++ b/sphinx/versioning.py @@ -20,8 +20,9 @@ from sphinx.transforms import SphinxTransform if False: # For type annotation - from typing import Any, Iterator # NOQA + from typing import Any, Dict, Iterator # NOQA from docutils import nodes # NOQA + from sphinx.application import Sphinx # NOQA try: import Levenshtein @@ -186,3 +187,14 @@ def prepare(document): RemovedInSphinx30Warning, stacklevel=2) transform = UIDTransform(document) transform.apply() + + +def setup(app): + # type: (Sphinx) -> Dict[str, Any] + app.add_transform(UIDTransform) + + return { + 'version': 'builtin', + 'parallel_read_safe': True, + 'parallel_write_safe': True, + } |