On 10 October 2012 08:59, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 10/10/2012 07:55 AM, Paul Berry wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This brings us into accordance with the official Python style guide<br>
(<a href="http://www.python.org/dev/peps/pep-0008/#indentation" target="_blank">http://www.python.org/dev/<u></u>peps/pep-0008/#indentation</a>).<br>
<br>
To preserve the indentation of the c code that is generated by these<br>
scripts, I've avoided re-indenting triple-quoted strings (unless those<br>
strings appear to be docstrings).<br>
---<br>
<br>
I'm about to start doing some work on the Python code generation<br>
scripts in src/mapi/glapi/gen, and I'd like to use the standard Python<br>
style of 4-space indentation. Several of us have talked about<br>
switching to the standard style for a long time, and one of the chief<br>
stumbling blocks was not wanting to deal with a transitional period<br>
where the indentation was inconsistent. So yesterday I wrote a script<br>
to automate the conversion process<br>
(<a href="https://github.com/stereotype441/mesa-tools/blob/master/fix-indentation.py" target="_blank">https://github.com/<u></u>stereotype441/mesa-tools/blob/<u></u>master/fix-indentation.py</a>).<br>
<br>
This patch is the result of applying that script to the python files<br>
in src/mapi/glapi/gen only. I would be happy to apply the script to<br>
other python files in Mesa (or Piglit) if there is interest.<br>
<br>
I based the algorithm on the Python line structure analysis rules<br>
(documented in<br>
<a href="http://docs.python.org/reference/lexical_analysis.html#line-structure" target="_blank">http://docs.python.org/<u></u>reference/lexical_analysis.<u></u>html#line-structure</a>)<br>
so I believe it should not alter any semantics.<br>
<br>
The diff is over 400k, so I've included just two of the smaller python<br>
files as representative examples. The complete patch can be found at<br>
git://<a href="http://github.com/stereotype441/mesa.git" target="_blank">github.com/<u></u>stereotype441/mesa.git</a> in branch "reindent-glapi".<br>
</blockquote>
<br></div></div>
I definitely approve of using PEP-8 style.<br>
<br>
Acked-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>><br>
<br>
Incidentally, the glsl/builtins scripts are all already 4-space indent.<br>
<br>
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. </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I'm curious whether there's any work to be done besides the indentation.<br></blockquote><div><br>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.<br>
<br>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.<br>
<br>autopep8, on the other hand, mucked with the indentation *inside* a lot of strings, changing the generated code. We can't have that.<br><br>I'll try to find some options for autopep8 that tiptoe around its bugs, and submit some more clean-up patches.<br>
</div></div>