On 10 October 2012 08:59, Kenneth Graunke <kenn...@whitecape.org> wrote:
> On 10/10/2012 07:55 AM, Paul Berry wrote: > >> This brings us into accordance with the official Python style guide >> (http://www.python.org/dev/**peps/pep-0008/#indentation<http://www.python.org/dev/peps/pep-0008/#indentation> >> ). >> >> 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 >> (https://github.com/**stereotype441/mesa-tools/blob/** >> master/fix-indentation.py<https://github.com/stereotype441/mesa-tools/blob/master/fix-indentation.py> >> ). >> >> 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 >> http://docs.python.org/**reference/lexical_analysis.**html#line-structure<http://docs.python.org/reference/lexical_analysis.html#line-structure> >> ) >> 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 <kenn...@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.
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev