lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GOP-PROP 1: python formatting - probable decision


From: Phil Holmes
Subject: Re: GOP-PROP 1: python formatting - probable decision
Date: Thu, 30 Jun 2011 14:59:10 +0100

----- Original Message ----- From: "Graham Percival" <address@hidden>
To: <address@hidden>
Sent: Wednesday, June 15, 2011 12:11 AM
Subject: GOP-PROP 1: python formatting - probable decision


Unless anybody has a compelling reason against it, this is the
proposal which will be adopted on 22 June 2011:
http://lilypond.org/~graham/gop/gop_1.html

GOP 1 - python formatting
Proposal summary

let’s follow the indentation described in PEP-8.
http://www.python.org/dev/peps/pep-0008/

   * use 4 spaces per indentation level
   * never mix tabs and spaces (for indentation)
   * Code indented with a mixture of tabs and spaces should be
     converted to using spaces exclusively

     Once this is done, we should add "python -tt" to the build
system to avoid such errors in the future.

There should be absolutely no tab characters for indentation in
any .py file in lilypond git. All such files should be converted
to use spaces only.
Rationale

Mixing indentation styles is not a great idea, and in my
experience of python code documentation and examples online, the
4-space indent rule from PEP-8 is almost universally followed.
Implementation notes

We have very few (or none) patches for python files, so a large
whitespace change should not break any pending patches.

You can see offending files with: (that said, this command may
give false positives; it catches any tab character in a file, not
just tabs used for indentation)


address@hidden:~/src/lilypond$ git grep -l $'\t' --
"*.py"
python/convertrules.py
python/fontextract.py
python/lilylib.py
python/musicxml.py
python/rational.py
scripts/auxiliar/makelsr.py
scripts/build/create-weblinks-itexi.py
scripts/build/website_post.py
scripts/musicxml2ly.py

On the command-line, there’s the expand(1) command. Alternately, a
text editor could be used to replace \t with 8 spaces. I _think_
that all instances of tabs are used to represent 8 spaces (one of
the curses of emacs), but since indentation is so important in
python files, I fear that manual attention to any automatic system
is required.

potentially useful tool:
http://hg.python.org/cpython/file/ba975c7c33d3/Tools/scripts/reindent.py


Cheers,
- Graham


Just looking at some python files and referring to this and I've got confused. At the top of this we have:

"use 4 spaces per indentation level"

At the bottom we have:

"a text editor could be used to replace \t with 8 spaces"

Unless we have only ever used tabs to represent double indents, this isn't self consistent.

There are also a number of examples of indented lines under function definitions/calls - the parameters are normally indented. I think we should explicitly state a rule for this.

--
Phil Holmes





reply via email to

[Prev in Thread] Current Thread [Next in Thread]