diff --git a/sphinx/io.py b/sphinx/io.py index 26c8b756fab..f61c9d16378 100644 --- a/sphinx/io.py +++ b/sphinx/io.py @@ -25,6 +25,7 @@ from sphinx.application import Sphinx from sphinx.environment import BuildEnvironment + from sphinx.registry import SphinxComponentRegistry logger = logging.getLogger(__name__) @@ -38,20 +39,6 @@ class SphinxBaseReader(standalone.Reader): # type: ignore[misc] transforms: list[type[Transform]] = [] - def __init__(self, *args: Any, **kwargs: Any) -> None: - from sphinx.application import Sphinx - - if len(args) > 0 and isinstance(args[0], Sphinx): - self._app = args[0] - self._env = self._app.env - args = args[1:] - - super().__init__(*args, **kwargs) - - def setup(self, app: Sphinx) -> None: - self._app = app # hold application object only for compatibility - self._env = app.env - def get_transforms(self) -> list[type[Transform]]: transforms = super().get_transforms() + self.transforms @@ -83,9 +70,8 @@ def new_document(self) -> nodes.document: class SphinxStandaloneReader(SphinxBaseReader): """A basic document reader for Sphinx.""" - def setup(self, app: Sphinx) -> None: - self.transforms = self.transforms + app.registry.get_transforms() - super().setup(app) + def _setup_transforms(self, *, registry: SphinxComponentRegistry) -> None: + self.transforms = self.transforms + registry.get_transforms() def read(self, source: Input, parser: Parser, settings: Values) -> nodes.document: # type: ignore[type-arg] self.source = source @@ -130,7 +116,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: def create_publisher(app: Sphinx, filetype: str) -> Publisher: reader = SphinxStandaloneReader() - reader.setup(app) + reader._setup_transforms(registry=app.registry) parser = app.registry.create_source_parser(app, filetype) if parser.__class__.__name__ == 'CommonMarkParser' and parser.settings_spec == (): diff --git a/sphinx/testing/restructuredtext.py b/sphinx/testing/restructuredtext.py index b2ebcf23002..4439b128cd5 100644 --- a/sphinx/testing/restructuredtext.py +++ b/sphinx/testing/restructuredtext.py @@ -20,7 +20,7 @@ def parse(app: Sphinx, text: str, docname: str = 'index') -> nodes.document: try: app.env.current_document.docname = docname reader = SphinxStandaloneReader() - reader.setup(app) + reader._setup_transforms(registry=app.registry) parser = RSTParser() parser.config = app.config parser.env = app.env