From e319477dca8601b1ecbf196b57ea1c690c7f5c23 Mon Sep 17 00:00:00 2001 From: Fergal Hainey Date: Sat, 24 Mar 2018 11:42:08 +0000 Subject: Add version printing --- pylint/config.py | 2 +- pylint/lint.py | 29 ++++++++++++++++++++++------- pylint/test/test_self.py | 11 +++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/pylint/config.py b/pylint/config.py index 1b4c4435b..c1e302f61 100644 --- a/pylint/config.py +++ b/pylint/config.py @@ -456,7 +456,7 @@ class CLIParser(ConfigParser): 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: diff --git a/pylint/lint.py b/pylint/lint.py index ec04fd805..e434baccc 100644 --- a/pylint/lint.py +++ b/pylint/lint.py @@ -81,6 +81,12 @@ from pylint.__pkginfo__ import version 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 @@ -543,12 +549,6 @@ class PyLinter(utils.MessagesHandlerMixIn, checkers.BaseTokenChecker): 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() @@ -1097,6 +1097,15 @@ class CLIRunner(Runner): "checker will be displayed", }, ), + ( + "version", + { + "group": "Commands", + "action": "version", + "version": FULL_VERSION, + "help": "Print the version of pylint and important " "dependencies", + }, + ), ) option_groups = ( @@ -1171,7 +1180,13 @@ group are mutually exclusive.", self._linter.config = self._global_config parsed = parser.preprocess( - args, "init_hook", "rcfile", "load_plugins", "ignore", "ignore_patterns" + args, + "init_hook", + "rcfile", + "load_plugins", + "ignore", + "ignore_patterns", + "version", ) # Call init-hook diff --git a/pylint/test/test_self.py b/pylint/test/test_self.py index e63eb9f5b..e5549f349 100644 --- a/pylint/test/test_self.py +++ b/pylint/test/test_self.py @@ -196,6 +196,17 @@ class TestRunTC(object): 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 = StringIO() with pytest.raises(IOError) as excinfo: -- cgit v1.2.1