diff options
| author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2014-03-21 07:55:52 +0100 |
|---|---|---|
| committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2014-03-21 07:55:52 +0100 |
| commit | 9f9aaf867287c09b66302d92f65b408ad324b668 (patch) | |
| tree | 7024ef2604cfd5a9f6612f858527d8075bbfae84 | |
| parent | bd15fd5219e3453e7a2c1964d972806c4bac1508 (diff) | |
| download | pylint-9f9aaf867287c09b66302d92f65b408ad324b668.tar.gz | |
ensure --init-hooks is evaluated before other options. Closes issue #166
| -rw-r--r-- | ChangeLog | 3 | ||||
| -rw-r--r-- | lint.py | 16 | ||||
| -rw-r--r-- | test/unittest_lint.py | 7 |
3 files changed, 18 insertions, 8 deletions
@@ -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. @@ -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': '<code>', - 'callback' : cb_init_hook, 'level': 1, + {'action' : 'callback', 'callback' : lambda *args: 1, + 'type' : 'string', 'metavar': '<code>', + '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): |
