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

Addressing problems raised in sphinx_issues #10104 #10379

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 8 additions & 5 deletions sphinx/builders/gettext.py
@@ -1,5 +1,5 @@
"""The MessageCatalogBuilder class."""

import os
Copy link
Member

Choose a reason for hiding this comment

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

Keep a blank line here

Suggested change
import os
import os

from codecs import open
from collections import OrderedDict, defaultdict
from datetime import datetime, timedelta, tzinfo
Expand Down Expand Up @@ -32,13 +32,14 @@ class Message:
"""An entry of translatable message."""
def __init__(self, text: str, locations: List[Tuple[str, int]], uuids: List[str]):
self.text = text
self.locations = locations
self.locations = list(sorted(list(set(locations)))) #make list unique and sorted alphabetically
Copy link
Member

@AA-Turner AA-Turner Apr 24, 2022

Choose a reason for hiding this comment

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

sorted returns a list and can take a set as input

Suggested change
self.locations = list(sorted(list(set(locations)))) #make list unique and sorted alphabetically
self.locations = sorted(set(locations)) # sort and de-duplicate the locations list

self.uuids = uuids


class Catalog:
"""Catalog of translatable messages."""

# make a class var so any instance can share this parent class, where all building info can be found, such as srcdir etc..
builder = None
def __init__(self) -> None:
self.messages: List[str] = [] # retain insertion order, a la OrderedDict

Expand All @@ -56,8 +57,9 @@ def add(self, msg: str, origin: Union[Element, "MsgOrigin"]) -> None:
self.metadata[msg].append((origin.source, origin.line, origin.uid)) # type: ignore

def __iter__(self) -> Generator[Message, None, None]:
src_dir = Catalog.builder.srcdir
for message in self.messages:
positions = [(source, line) for source, line, uuid in self.metadata[message]]
positions = [(relpath(source, start=src_dir), 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 Expand Up @@ -213,7 +215,8 @@ class MessageCatalogBuilder(I18nBuilder):
def init(self) -> None:
super().init()
self.create_template_bridge()
self.templates.init(self)
self.templates.init(self)
Catalog.builder = self # make the builder visible to instances of catalog

def _collect_templates(self) -> Set[str]:
template_files = set()
Expand Down