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

Fix sphinx-doc#10104: gettext: Duplicated locations are output to pot file #10466

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -21,6 +21,8 @@ Bugs fixed
* #9648: autodoc: ``*args`` and ``**kwargs`` entries are duplicated when
``autodoc_typehints="description"``
* #10443: epub: EPUB builder can't detect the mimetype of .webp file
* #10104: gettext: Duplicated locations are shown if 3rd party extension does
not provide correct information
* #10456: py domain: ``:meta:`` fields are displayed if docstring contains two
or more meta-field
* #9096: sphinx-build: the value of progress bar for paralle build is wrong
Expand Down
3 changes: 2 additions & 1 deletion sphinx/builders/gettext.py
Expand Up @@ -57,7 +57,8 @@ def add(self, msg: str, origin: Union[Element, "MsgOrigin"]) -> None:

def __iter__(self) -> Generator[Message, None, None]:
for message in self.messages:
positions = [(source, line) for source, line, uuid in self.metadata[message]]
positions = sorted(set((source, line) for source, line, uuid
in self.metadata[message]))
uuids = [uuid for source, line, uuid in self.metadata[message]]
yield Message(message, positions, uuids)

Expand Down
20 changes: 20 additions & 0 deletions tests/test_build_gettext.py
Expand Up @@ -8,9 +8,29 @@

import pytest

from sphinx.builders.gettext import Catalog, MsgOrigin
from sphinx.util.osutil import cd


def test_Catalog_duplicated_message():
catalog = Catalog()
catalog.add('hello', MsgOrigin('/path/to/filename', 1))
catalog.add('hello', MsgOrigin('/path/to/filename', 1))
catalog.add('hello', MsgOrigin('/path/to/filename', 2))
catalog.add('hello', MsgOrigin('/path/to/yetanother', 1))
catalog.add('world', MsgOrigin('/path/to/filename', 1))

assert len(list(catalog)) == 2

msg1, msg2 = list(catalog)
assert msg1.text == 'hello'
assert msg1.locations == [('/path/to/filename', 1),
('/path/to/filename', 2),
('/path/to/yetanother', 1)]
assert msg2.text == 'world'
assert msg2.locations == [('/path/to/filename', 1)]


@pytest.mark.sphinx('gettext', srcdir='root-gettext')
def test_build_gettext(app):
# Generic build; should fail only when the builder is horribly broken.
Expand Down