Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Pylint for Django projects

Tags:

django

pylint

G'Day,

I have a number of Django projects and a number of other Python projects as git repositories. I have pre-commit hook that runs Pylint on my code before allowing me to commit it - this hook doesn't know whether the project is a Django application or a vanilla Python project.

For all my Django projects, I have a structure like:

> my_django_project
|-- manage.py
|-- settings.py
|--> apps
   |--> my_django_app
      |-- models.py
      |-- admin.py 

Now, when I run pylint on this project, it gives me errors like:

F:  4,0: Unable to import 'my_django_app.models'

for my_django_app.admin module for example.

How to do I configure Pylint, so that when it is going over my django projects (not vanilla python projects), it knows that the my_django_project/apps should also be in the sys.path? Normally, manage.py adds it to the sys.path.

Thanks!

like image 375
Gaurav Dadhania Avatar asked Dec 21 '11 02:12

Gaurav Dadhania


1 Answers

Take a look at init_hook in pylint configuration file.

init-hook=import sys; sys.path.insert(0, 'my_django_project/apps');

You will obviously need a configuration file per Django application, and run pylint as, e.g.

pylint --rcfile=pylint.conf my_django_project
like image 98
Koterpillar Avatar answered Sep 21 '22 07:09

Koterpillar