OK I made a bitbucket repo: https://bitbucket.org/kevinjqiu/pylint/ and
fixed the code to use helper methods in logilab-commons to load classes.
This is the branch:
https://bitbucket.org/kevinjqiu/pylint/src/f626a1cb3cd4
Here are the 3 commits:
https://bitbucket.org/kevinjqiu/pylint/changeset/1fffc9e7a2a0127931aa24fab2387449dca49d79
https://bitbucket.org/kevinjqiu/pylint/changeset/b8d8083d260ca35d08b339e6371f79799b76011b
https://bitbucket.org/kevinjqiu/pylint/changeset/f626a1cb3cd4626fb30b353b290735cc0ead7de8
Here's the ticket in pylint tracker:
http://www.logilab.org/ticket/105337
Cheers,
On 12-09-17 11:40 AM, Sylvain Thénault wrote:
On 16 septembre 23:35, Kevin Qiu wrote:
Salut,
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
I like the idea, though it's weird to specify such thing using output-format
(but I've nothing better to propose which stay as simple as your proposal)
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.
Publishing a mercurial repository is better, though posting a patch is
fine. Minor remark below. Also you should:
* add a ticket in pylint tracker
* add an entry in the ChangeLog.
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())
I'm afraid this only work if the top level package trigger import of necessary
submodule (eg in your exemple, mypackage.__init__ import mymodule), else you
ends up with an attribute error. That should be fixed. Function get_module_part
and load_module_from_name in logilab.common.modutils should help.
Thank you for your contribution,
_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects