From c4ea64da09a2d60ee9388469fbc5de8157d726f8 Mon Sep 17 00:00:00 2001 From: GetPsyched Date: Mon, 4 Nov 2024 02:07:18 +0400 Subject: [PATCH] fix: minor cleanup --- .../src/nixos_render_docs/redirects.py | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/redirects.py b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/redirects.py index 4b65e2c79de86..9d842a25700bc 100644 --- a/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/redirects.py +++ b/pkgs/tools/nix/nixos-render-docs/src/nixos_render_docs/redirects.py @@ -1,6 +1,5 @@ import json from dataclasses import dataclass, field -from pathlib import Path from .manual_structure import XrefTarget @@ -14,10 +13,9 @@ class Redirects: _raw_redirects: dict[str, list[str]] _redirects_script: str - _xref_targets: dict[str, XrefTarget] = field(default_factory=dict) _errors: list[RedirectsError] = field(default_factory=list) - def validate(self, xref_targets): + def validate(self, xref_targets: dict[str, XrefTarget]): """ Parse redirects from an static set of identifier-locations pairs @@ -30,9 +28,6 @@ def validate(self, xref_targets): - Flatten redirects into simple key-value pairs for simpler indexing - Segregate client and server side redirects """ - self._xref_targets = xref_targets - redirection_targets = {target.path for target in xref_targets.values()} - identifiers_without_redirects = xref_targets.keys() - self._raw_redirects.keys() orphan_identifiers = self._raw_redirects.keys() - xref_targets.keys() if orphan_identifiers: @@ -107,7 +102,7 @@ def raise_errors(self, error_type: RedirectsError = None): if len(errors_to_raise) == 1: raise errors_to_raise[0] else: - raise RuntimeError("Multiple errors occurred:", "\n\n".join(errors_to_raise)) + raise RedirectsError(f"Multiple validation errors occurred:\n{'\n'.join(map(str, errors_to_raise))}") def get_client_redirects(self, redirection_target: str): client_redirects = {} @@ -132,9 +127,9 @@ def __str__(self): conflict_list = "\n - ".join(sorted(self.conflicts)) return f""" **Conflicting Anchors Found** -An identifier must not match the name of an anchor across any historical location. +An identifier must not match the name of an anchor across any historical location of the same output path. -The following paths voilate the above rule: +The following identifiers voilate the above rule: - {conflict_list} This can generally happen when: @@ -176,7 +171,7 @@ def __str__(self): **Invalid Current Paths Found** The head element of an identifier's corresponding historical location must be its current output location. -The following paths voilate the above rule: +The following identifiers voilate the above rule: - {invalid_list} This is problematic because: @@ -194,7 +189,7 @@ def __str__(self): **Redirects Missing** Every identifier present in the source files must have a mapping in the redirects. -The following paths voilate the above rule: +The following identifiers voilate the above rule: - {missing_list} This can generally happen when: @@ -216,7 +211,7 @@ def __str__(self): **Orphan Identifiers Found** Every key of the redirects mapping must correspond to some identifier in the source files. -The following paths voilate the above rule: +The following identifiers voilate the above rule: - {orphan_list} This can generally happen when: @@ -235,7 +230,7 @@ def __str__(self): **Transitive Redirects Found** Transitivity is disallowed to avoid multiple network calls. -The following paths voilate the above rule: +The following identifiers voilate the above rule: - {transitive_list} This can generally happen when: