Hi experts !
I am struggling with Pylint with an issue that might be a problem coming
from my code. Since I am relatively new to python (~1year) I would like to
have your input on the matter.
I am trying to split a big python project I am doing for my company into
several packages, allowing me to update each part without impacting the
others. Doing that, we decided to go with Jenkins to improve our code
quality which lead me to implement pylint for code violations checks.
Currently my build process is the following :
- Create a new virtualenv with Python version 2.7.6
- Install all dependencies needed by my package
- Download the last version of the package from the master branch in our
internal gitlab
- Run nosetests with coverage reports
- Run pylint and export the result to have some violations reports in
Jenkins.
At first I had a lot of pylint errors since I wasn't installing all
dependencies, resulting in something like 200 import errors ... Now it is
reduced to some 60 errors but when I look a the build output log, I can see
that pylint is actually crashing in the middle of the process.
************* Module company.project.core.security.app
company/project/core/security/app.py:1: [C0111(missing-docstring), ]
Missing module docstring
load_entry_point('pylint==1.2.1', 'console_scripts', 'pylint')()
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/pylint/__init__.py",
line 21, in run_pylint
Run(sys.argv[1:])
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/pylint/lint.py",
line 1051, in __init__
linter.check(args)
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/pylint/lint.py",
line 626, in check
self.check_astroid_module(astroid, walker, rawcheckers, tokencheckers)
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/pylint/lint.py",
line 712, in check_astroid_module
walker.walk(astroid)
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/pylint/utils.py",
line 715, in walk
self.walk(child)
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/pylint/utils.py",
line 712, in walk
cb(astroid)
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/pylint/checkers/imports.py",
line 269, in visit_from
self._add_imported_module(node, '%s.%s' % (importedmodnode.name, name))
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/pylint/checkers/imports.py",
line 302, in _add_imported_module
importedmodname = get_module_part(importedmodname)
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/logilab/common/modutils.py",
line 352, in get_module_part
path=path, context_file=context_file)
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/logilab/common/modutils.py",
line 297, in file_from_modpath
return _file_from_modpath(modpath, path, context)
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/logilab/common/modutils.py",
line 556, in _file_from_modpath
mtype, mp_filename = _module_file(modpath, path)
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/logilab/common/modutils.py",
line 636, in _module_file
return _search_zip(modpath, pic)[:2]
File "/var/lib/jenkins/.pyenv/versions/2.7.6/lib/python2.7/site-packages/logilab/common/modutils.py",
line 577, in _search_zip
raise ImportError('No module named %s' % '.'.join(modpath))
ImportError: No module named project
This is how my package is constructed :
company/
-- __init__.py
-- project/
-- __init__.py
-- core/
-- __init__.py
-- app.py
-- security/
-- __init__.py
-- app.py
In company.project.core.security.app I am trying to import
company.project.core.app which contains some BaseClass for my project using:
from ..app import BaseApplication
This is working fine with python, although pylint is crying out loud on
this specific line. I tried to replace the relative import by core.app
which worked fine with pylint but my code is not working anymore. I tried
also to use the full path (company.project.core.app) but I have the exact
same import error.
Be aware that both company and project are just namespace packages.
Also I am forced to use the path to run pylint because it looks like my
top-level folder is not a package (even if it contains a __init__ file).
pylint company.project.core
No module named project.core (fatal)
pylint company/project/core is working.
When I try to run pylint directly from the top-level package, I have the
exact same result as from the path.
A workaround I can try is to install the package before running pylint on
it but I reckon since my cwd is supposed to be added to the path I can't
see how it would help (although I have other company packages installed).
What do you think I should do ? Is my design a poorly chosen one and I
don't have any solution ?
Thanks,
François