From ef6c2875ad248383dbfa66e8fd05856223c2680c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Sat, 2 Apr 2022 12:00:32 +0200 Subject: [PATCH 1/2] Remove broken ``generate-man`` option --- ChangeLog | 4 + doc/whatsnew/2.14.rst | 4 + pylint/config/__init__.py | 2 - pylint/config/man_help_formatter.py | 121 -------------------------- pylint/config/option_manager_mixin.py | 16 ---- pylint/lint/run.py | 17 +--- 6 files changed, 9 insertions(+), 155 deletions(-) delete mode 100644 pylint/config/man_help_formatter.py diff --git a/ChangeLog b/ChangeLog index 8a4b812c0e..7c1f6ec3d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,10 @@ Release date: TBA Closes #6074 +* Removed the broken ``generate-man`` option. + + Closes #5283 + * Add new check ``unnecessary-dunder-call`` for unnecessary dunder method calls. Closes #5936 diff --git a/doc/whatsnew/2.14.rst b/doc/whatsnew/2.14.rst index f17493b089..a0ede2eca7 100644 --- a/doc/whatsnew/2.14.rst +++ b/doc/whatsnew/2.14.rst @@ -46,6 +46,10 @@ Other Changes Closes #5931 +* Removed the broken ``generate-man`` option. + + Closes #5283 + * The concept of checker priority has been removed. * The ``set_config_directly`` decorator has been removed. diff --git a/pylint/config/__init__.py b/pylint/config/__init__.py index 05b7568c01..732d4448e3 100644 --- a/pylint/config/__init__.py +++ b/pylint/config/__init__.py @@ -17,7 +17,6 @@ find_default_config_files, find_pylintrc, ) -from pylint.config.man_help_formatter import _ManHelpFormatter from pylint.config.option import Option from pylint.config.option_manager_mixin import OptionsManagerMixIn from pylint.config.option_parser import OptionParser @@ -32,7 +31,6 @@ "ConfigurationMixIn", "find_default_config_files", "find_pylintrc", - "_ManHelpFormatter", "Option", "OptionsManagerMixIn", "OptionParser", diff --git a/pylint/config/man_help_formatter.py b/pylint/config/man_help_formatter.py deleted file mode 100644 index 84837cc3c1..0000000000 --- a/pylint/config/man_help_formatter.py +++ /dev/null @@ -1,121 +0,0 @@ -# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE -# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt - -import optparse # pylint: disable=deprecated-module -import sys -import time - - -class _ManHelpFormatter(optparse.HelpFormatter): - def __init__( - self, indent_increment=0, max_help_position=24, width=79, short_first=0 - ): - super().__init__(indent_increment, max_help_position, width, short_first) - self.output_level: int - - def format_heading(self, heading): - return f".SH {heading.upper()}\n" - - def format_description(self, description): - return description - - def format_option(self, option): - try: - optstring = option.option_strings - except AttributeError: - optstring = self.format_option_strings(option) - if option.help: - help_text = self.expand_default(option) - help_string = " ".join(line.strip() for line in help_text.splitlines()) - help_string = help_string.replace("\\", "\\\\") - help_string = help_string.replace("[current:", "[default:") - else: - help_string = "" - return f""".IP "{optstring}" -{help_string} -""" - - def format_head(self, optparser, pkginfo, section=1): - long_desc = "" - try: - pgm = optparser._get_prog_name() - except AttributeError: - # py >= 2.4.X (dunno which X exactly, at least 2) - pgm = optparser.get_prog_name() - short_desc = self.format_short_description(pgm, pkginfo.description) - if hasattr(pkginfo, "long_desc"): - long_desc = self.format_long_description(pgm, pkginfo.long_desc) - return f"""{self.format_title(pgm, section)} -{short_desc} -{self.format_synopsis(pgm)} -{long_desc}""" - - @staticmethod - def format_title(pgm, section): - date = ( - "%d-%02d-%02d" # pylint: disable=consider-using-f-string - % time.localtime()[:3] - ) - return f'.TH {pgm} {section} "{date}" {pgm}' - - @staticmethod - def format_short_description(pgm, short_desc): - return f""".SH NAME -.B {pgm} -\\- {short_desc.strip()} -""" - - @staticmethod - def format_synopsis(pgm): - return f""".SH SYNOPSIS -.B {pgm} -[ -.I OPTIONS -] [ -.I -] -""" - - @staticmethod - def format_long_description(pgm, long_desc): - long_desc = "\n".join(line.lstrip() for line in long_desc.splitlines()) - long_desc = long_desc.replace("\n.\n", "\n\n") - if long_desc.lower().startswith(pgm): - long_desc = long_desc[len(pgm) :] - return f""".SH DESCRIPTION -.B {pgm} -{long_desc.strip()} -""" - - @staticmethod - def format_tail(pkginfo): - tail = f""".SH SEE ALSO -/usr/share/doc/pythonX.Y-{getattr(pkginfo, "debian_name", "pylint")}/ - -.SH BUGS -Please report bugs on the project\'s mailing list: -{pkginfo.mailinglist} - -.SH AUTHOR -{pkginfo.author} <{pkginfo.author_email}> -""" - if hasattr(pkginfo, "copyright"): - tail += f""" -.SH COPYRIGHT -{pkginfo.copyright} -""" - return tail - - def format_usage(self, usage): - """Taken from optparse.IndentedHelpFormatter.""" - return f"Usage: {usage}\n" - - -def _generate_manpage(optparser, pkginfo, section=1, stream=sys.stdout, level=0): - formatter = _ManHelpFormatter() - formatter.output_level = level - formatter.parser = optparser - print(formatter.format_head(optparser, pkginfo, section), file=stream) - print(optparser.format_option_help(formatter), file=stream) - print(formatter.format_tail(pkginfo), file=stream) diff --git a/pylint/config/option_manager_mixin.py b/pylint/config/option_manager_mixin.py index ddd75eab44..1b4b2eeb34 100644 --- a/pylint/config/option_manager_mixin.py +++ b/pylint/config/option_manager_mixin.py @@ -10,11 +10,9 @@ import os import sys from pathlib import Path -from types import ModuleType from typing import Dict, List, Optional, TextIO, Tuple from pylint import utils -from pylint.config.man_help_formatter import _ManHelpFormatter from pylint.config.option import Option from pylint.config.option_parser import OptionParser @@ -219,20 +217,6 @@ def generate_config( ) printed = True - def generate_manpage( - self, pkginfo: ModuleType, section: int = 1, stream: TextIO = sys.stdout - ) -> None: - with _patch_optparse(): - formatter = _ManHelpFormatter() - formatter.output_level = self._maxlevel - formatter.parser = self.cmdline_parser - print( - formatter.format_head(self.cmdline_parser, pkginfo, section), - file=stream, - ) - print(self.cmdline_parser.format_option_help(formatter), file=stream) - print(formatter.format_tail(pkginfo), file=stream) - def load_provider_defaults(self): """Initialize configuration using default values.""" for provider in self.options_providers: diff --git a/pylint/lint/run.py b/pylint/lint/run.py index 9660f9c744..ecbdad8a76 100644 --- a/pylint/lint/run.py +++ b/pylint/lint/run.py @@ -8,7 +8,7 @@ import warnings from typing import NoReturn, Optional -from pylint import __pkginfo__, config, extensions, interfaces +from pylint import config, extensions, interfaces from pylint.config.config_initialization import _config_initialization from pylint.constants import DEFAULT_PYLINT_HOME, OLD_DEFAULT_PYLINT_HOME, full_version from pylint.lint.pylinter import PyLinter @@ -238,16 +238,6 @@ def __init__( "configuration.", }, ), - ( - "generate-man", - { - "action": "callback", - "callback": self.cb_generate_manpage, - "group": "Commands", - "help": "Generate pylint's man page.", - "hide": True, - }, - ), ( "errors-only", { @@ -437,11 +427,6 @@ def cb_generate_config(self, *args, **kwargs): self.linter.generate_config(skipsections=("COMMANDS",)) sys.exit(0) - def cb_generate_manpage(self, *args, **kwargs): - """Optik callback for sample config file generation.""" - self.linter.generate_manpage(__pkginfo__) - sys.exit(0) - def cb_help_message(self, option, optname, value, parser): """Optik callback for printing some help about a particular message.""" self.linter.msgs_store.help_message(utils._splitstrip(value)) From 897e5379848d6761451cd4e39833dd1ba466a3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Sat, 2 Apr 2022 12:11:57 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Pierre Sassoulas --- ChangeLog | 1 + doc/whatsnew/2.14.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7c1f6ec3d1..61b5a112cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,7 @@ Release date: TBA * Removed the broken ``generate-man`` option. Closes #5283 + Closes #1887 * Add new check ``unnecessary-dunder-call`` for unnecessary dunder method calls. diff --git a/doc/whatsnew/2.14.rst b/doc/whatsnew/2.14.rst index a0ede2eca7..b939de6891 100644 --- a/doc/whatsnew/2.14.rst +++ b/doc/whatsnew/2.14.rst @@ -49,6 +49,7 @@ Other Changes * Removed the broken ``generate-man`` option. Closes #5283 + Closes #1887 * The concept of checker priority has been removed.