From 9f9aaf867287c09b66302d92f65b408ad324b668 Mon Sep 17 00:00:00 2001 From: Sylvain Th?nault Date: Fri, 21 Mar 2014 07:55:52 +0100 Subject: ensure --init-hooks is evaluated before other options. Closes issue #166 --- ChangeLog | 3 +++ lint.py | 16 +++++++++------- test/unittest_lint.py | 7 ++++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 51253d8..4e34f9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ ChangeLog for Pylint ==================== -- + * ensure init-hooks is evaluated before other options, notably load-plugins + (#166) + * Python 2.5 support restored: fixed small issues preventing pylint to run on python 2.5. Bitbucket issues #50 and #62. diff --git a/lint.py b/lint.py index 7697315..7d88d8e 100644 --- a/lint.py +++ b/lint.py @@ -906,10 +906,11 @@ group are mutually exclusive.'), self._plugins = [] try: preprocess_options(args, { - # option: (callback, takearg) - 'rcfile': (self.cb_set_rcfile, True), - 'load-plugins': (self.cb_add_plugins, True), - }) + # option: (callback, takearg) + 'init-hooks': (cb_init_hook, True), + 'rcfile': (self.cb_set_rcfile, True), + 'load-plugins': (self.cb_add_plugins, True), + }) except ArgumentPreprocessingError, ex: print >> sys.stderr, ex sys.exit(32) @@ -921,8 +922,9 @@ group are mutually exclusive.'), 'help' : 'Specify a configuration file.'}), ('init-hook', - {'action' : 'callback', 'type' : 'string', 'metavar': '', - 'callback' : cb_init_hook, 'level': 1, + {'action' : 'callback', 'callback' : lambda *args: 1, + 'type' : 'string', 'metavar': '', + 'level': 1, 'help' : 'Python code to execute, usually for sys.path \ manipulation such as pygtk.require().'}), @@ -1091,7 +1093,7 @@ are done by default'''}), self.linter.list_messages() sys.exit(0) -def cb_init_hook(option, optname, value, parser): +def cb_init_hook(optname, value): """exec arbitrary code to set sys.path for instance""" exec value diff --git a/test/unittest_lint.py b/test/unittest_lint.py index e211c15..8f11a5f 100644 --- a/test/unittest_lint.py +++ b/test/unittest_lint.py @@ -378,7 +378,12 @@ class PyLinterTC(TestCase): self.linter.check_message_id('W0001').symbol) self.assertEqual('msg-symbol', self.linter.check_message_id('old-symbol').symbol) - + + def test_init_hooks_called_before_load_plugins(self): + self.assertRaises(RuntimeError, + Run, ['--load-plugins', 'unexistant', '--init-hooks', 'raise RuntimeError']) + self.assertRaises(RuntimeError, + Run, ['--init-hooks', 'raise RuntimeError', '--load-plugins', 'unexistant']) class ConfigTC(TestCase): -- cgit v1.2.1