Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
show version for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Oct 2, 2019
1 parent 8aed9bf commit 8ace784
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion 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.
Expand Down
17 changes: 12 additions & 5 deletions flakehell/_logic/_discover.py
Expand Up @@ -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],
)
16 changes: 10 additions & 6 deletions flakehell/commands/_plugins.py
Expand Up @@ -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()
Expand All @@ -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, ''
4 changes: 2 additions & 2 deletions flakehell/plugins/_pylint.py
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 8ace784

Please sign in to comment.