summaryrefslogtreecommitdiff
path: root/doc/exts
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2022-05-26 11:21:15 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2022-05-28 23:52:20 +0200
commit365e690f4824c250972138e4e01d851067f17984 (patch)
treebdcc0a8b0810d6154b3b38ba5d9302feab600465 /doc/exts
parentd077f01e36b7e7042e776306efb6578b5d32766c (diff)
downloadpylint-git-365e690f4824c250972138e4e01d851067f17984.tar.gz
[refactor] Create a function to get the messages' data path
Diffstat (limited to 'doc/exts')
-rw-r--r--doc/exts/pylint_messages.py35
1 files changed, 22 insertions, 13 deletions
diff --git a/doc/exts/pylint_messages.py b/doc/exts/pylint_messages.py
index 58e507b17..d83daf83a 100644
--- a/doc/exts/pylint_messages.py
+++ b/doc/exts/pylint_messages.py
@@ -157,10 +157,9 @@ def _get_all_messages(
for checker in linter.get_checkers()
)
for checker, message in checker_message_mapping:
- message_data_path = (
- PYLINT_MESSAGES_DATA_PATH / message.symbol[0] / message.symbol
+ good_code, bad_code, details, related = _get_message_data(
+ _get_message_data_path(message)
)
- good_code, bad_code, details, related = _get_message_data(message_data_path)
checker_module = getmodule(checker)
@@ -192,6 +191,10 @@ def _get_all_messages(
return messages_dict, old_messages
+def _get_message_data_path(message: MessageDefinition) -> Path:
+ return PYLINT_MESSAGES_DATA_PATH / message.symbol[0] / message.symbol
+
+
def _message_needs_update(message_data: MessageData, category: str) -> bool:
"""Do we need to regenerate this message .rst ?"""
message_path = _get_message_path(category, message_data)
@@ -301,7 +304,6 @@ Pylint can emit the following messages:
old_messages_string = "".join(
f" {category}/{old_message[0]}\n" for old_message in old_messages
)
-
# Write list per category. We need the '-category' suffix in the reference
# because 'fatal' is also a message's symbol
stream.write(
@@ -333,15 +335,21 @@ def _write_redirect_pages(old_messages: OldMessagesDict) -> None:
if not os.path.exists(category_dir):
os.makedirs(category_dir)
for old_name, new_names in old_names.items():
- old_name_file = os.path.join(category_dir, f"{old_name[0]}.rst")
- with open(old_name_file, "w", encoding="utf-8") as stream:
- new_names_string = "".join(
- f" ../{new_name[1]}/{new_name[0]}.rst\n" for new_name in new_names
- )
- stream.write(
- f""".. _{old_name[0]}:
+ _write_redirect_old_page(category_dir, old_name, new_names)
+
-{get_rst_title(" / ".join(old_name), "=")}
+def _write_redirect_old_page(
+ category_dir: Path,
+ old_name: Tuple[str, str],
+ new_names: List[Tuple[str, str]],
+) -> None:
+ old_name_file = os.path.join(category_dir, f"{old_name[0]}.rst")
+ new_names_string = "".join(
+ f" ../{new_name[1]}/{new_name[0]}.rst\n" for new_name in new_names
+ )
+ content = f""".. _{old_name[0]}:
+
+{get_rst_title("/".join(old_name), "=")}
"{old_name[0]} has been renamed. The new message can be found at:
.. toctree::
@@ -350,7 +358,8 @@ def _write_redirect_pages(old_messages: OldMessagesDict) -> None:
{new_names_string}
"""
- )
+ with open(old_name_file, "w", encoding="utf-8") as stream:
+ stream.write(content)
# pylint: disable-next=unused-argument