diff --git a/docs/commands/plugins.md b/docs/commands/plugins.md index 7fe1b39..79f207e 100644 --- a/docs/commands/plugins.md +++ b/docs/commands/plugins.md @@ -1,6 +1,6 @@ # **plugins**: installed plugins, codes, rules -Show table of all installed plugins, their declared codes prefixes, matched rules from the config. +Show table of all installed plugins, their version, declared codes prefixes, and matched rules from the config. + For plugin name green means that this plugin is used in current config, and red -- isn't. + For rule green means "include", and red means "exclude". If rule has no color, it's invalid rule. diff --git a/flakehell/_logic/_discover.py b/flakehell/_logic/_discover.py index 74ab30a..3905e8f 100644 --- a/flakehell/_logic/_discover.py +++ b/flakehell/_logic/_discover.py @@ -18,27 +18,34 @@ def get_installed(app) -> Iterator[Dict[str, Any]]: plugins_codes = defaultdict(list) + versions = dict() app.initialize([]) - for check_type, checks in app.check_plugins.to_dictionary().items(): - for check in checks: - key = (check_type, get_plugin_name(check)) + + for check_type in ('ast_plugins', 'logical_line_plugins', 'physical_line_plugins'): + for plugin in getattr(app.check_plugins, check_type): + key = (check_type, get_plugin_name(plugin.to_dictionary())) + versions[key[-1]] = plugin.version # if codes for plugin specified explicitly in ALIASES, use it - codes = ALIASES.get(check['plugin_name']) + codes = ALIASES.get(plugin.plugin_name) if codes: plugins_codes[key] = list(codes) continue # otherwise get codes from plugin entrypoint - code = check['name'] + code = plugin.name if not REX_CODE.match(code): raise ValueError('Invalid code format: {}'.format(code)) plugins_codes[key].append(code) + if 'flake8-docstrings' in versions: + versions['flake8-docstrings'] = versions['flake8-docstrings'].split(',')[0] + for (check_type, name), codes in plugins_codes.items(): yield dict( type=check_type, name=name, codes=sorted(codes), + version=versions[name], ) diff --git a/flakehell/commands/_plugins.py b/flakehell/commands/_plugins.py index b130eea..45da2c6 100644 --- a/flakehell/commands/_plugins.py +++ b/flakehell/commands/_plugins.py @@ -14,11 +14,14 @@ def plugins_command(argv) -> CommandResult: if not plugins: return ExitCodes.NO_PLUGINS_INSTALLED, 'no plugins installed' - width = max(len(p['name']) for p in plugins) - template = '{name} | {codes:8} | {rules}' + name_width = max(len(p['name']) for p in plugins) + version_width = min(8, max(len(p['version']) for p in plugins)) + codes_width = min(6, max(len(' '.join(p['codes'])) for p in plugins)) + template = '{name} | {version} | {codes} | {rules}' print(template.format( - name=colored('NAME'.ljust(width), 'yellow'), - codes=colored('CODES ', 'yellow'), + name=colored('NAME'.ljust(name_width), 'yellow'), + version=colored('VERION'.ljust(version_width), 'yellow'), + codes=colored('CODES'.ljust(codes_width), 'yellow'), rules=colored('RULES', 'yellow'), )) showed = set() @@ -42,8 +45,9 @@ def plugins_command(argv) -> CommandResult: colored_rules.append(rule) color = 'green' if rules else 'red' print(template.format( - name=colored(plugin['name'].ljust(width), color), - codes=', '.join(plugin['codes']), + name=colored(plugin['name'].ljust(name_width), color), + version=plugin['version'].ljust(version_width), + codes=', '.join(plugin['codes']).ljust(codes_width), rules=', '.join(colored_rules), )) return 0, '' diff --git a/flakehell/plugins/_pylint.py b/flakehell/plugins/_pylint.py index 1f5d6cb..7d639b6 100644 --- a/flakehell/plugins/_pylint.py +++ b/flakehell/plugins/_pylint.py @@ -2,7 +2,7 @@ from tokenize import TokenInfo from typing import Sequence -from pylint.__pkginfo__ import numversion +from pylint.__pkginfo__ import version from pylint.lint import Run from pylint.reporters import BaseReporter @@ -28,7 +28,7 @@ def handle_message(self, msg): class PyLintChecker: name = 'pylint' - version = numversion + version = version def __init__(self, tree: AST, file_tokens: Sequence[TokenInfo], filename: str = STDIN) -> None: self.tree = tree