Skip to content

Commit

Permalink
Add version printing
Browse files Browse the repository at this point in the history
  • Loading branch information
Fergal Hainey authored and AWhetter committed Mar 25, 2018
1 parent 602c712 commit 6ae2b43
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pylint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ def _convert_definition(option, definition):

args.append('--{0}'.format(option))

copy_keys = ('action', 'default', 'dest', 'help', 'metavar', 'level')
copy_keys = (
'action', 'default', 'dest', 'help', 'metavar', 'level', 'version')
kwargs = {k: definition[k] for k in copy_keys if k in definition}

if 'type' in definition:
Expand Down
12 changes: 9 additions & 3 deletions pylint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
from pylint.reporters.ureports import nodes as report_nodes


FULL_VERSION = '%%(prog)s %s\nastroid %s\nPython %s' % (
version, astroid_version, sys.version)

MANAGER = astroid.MANAGER


Expand Down Expand Up @@ -416,9 +419,6 @@ def __init__(self, config=None):
self.current_name = None
self.current_file = None

# TODO: Runner needs to give this to parser?
full_version = '%%prog %s\nastroid %s\nPython %s' % (
version, astroid_version, sys.version)
super().__init__()
# provided reports
self._dynamic_plugins = set()
Expand Down Expand Up @@ -903,6 +903,11 @@ class CLIRunner(Runner):
'help' : 'In Python 3 porting mode, all checkers will be '
'disabled and only messages emitted by the porting '
'checker will be displayed'}),

('version',
{'group': 'Commands', 'action': 'version', 'version': FULL_VERSION,
'help': 'Print the version of pylint and important '
'dependencies'}),
)

option_groups = (
Expand Down Expand Up @@ -976,6 +981,7 @@ def run(self, args):
'load_plugins',
'ignore',
'ignore_patterns',
'version',
)

# Call init-hook
Expand Down
11 changes: 11 additions & 0 deletions pylint/test/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ def test_generate_rcfile_no_obsolete_methods(self):
output = out.getvalue()
assert "profile" not in output

def test_version(self):
"""Test version printing."""
out = six.StringIO()
self._run_pylint(['--version'], out=out)
output = out.getvalue()
# The name of pylint in version output is dependant on
# invokation (argparse %(prog)s). Python version could be
# something like PyPy. astroid is the most contant name, and we
# just want to test the version flag is wired up to print.
assert 'astroid ' in output

def test_inexisting_rcfile(self):
out = six.StringIO()
with pytest.raises(IOError) as excinfo:
Expand Down

0 comments on commit 6ae2b43

Please sign in to comment.