|
13 | 13 | # built documents.
|
14 | 14 | #
|
15 | 15 | # The short X.Y version.
|
| 16 | +from itertools import chain |
| 17 | + |
16 | 18 | from pylint import __version__
|
| 19 | +from pylint.checkers import initialize as initialize_checkers |
| 20 | +from pylint.constants import MSG_TYPES |
| 21 | +from pylint.extensions import initialize as initialize_extensions |
| 22 | +from pylint.lint import PyLinter |
17 | 23 |
|
18 | 24 | # Pylint documentation build configuration file, created by
|
19 | 25 | # sphinx-quickstart on Thu Apr 4 20:31:25 2013.
|
|
30 | 36 | # If extensions (or modules to document with autodoc) are in another directory,
|
31 | 37 | # add these directories to sys.path here. If the directory is relative to the
|
32 | 38 | # documentation root, use os.path.abspath to make it absolute, like shown here.
|
| 39 | + |
| 40 | + |
33 | 41 | sys.path.append(os.path.abspath("exts"))
|
34 | 42 |
|
35 | 43 | # -- General configuration -----------------------------------------------------
|
|
49 | 57 | "sphinx_reredirects",
|
50 | 58 | ]
|
51 | 59 |
|
| 60 | +MSG_TYPES_DOC = {k: v if v != "info" else "information" for k, v in MSG_TYPES.items()} |
| 61 | + |
| 62 | + |
| 63 | +def get_all_messages_redirect() -> dict[str, str]: |
| 64 | + result = {} |
| 65 | + linter = PyLinter() |
| 66 | + initialize_checkers(linter) |
| 67 | + initialize_extensions(linter) |
| 68 | + checker_message_mapping = chain.from_iterable( |
| 69 | + ((checker, msg) for msg in checker.messages) |
| 70 | + for checker in linter.get_checkers() |
| 71 | + ) |
| 72 | + for checker, message in checker_message_mapping: |
| 73 | + category = MSG_TYPES_DOC[message.msgid[0]] |
| 74 | + before = f"messages/{category}/{message.symbol}" |
| 75 | + result[before] = f"user_guide/messages/{category}/{message.symbol}.html" |
| 76 | + if message.old_names: |
| 77 | + for old_name in message.old_names: |
| 78 | + old_category = MSG_TYPES_DOC[old_name[0][0]] |
| 79 | + before = f"messages/{old_category}/{old_name[1]}" |
| 80 | + result[ |
| 81 | + before |
| 82 | + ] = f"user_guide/messages/{old_category}/{old_name[1]}.html" |
| 83 | + return result |
| 84 | + |
| 85 | + |
52 | 86 | # https://documatt.gitlab.io/sphinx-reredirects/usage.html
|
53 | 87 | redirects: dict[str, str] = {
|
54 | 88 | # "<source>": "<target>"
|
|
60 | 94 | "messages/messages_list": "user_guide/messages/messages_overview.html",
|
61 | 95 | "user_guide/message-control": "user_guide/messages/message-control.html",
|
62 | 96 | }
|
| 97 | +redirects.update(get_all_messages_redirect()) |
| 98 | + |
| 99 | +print(redirects) |
63 | 100 |
|
64 | 101 | # Add any paths that contain templates here, relative to this directory.
|
65 | 102 | templates_path = ["_templates"]
|
|
0 commit comments