summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-04-13 10:08:07 +0200
committerGitHub <noreply@github.com>2022-04-13 10:08:07 +0200
commitbbb54188c4b27e2a9f403d1b9c89b371ddab0363 (patch)
treec24e11005243831dc8443550df9a5e740ec48433
parentb95bc235cbfded0ebaa48c63b5644e2e53da1dec (diff)
downloadpylint-git-bbb54188c4b27e2a9f403d1b9c89b371ddab0363.tar.gz
Use ``namespace`` in ``--generate-rcfile`` (#6282)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
-rw-r--r--doc/Makefile10
-rw-r--r--pylint/config/arguments_manager.py54
-rw-r--r--pylint/config/callback_actions.py5
-rw-r--r--tbump.toml4
-rw-r--r--tests/test_self.py5
5 files changed, 40 insertions, 38 deletions
diff --git a/doc/Makefile b/doc/Makefile
index 39266a91e..278eea897 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -151,13 +151,3 @@ features.rst: $(shell find ../pylint/checkers -type f -regex '.*\.py')
PYTHONPATH=$(PYTHONPATH) $(PYTHON) ./exts/pylint_features.py
messages: $(PYTHONPATH) $(PYTHON) ./exts/pylint_messages.py
-
-gen-examples:
- chmod u+w ../examples/pylintrc
- pylint --rcfile=/dev/null --generate-rcfile > ../examples/pylintrc
-
-gen-man:
- chmod u+w ../man/pylint.1
- pylint --rcfile=/dev/null --generate-man > ../man/pylint.1
-
-all: html gen-man gen-examples
diff --git a/pylint/config/arguments_manager.py b/pylint/config/arguments_manager.py
index bc58a8244..2bdd344b4 100644
--- a/pylint/config/arguments_manager.py
+++ b/pylint/config/arguments_manager.py
@@ -374,27 +374,41 @@ class _ArgumentsManager:
"generate_config has been deprecated. It will be removed in pylint 3.0.",
DeprecationWarning,
)
- options_by_section: Dict[str, List[Tuple]] = {}
+ options_by_section = {}
sections = []
- for provider in self.options_providers:
- with warnings.catch_warnings():
- warnings.filterwarnings("ignore", category=DeprecationWarning)
- for section, options in provider.options_by_section():
- if section is None:
- section = provider.name
- if section in skipsections:
- continue
- options = [ # type: ignore[misc]
- (n, d, v)
- for (n, d, v) in options
- if d.get("type") is not None and not d.get("deprecated")
- ]
- if not options:
- continue
- if section not in sections:
- sections.append(section)
- all_options = options_by_section.setdefault(section, [])
- all_options += options
+ for group in self._arg_parser._action_groups:
+ group_name = group.title
+ assert group_name
+ if group_name in skipsections:
+ continue
+
+ options = []
+ for opt in group._group_actions:
+ if "--help" in opt.option_strings:
+ continue
+
+ optname = opt.option_strings[0][2:]
+
+ try:
+ optdict = self._option_dicts[optname]
+ except KeyError:
+ continue
+
+ options.append(
+ (
+ optname,
+ optdict,
+ getattr(self.namespace, optname.replace("-", "_")),
+ )
+ )
+
+ options = [
+ (n, d, v) for (n, d, v) in options if not d.get("deprecated")
+ ]
+
+ if options:
+ sections.append(group_name)
+ options_by_section[group_name] = options
stream = stream or sys.stdout
printed = False
for section in sections:
diff --git a/pylint/config/callback_actions.py b/pylint/config/callback_actions.py
index 8dce54d1b..a3904c503 100644
--- a/pylint/config/callback_actions.py
+++ b/pylint/config/callback_actions.py
@@ -238,11 +238,10 @@ class _GenerateRCFileAction(_AccessRunObjectAction):
option_string: Optional[str] = "--generate-rcfile",
) -> None:
# pylint: disable-next=fixme
- # TODO: Optparse: Deprecate this function and raise a warning.
- # This is (obviously) dependent on a --generate-toml-config flag.
+ # TODO: Optparse: Deprecate this after discussion about this removal has been completed.
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
- self.run.linter.generate_config(skipsections=("COMMANDS",))
+ self.run.linter.generate_config(skipsections=("Commands",))
sys.exit(0)
diff --git a/tbump.toml b/tbump.toml
index 5426c45f5..27a7db71a 100644
--- a/tbump.toml
+++ b/tbump.toml
@@ -33,6 +33,10 @@ name = "Upgrade and check doc"
cmd = "tox -e docs||echo 'Hack so this command does not fail'"
[[before_commit]]
+name = "Upgrade the pylintrc examples"
+cmd = "pylint --rcfile=/dev/null --generate-rcfile > examples/pylintrc"
+
+[[before_commit]]
name = "Normalize the contributors-txt configuration"
cmd = "contributors-txt-normalize-configuration -a script/.contributors_aliases.json -o script/.contributors_aliases.json"
diff --git a/tests/test_self.py b/tests/test_self.py
index 0c81e6c08..c8c943e10 100644
--- a/tests/test_self.py
+++ b/tests/test_self.py
@@ -1342,12 +1342,7 @@ class TestCallbackOptions:
)
assert process.stdout == process_two.stdout
- # pylint: disable-next=fixme
- # TODO: Optparse: This test should be used in --generate-toml-config
- # and then removed. Since `disable` is now in namespace it no longer
- # works.
@staticmethod
- @pytest.mark.xfail
def test_generate_config_disable_symbolic_names() -> None:
"""Test that --generate-rcfile puts symbolic names in the --disable option."""
out = StringIO()