I've tried doing it your way and it does work. The differences are that I
edited the executable a bit to tailor my environment and I include the
custom checker in the rcfile. Seems to be a problem with ConfigParser

[hsebastian@hans-l contrib]$  cat bin/lint.py
import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from pylint import lint
lint.Run(sys.argv[1:])
[hsebastian@hans-l contrib]$  python bin/lint.py
--load-plugins=pylint_import pylint
No config file found, using default configuration
************* Module pylint.__pkginfo__
I:  1: Locally disabling W0622
I:  1: Locally disabling C0103
...
[hsebastian@hans-l contrib]$  cat config.ini | grep load-plugins
load-plugins=pylint_import
[hsebastian@hans-l contrib]$  python bin/lint.py --rcfile=config.ini pylint
Traceback (most recent call last):
  File "bin/lint.py", line 4, in <module>
    lint.Run(sys.argv[1:])
  File "bin/../pylint/lint.py", line 830, in __init__
    linter.load_plugin_modules(plugins)
  File "bin/../pylint/lint.py", line 279, in load_plugin_modules
    module.register(self)
  File "bin/../pylint_import.py", line 21, in register
    linter.register_checker(MyImportsChecker(linter))
  File "bin/../pylint/lint.py", line 323, in register_checker
    self.register_options_provider(checker)
  File "bin/../logilab/common/configuration.py", line 446, in
register_options_provider
    non_group_spec_options, provider)
  File "bin/../logilab/common/configuration.py", line 471, in
add_option_group
    self.cfgfile_parser.add_section(group_name)
  File "/Users/hsebastian/target/lib/python2.7/ConfigParser.py", line 256,
in add_section
    raise DuplicateSectionError(section)
ConfigParser.DuplicateSectionError: Section 'IMPORTS' already exists
[hsebastian@hans-l contrib]$  cat pylint_import.py
import re
from logilab import astng
from pylint.checkers.imports import ImportsChecker

class MyImportsChecker(ImportsChecker):
    def __init__(self, linter=None):
        self.msgs['R0402'] = ('Unable to import %r because this is not
Windows', 'WONTFIX')
        ImportsChecker.__init__(self, linter)

    def get_imported_module(self, modnode, importnode, modname):
        try:
            return importnode.do_import_module(modname)
        except astng.InferenceError, ex:
            if re.search('win', modname) is not None:
                self.add_message("R0402", args=modname, node=importnode)
            else:
                self.add_message("F0401", args=modname, node=importnode)

def register(linter):
   """required method to auto register this checker """
   linter.register_checker(MyImportsChecker(linter))

Thanks

-hans

2011/5/3 Sylvain Thénault <[email protected]>

> On 02 mai 18:25, Hans Sebastian wrote:
> > I tried the custom checker in my previous reply again but it's still not
> > working. I loaded it in my config file using
> > 'load-plugins=my_import_checker'. And then, I commented out the register
> > method in imports.py. Fyi, when I comment out this register method
> without
> > my custom checker, the import errors disappear so I know at least that
> > works.
> >
> > My current workaround is by adding the custom checker extending
> > ImportsChecker directly in imports.py and editing the register method to
> use
> > my custom checker instead. That works. But it would be nice if it can
> exists
> > in its own file so it's like an actual plugin, besides being easier to
> > maintain. :)
>
> [snip]
>
> I fail to grasp what's going on. Trying to reproduce your problem, here is
> what
> I have done:
>
> [syt@scorpius ~]$ cat ~/src/pylint_import.py
> from pylint.checkers.imports import ImportsChecker
>
> class MyImportsChecker(ImportsChecker):
>    pass
>
> def register(linter):
>    """required method to auto register this checker """
>     linter.register_checker(MyImportsChecker(linter))
>
> [syt@scorpius pylint]$ hg diff
> diff --git a/checkers/imports.py b/checkers/imports.py
> --- a/checkers/imports.py
> +++ b/checkers/imports.py
> @@ -364,8 +364,8 @@ given file (report RP0402 must not be di
>             self.__int_dep_info = filter_dependencies_info(
>                 self.stats['dependencies'], self.package_dir(), 'internal')
>         return self.__int_dep_info
>
>
> -def register(linter):
> -    """required method to auto register this checker """
> -    linter.register_checker(ImportsChecker(linter))
> +# def register(linter):
> +#     """required method to auto register this checker """
> +#     linter.register_checker(ImportsChecker(linter))
>
>
> [syt@scorpius pylint]$ pylint --load-plugins=pylint_import pylint
> No config file found, using default configuration
> ************* Module config
> [run smoothly]
>
> Any difference between that and what you're doing?
>
> --
> Sylvain Thénault                               LOGILAB, Paris (France)
> 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
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to