[Qgis-developer] Python coding style for QGIS

Larry Shaffer larrys at dakotacarto.com
Tue May 1 16:13:35 EDT 2012


Hi,

On Tue, May 1, 2012 at 4:34 AM, Vincent Picavet <vincent.ml at oslandia.com>wrote:

> Hi,
>
> > I would suggest that we use PEP8 - many editors will parse this and
> > there are checking tools that can be run from the command line. I
> > would also suggest we use 4 space indents so we can process code using
> > pyindent. I know it isnt very consistent with QGIS C++ coding standard
> > but many python coders are used to these standards and they are easy
> > to check and enforce.
>
> +1 for using PEP8 as more tools and projects use it.
> I don't think the c++ consistency it is a problem : different language,
> different coding standards.
>
> > I think it would be great to extend our CODING doc to include python
> > guidelines. I have already worked on similar guidelines for another
> > project [1] which we could easily adapt.
>
> +1
>

Some of you may know this, but I have incorporated a style/coding checker
into my soon-to-be-released Plugin Editor plugin. It currently checks
against PEP8.py and an embedded version of Pylint.

I have also made several design decisions regarding PEP compliance and
general coding style. I would very much like any input on these decisions,
with regards to anticipated coding standards.

1) The default (smallest) size of the editor window is ~83 characters, with
an edge line at 80, depending upon font and zoom level used. I am releasing
the editor with 3 free fonts tested to ensure correct sizing across
platforms. By default, I hope this helps plugin developers keep their code
under 80 characters [0].

2) The PEP8.py checker is used 'as is,' while the Pylint setup's pylintrc
has been augmented to allow mixed case methods, etc., often found in PyQt
development. I have provided the default pylintrc, the augmented one and a
diff below [1]. I would appreciate any other changes to the pylintrc_pyqt I
can incorporate for QGIS plugin coding standards.

3) There is currently an error with Pylint (and or PyQt) where Pylint
chokes if PyQt4.QtCore is imported before QtGui. I am currently
recommending that QtGui's import is placed first to avoid the flaw [2].

Having run all of the core and many user plugins through the checkers, one
item sticks out every time: line length. Practically no plugin file keeps
within the 79 character line PEP standard. My only suggestion is that for
QGIS standards, a more 'modern' line length cap might be considered. Maybe
100 or even 120? Or should the 79 char style be adhered to?


[0]
http://dl.dropbox.com/u/4058089/qgis/checkers/plugin_editor_80char-line.png
[1] http://dl.dropbox.com/u/4058089/qgis/checkers/pylintrc_pyqt.zip
[2]
http://dl.dropbox.com/u/4058089/qgis/checkers/plugin_editor_pylint-error.png

Regards,

Larry Shaffer
Dakota Cartography
Black Hills, South Dakota
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20120501/4aee9df3/attachment.html


More information about the Qgis-developer mailing list