Python code standard

Hi ,

In PR https://github.com/ArduPilot/ardupilot/pull/4092 we raised the question about using a code standard for python.
I would like to propose pep8 as standard .It is pretty well documented, got plenty tools to check it (pep8, flake8 etc ) and it is the standard in ROS too (http://wiki.ros.org/PyStyleGuide)

What do you think ?

Moreover, could we use try to be compatible to python3 ?

Ps: normally I shouldn’t be allow to post in developpement team, you should have miss something in configuration !

I think pep8 is fine. Just make sure to add some exclusions for the insane things.

Proposed tool :
Flake8 : http://flake8.pycqa.org/en/latest/
It does pep8 code style checking + some python mistakes

It can be configured for project, file or by line

Proposed exclued rules :

PEP 8: visually indented line with same indent as next logical line
PEP 8: line too long

I’d be happy with that.
I think there will be some challenges with python3 for pymavlink and mavproxy, but as long as it doesn’t break py2 support then I’d be happy for someone to work on it!

I remember using them with Python 3. I submitted a pr for that a long time ago. I need to check again if it didn’t bitrot

@peterbarker
You raised a question about a tool that can format python file. I found and test autopep8 (https://github.com/hhatto/autopep8) that do good job at it.

Using :
autopep8 -i --max-line-length 120 --select E121,E301,E302,E303,E304,E309,E251,E231,E502,W291,W293,W391,E26,E265,E227,E228,E101,E111 -a -a

It remove only trailling whitespace, add some for readability, but not around math operator !
And combine with flake8 thepythonfile.py --ignore=E501,F405,E401,E226,E201,E202,E203,E129,E127,E241,E221,E126,E225,E123,E222

It should trigger online syntax error