How to control of the python/Django/Celery code quality

844 Views Asked by At

I am leading a big python project, it using Django(model), celery, python. Right now, I just find the code quality is out of control. The problems are:

  1. The code submitted to git has some basic programmer mistake (It's had to covered by test)
  2. Sever people submit code to one branch. (We use git flow, it need to merge very often)

For problem 1, I am thinking using Pylint , but our project is big, and have so many dependency (Django,Celery).

Can pylint work well? I just have a try pylint, seems it will report some misleading error, like django.objects does not exist. So what's your best practice to do quality control for your project?

For problem 2, I have no idea how to improve it ?

2

There are 2 best solutions below

0
On

If you are open to use a SaaS solution, feel free to check out QuantifiedCode (https://www.quantifiedcode.com).

It's an online tool for automated, continuous code review and intelligence and completely free for open-source projects. It has Github integration and provides a large range of customizable code checks (both general-purpose and library-specific checks e.g. for Django), as well as metrics for your project (disclosure: I'm the CTO).

Our code checker is open-source as well and can be found on Github:

https://github.com/quantifiedcode/checkmate

There are similar tools that you should check out as well, e.g. Landscape (www.landscape.io), CodeClimate (www.codeclimate.com), Codacy(www.codacy.com) or SonarSource (www.sonarsource.com - self hosted solution). Most of them provide a free tier for open-source projects as well.

0
On

I'm not familiar with other python code checkers but I can tell you my experience using Pylint with a small Django project.

It gives a lot of false errors. There seems to be a tradeoff of excess false errors vs. possibly missing legitimate errors in those categories. I'm using it on code that has been tested & run, so for now I've configured it to ignore most of those categories.

This is my .pylintrc setup at the moment

Add stuff to the path if you want it to check if imports work

[MASTER]

init-hook='import sys; sys.path.append("...your directories...")

My liberal ignoring of error messages that frequently give false positives.

[MESSAGES CONTROL]

# E1002: use of super on old style class
# E1101: __ has no __ member
# E1103: maybe no member
# F0401: couldn't import
# R0924: badly implemented container (false pos on forms.Form subclassers)
# W0232: class has no __init__ (when inheriting)
# W0613: unused-argument (functions that are supposed to always take request/obj)
disable=E1002,E1101,E1103,F0401,R0903,R0924,W0232,W0613

Add some automatic members to avoid some of the common E1101, if you want to enable that check

[TYPECHECK]

generated-members=REQUEST,acl_users,aq_parent,objects,_meta,id,pk

Hope that helps as far as Django + Pylint goes.