Skip to content

Commit 8eaa0ab

Browse files
authored
Stop taking app in create_source_parser() (#13639)
1 parent b544cfc commit 8eaa0ab

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Dependencies
77
Incompatible changes
88
--------------------
99

10+
* #13639: :py:meth:`!SphinxComponentRegistry.create_source_parser` no longer
11+
has an *app* parameter, instead taking *config* and *env*.
12+
Patch by Adam Turner.
13+
1014
Deprecated
1115
----------
1216

sphinx/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def create_publisher(app: Sphinx, filetype: str) -> Publisher:
118118
reader = SphinxStandaloneReader()
119119
reader._setup_transforms(registry=app.registry)
120120

121-
parser = app.registry.create_source_parser(app, filetype)
121+
parser = app.registry.create_source_parser(filetype, config=app.config, env=app.env)
122122
if parser.__class__.__name__ == 'CommonMarkParser' and parser.settings_spec == ():
123123
# a workaround for recommonmark
124124
# If recommonmark.AutoStrictify is enabled, the parser invokes reST parser

sphinx/registry.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,14 @@ def get_source_parser(self, filetype: str) -> type[Parser]:
375375
def get_source_parsers(self) -> dict[str, type[Parser]]:
376376
return self.source_parsers
377377

378-
def create_source_parser(self, app: Sphinx, filename: str) -> Parser:
378+
def create_source_parser(
379+
self, filename: str, *, config: Config, env: BuildEnvironment
380+
) -> Parser:
379381
parser_class = self.get_source_parser(filename)
380382
parser = parser_class()
381383
if isinstance(parser, SphinxParser):
382-
parser.config = app.config
383-
parser.env = app.env
384+
parser.config = config
385+
parser.env = env
384386
return parser
385387

386388
def add_translator(

sphinx/transforms/i18n.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import contextlib
66
from re import DOTALL, match
77
from textwrap import indent
8-
from types import SimpleNamespace
98
from typing import TYPE_CHECKING, Any, TypeVar
109

1110
from docutils import nodes
@@ -109,9 +108,8 @@ def publish_msgstr(
109108
config.rst_prolog = None
110109

111110
reader = _SphinxI18nReader(registry=registry)
112-
app = SimpleNamespace(config=config, env=env, registry=registry)
113111
filetype = get_filetype(config.source_suffix, source_path)
114-
parser = registry.create_source_parser(app, filetype) # type: ignore[arg-type]
112+
parser = registry.create_source_parser(filetype, config=config, env=env)
115113
doc = reader.read(
116114
source=StringInput(
117115
source=source, source_path=f'{source_path}:{source_line}:<translated>'

0 commit comments

Comments
 (0)