File: logging.py

package info (click to toggle)
sphinx-needs 5.1.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,108 kB
  • sloc: python: 21,148; javascript: 187; makefile: 95; sh: 29; xml: 10
file content (120 lines) | stat: -rw-r--r-- 3,958 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from __future__ import annotations

from typing import Literal

from docutils.nodes import Node
from sphinx import version_info
from sphinx.util import logging
from sphinx.util.logging import SphinxLoggerAdapter


def get_logger(name: str) -> SphinxLoggerAdapter:
    return logging.getLogger(name)


WarningSubTypes = Literal[
    "config",
    "constraint",
    "create_need",
    "delete_need",
    "deprecated",
    "diagram_scale",
    "duplicate_id",
    "duplicate_part_id",
    "dynamic_function",
    "external_link_outgoing",
    "needextend",
    "needextract",
    "needflow",
    "needgantt",
    "needimport",
    "needreport",
    "needsequence",
    "filter",
    "filter_func",
    "github",
    "import_need",
    "json_load",
    "layout",
    "link_outgoing",
    "link_ref",
    "link_text",
    "load_external_need",
    "load_service_need",
    "mpl",
    "title",
    "uml",
    "unknown_external_keys",
    "mistyped_external_values",
    "unknown_import_keys",
    "mistyped_import_values",
    "variant",
    "warnings",
]

WarningSubTypeDescription: dict[WarningSubTypes, str] = {
    "config": "Invalid configuration",
    "constraint": "Constraint violation",
    "create_need": "Creation of a need from directive failed",
    "delete_need": "Deletion of a need failed",
    "deprecated": "Deprecated feature",
    "diagram_scale": "Failed to process diagram scale option",
    "duplicate_id": "Duplicate need ID found when merging needs from parallel processes",
    "duplicate_part_id": "Duplicate part ID found when parsing need content",
    "dynamic_function": "Failed to load/execute dynamic function",
    "needextend": "Error processing needextend directive",
    "needextract": "Error processing needextract directive",
    "needflow": "Error processing needflow directive",
    "needgantt": "Error processing needgantt directive",
    "needimport": "Error processing needimport directive",
    "needreport": "Error processing needreport directive",
    "needsequence": "Error processing needsequence directive",
    "filter": "Error processing needs filter",
    "filter_func": "Error loading needs filter function",
    "github": "Error in processing GitHub service directive",
    "import_need": "Failed to import a need",
    "layout": "Error occurred during layout rendering of a need",
    "link_outgoing": "Unknown outgoing link in standard need",
    "external_link_outgoing": "Unknown outgoing link in external need",
    "link_ref": "Need could not be referenced",
    "link_text": "Reference text could not be generated",
    "load_external_need": "Failed to load an external need",
    "load_service_need": "Failed to load a service need",
    "mpl": "Matplotlib required but not installed",
    "title": "Error creating need title",
    "uml": "Error in processing of UML diagram",
    "unknown_external_keys": "Unknown keys found in external need data",
    "mistyped_external_values": "Unexpected value types found in external need data",
    "unknown_import_keys": "Unknown keys found in imported need data",
    "mistyped_import_values": "Unexpected value types found in imported need data",
    "variant": "Error processing variant in need field",
    "warnings": "Need warning check failed for one or more needs",
}


def log_warning(
    logger: SphinxLoggerAdapter,
    message: str,
    subtype: WarningSubTypes,
    /,
    location: str | tuple[str | None, int | None] | Node | None,
    *,
    color: str | None = None,
    once: bool = False,
) -> None:
    # Since sphinx in v7.3, sphinx will show warning types if `show_warning_types=True` is set,
    # and in v8.0 this was made the default.
    if version_info < (8,):
        if subtype:
            message += f" [needs.{subtype}]"
        else:
            message += " [needs]"

    logger.warning(
        message,
        type="needs",
        subtype=subtype,
        location=location,
        color=color,
        once=once,
    )