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

Restore support for list-style source_suffix with third-party parsers #12584

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Release 7.4.3 (in development)
Bugs fixed
----------

* #12582: Restore support for list-styled :confval:`source_suffix` values
with extensions that register parsers.
Patch by Adam Turner.

Release 7.4.2 (released Jul 15, 2024)
=====================================
Expand Down
10 changes: 7 additions & 3 deletions sphinx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,17 @@ def convert_source_suffix(app: Sphinx, config: Config) -> None:
# The default filetype is determined on later step.
# By default, it is considered as restructuredtext.
config.source_suffix = {source_suffix: 'restructuredtext'}
logger.info(__("Converting `source_suffix = %r` to `source_suffix = %r`."),
source_suffix, config.source_suffix)
elif isinstance(source_suffix, (list, tuple)):
# if list, considers as all of them are default filetype
config.source_suffix = dict.fromkeys(source_suffix, 'restructuredtext')
logger.info(__("Converting `source_suffix = %r` to `source_suffix = %r`."),
source_suffix, config.source_suffix)
elif not isinstance(source_suffix, dict):
logger.warning(__("The config value `source_suffix' expects "
"a string, list of strings, or dictionary. "
"But `%r' is given." % source_suffix))
msg = __("The config value `source_suffix' expects a dictionary,"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg = __("The config value `source_suffix' expects a dictionary,"
msg = __("The config value `source_suffix' expects a dictionary, "

"a string, or a list of strings. Got `%r' instead (type %s).")
raise ConfigError(msg % (source_suffix, type(source_suffix)))


def convert_highlight_options(app: Sphinx, config: Config) -> None:
Expand Down
8 changes: 6 additions & 2 deletions sphinx/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,14 @@ def merge_source_suffix(app: Sphinx, config: Config) -> None:
for suffix, filetype in app.registry.source_suffix.items():
if suffix not in app.config.source_suffix: # NoQA: SIM114
app.config.source_suffix[suffix] = filetype
elif app.config.source_suffix[suffix] is None:
# filetype is not specified (default filetype).
elif app.config.source_suffix[suffix] == 'restructuredtext':
# The filetype is not specified (default filetype).
# So it overrides default filetype by extensions setting.
app.config.source_suffix[suffix] = filetype
elif app.config.source_suffix[suffix] is None:
msg = __('`None` is not a valid filetype for %r.') % suffix
logger.warning(msg)
app.config.source_suffix[suffix] = filetype

# copy config.source_suffix to registry
app.registry.source_suffix = app.config.source_suffix
Expand Down