summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2014-03-21 07:55:52 +0100
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2014-03-21 07:55:52 +0100
commit9f9aaf867287c09b66302d92f65b408ad324b668 (patch)
tree7024ef2604cfd5a9f6612f858527d8075bbfae84
parentbd15fd5219e3453e7a2c1964d972806c4bac1508 (diff)
downloadpylint-9f9aaf867287c09b66302d92f65b408ad324b668.tar.gz
ensure --init-hooks is evaluated before other options. Closes issue #166
-rw-r--r--ChangeLog3
-rw-r--r--lint.py16
-rw-r--r--test/unittest_lint.py7
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': '<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):