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,
-- 
Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org
_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to