jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/858590 )
Change subject: [IMPR] remove version hints when printing module documentation ......................................................................
[IMPR] remove version hints when printing module documentation
Also use ModuleNotFoundError exception instead of generic Exception and only keep import_module() function inside try statement.
Change-Id: I469ff08a24957b78577fd402ea0cdb595b38e39f --- M pywikibot/bot.py 1 file changed, 22 insertions(+), 6 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py index 4a85b17..3ccc9e9 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -93,6 +93,7 @@ import logging import logging.handlers import os +import re import sys import time import warnings @@ -1026,6 +1027,8 @@
.. versionchanged:: 4.0 Renamed from showHelp() to show_help(). + .. versionchanged:: 8.0 + Do not show version changes. """ if not module_name: module_name = calledModuleName() @@ -1039,16 +1042,17 @@
try: module = import_module(module_name) - help_text: str = module.__doc__ # type: ignore[assignment] - if hasattr(module, 'docuReplacements'): - for key, value in module.docuReplacements.items(): - help_text = help_text.replace(key, value.strip('\n\r')) - except Exception: + except ModuleNotFoundError: if module_name: pywikibot.stdout('Sorry, no help available for ' + module_name) pywikibot.log('show_help:', exc_info=True) else: - pywikibot.stdout(help_text) # output to STDOUT + help_text = re.sub(r'^.. version(added|changed)::.+', '', + module.__doc__, flags=re.MULTILINE | re.DOTALL) + if hasattr(module, 'docuReplacements'): + for key, value in module.docuReplacements.items(): + help_text = help_text.replace(key, value.strip()) + pywikibot.stdout(help_text)
if show_global or module_name == 'pwb': pywikibot.stdout(_GLOBAL_HELP.format(module_name))
pywikibot-commits@lists.wikimedia.org