Thursday, 31 October 2019

Pylint failing to load plugin on a mercurial precommit hook

I am trying to create a mercurial pre-commit hook that runs pylint on the pre-commit. My project uses a virtual environment.

I have the hook set up to call pylint on the changed files but I get the error:

Traceback (most recent call last):
  File "/home/barmstrong/.virtualenvs/amp/bin/pylint", line 10, in <module>
    sys.exit(run_pylint())
  File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/pylint/__init__.py", line 20, in run_pylint
    Run(sys.argv[1:])
  File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/pylint/lint.py", line 1583, in __init__
    linter.load_plugin_modules(plugins)
  File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/pylint/lint.py", line 636, in load_plugin_modules
    module = modutils.load_module_from_name(modname)
  File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/astroid/modutils.py", line 202, in load_module_from_name
    return load_module_from_modpath(dotted_name.split("."), path, use_sys)
  File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/astroid/modutils.py", line 244, in load_module_from_modpath
    mp_file, mp_filename, mp_desc = imp.find_module(part, path)
  File "/usr/lib/python3.6/imp.py", line 297, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'common'

I believe this is due to a custom plugin in the .pylintrc file that it tries to load from my project directory in:

'/common/blah/file.py'

And in the .pylintrc it is referenced by:

common.blah.file

I try to add this to the PYTHONPATH running:

sys.path.append('path/common')

But the error persists. How do I solve this so it can load my plugin? (I have also tried variations of adding the common module to the PYTHONPATH with no success).

EDIT: If I remove the common.blah/file.py file from my .pylintrc it works, so I need to figure out how I can import it. I have tried adding 'common' to the PYTHONPATH but it does not seem to work.



from Pylint failing to load plugin on a mercurial precommit hook

No comments:

Post a Comment