[Mesa-dev] [PATCH] glapi: Reformat python code generation scripts to use 4-space indentation.
stereotype441 at gmail.com
Wed Oct 10 10:16:53 PDT 2012
On 10 October 2012 08:59, Kenneth Graunke <kenneth at whitecape.org> wrote:
> On 10/10/2012 07:55 AM, Paul Berry wrote:
>> This brings us into accordance with the official Python style guide
>> To preserve the indentation of the c code that is generated by these
>> scripts, I've avoided re-indenting triple-quoted strings (unless those
>> strings appear to be docstrings).
>> I'm about to start doing some work on the Python code generation
>> scripts in src/mapi/glapi/gen, and I'd like to use the standard Python
>> style of 4-space indentation. Several of us have talked about
>> switching to the standard style for a long time, and one of the chief
>> stumbling blocks was not wanting to deal with a transitional period
>> where the indentation was inconsistent. So yesterday I wrote a script
>> to automate the conversion process
>> This patch is the result of applying that script to the python files
>> in src/mapi/glapi/gen only. I would be happy to apply the script to
>> other python files in Mesa (or Piglit) if there is interest.
>> I based the algorithm on the Python line structure analysis rules
>> (documented in
>> so I believe it should not alter any semantics.
>> The diff is over 400k, so I've included just two of the smaller python
>> files as representative examples. The complete patch can be found at
>> git://github.com/**stereotype441/mesa.git<http://github.com/stereotype441/mesa.git>in branch "reindent-glapi".
> I definitely approve of using PEP-8 style.
> Acked-by: Kenneth Graunke <kenneth at whitecape.org>
> Incidentally, the glsl/builtins scripts are all already 4-space indent.
> By the way, have you seen the 'pep8' and 'autopep8' tools? The former
> reports any PEP-8 style violations, and the latter attempts to fix them.
> I'm curious whether there's any work to be done besides the indentation.
Cool, I wasn't aware of those tools. Pep8 seems like a good tool, and a
lot of what it warns about is probably worth fixing.
Comparing the output of autopep8 and my tool turned out to be a good way to
find bugs in both tools. My tool changed the semantics of one function by
accident: FindOffset() in mesadef.py. It got confused by the silly
"#endfor" comment and wound up moving the "return -1" inside the loop.
Oops. I've fixed that now.
autopep8, on the other hand, mucked with the indentation *inside* a lot of
strings, changing the generated code. We can't have that.
I'll try to find some options for autopep8 that tiptoe around its bugs, and
submit some more clean-up patches.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the mesa-dev