Skip to content

gh-130979: Doc: Generate ids for audit_events using docname #136165

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 8 additions & 3 deletions Doc/tools/extensions/audit_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ def _check_args_match(self, name: str, args: list[str]) -> None:
logger.warning(msg)
return

def id_for(self, name) -> str:
source_count = len(self.sources.get(name, set()))
def _source_count(self, name, docname) -> int:
"""Count the event name in the same source"""
sources = self.sources.get(name, set())
return len([s for s, t in sources if s == docname])

def id_for(self, name, docname) -> str:
source_count = self._source_count(name, docname)
name_clean = re.sub(r"\W", "_", name)
return f"audit_event_{name_clean}_{source_count}"

Expand Down Expand Up @@ -142,7 +147,7 @@ def run(self) -> list[nodes.paragraph]:
except (IndexError, TypeError):
target = None
if not target:
target = self.env.audit_events.id_for(name)
target = self.env.audit_events.id_for(name, self.env.docname)
ids.append(target)
self.env.audit_events.add_event(name, args, (self.env.docname, target))

Expand Down
Loading