Salut,
The attached is a patch to allow custom 'output-format' for reports.
Previously, only a set of predefined reports are able to be used as
'output-format', e.g., text, parseable, csv, html are types defined in
lint.py. With this patch, users can still use these as 'aliased'
reporter types, but they're also able to directly supply a
full-qualified python class that supports the report contract.
e.g.,
[report]
output-format = mypackage.mymodule.JsonReporter
Cheers,
P.S. This is the first time I contribute to pylint and I haven't been
using mercurial as much (I'm primarily a git user), so if there's
anything that's not up to the project convention or standards, let me
know. Merci.
diff -r a8e0d01488a1 lint.py
--- a/lint.py Thu Sep 06 10:54:35 2012 +0200
+++ b/lint.py Sun Sep 16 23:24:22 2012 -0400
@@ -171,8 +171,7 @@
python modules names) to load, usually to register additional checkers.'}),
('output-format',
- {'default': 'text', 'type': 'choice', 'metavar' : '<format>',
- 'choices': REPORTER_OPT_MAP.keys(),
+ {'default': 'text', 'type': 'string', 'metavar' : '<format>',
'short': 'f',
'group': 'Reports',
'help' : 'Set the output format. Available formats are text,\
@@ -323,7 +322,15 @@
else :
meth(value)
elif optname == 'output-format':
- self.set_reporter(REPORTER_OPT_MAP[value.lower()]())
+ if value.lower() in REPORTER_OPT_MAP:
+ self.set_reporter(REPORTER_OPT_MAP[value.lower()]())
+ else:
+ components = value.split('.')
+ reporter_class = __import__(components[0])
+ for comp in components[1:]:
+ reporter_class = getattr(reporter_class, comp)
+ self.set_reporter(reporter_class())
+
try:
BaseRawChecker.set_option(self, optname, value, action, optdict)
except UnsupportedAction:
diff -r a8e0d01488a1 test/unittest_lint.py
--- a/test/unittest_lint.py Thu Sep 06 10:54:35 2012 +0200
+++ b/test/unittest_lint.py Sun Sep 16 23:24:22 2012 -0400
@@ -210,6 +210,19 @@
self.linter.enable('RP0001')
self.assertEqual(self.linter.report_is_enabled('RP0001'), True)
+ def test_report_output_format_aliased(self):
+ self.linter.set_option('output-format', 'text')
+ self.assertEqual(self.linter.reporter.__class__.__name__, 'TextReporter')
+
+ def test_report_output_format_custom(self):
+ this_module = sys.modules[__name__]
+ class TestReporter(object):
+ pass
+ this_module.TestReporter = TestReporter
+ class_name = ".".join((this_module.__name__, 'TestReporter'))
+ self.linter.set_option('output-format', class_name)
+ self.assertEqual(self.linter.reporter.__class__.__name__, 'TestReporter')
+
def test_set_option_1(self):
linter = self.linter
linter.set_option('disable', 'C0111,W0142')
_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects