[Mesa-dev] [PATCH] Fix usage of Python in Makefiles
vlee at vmware.com
Wed Oct 27 08:50:43 PDT 2010
> -----Original Message-----
> From: mesa-dev-bounces+vlee=vmware.com at lists.freedesktop.org [mailto:mesa-
> dev-bounces+vlee=vmware.com at lists.freedesktop.org] On Behalf Of José
> Sent: Wednesday, October 27, 2010 8:33 AM
> To: Matthew William Cox
> Cc: mesa-dev at lists.freedesktop.org
> Subject: Re: [Mesa-dev] [PATCH] Fix usage of Python in Makefiles
> On Tue, 2010-10-26 at 16:12 -0700, Matthew William Cox wrote:
> > Hello,
> > Firstly, Kenneth Graunke's patch fixes the autoconf issue and supercedes
> > this patch, so we should focus the review on that patch.
> > On Tue, Oct 26, 2010 at 06:23:00AM -0700, Dan Nicholson wrote:
> > > However, removing the second -O from PYTHON_FLAGS is really a separate
> > > change. Can you explain that problem in more detail?
> > The second -O flag triggers the same behaviour as passing -OO to the
> > python interpreter. A single -O enables optimizations, but -OO causes
> > doc strings to be stripped from the bytecode in addition to enabling
> > optimization. There's no real reason to do this, except perhaps to save
> > a small amount of memory.
> > This breaks u_format_srgb.py because that script uses its docstring as
> > part of its output, specifically, the copyright notice of the module is
> > copied to the output. If the docstring is stripped, this causes an
> > exception as the __doc__ variable is undefined.
> > > It might also be more reasonable to just drop $(PYTHON_FLAGS) when
> > > using src/gallium/auxiliary/util/u_format_srgb.py so this isn't a
> > > global change.
> > There's really no global effect to dropping the second -O, and it's more
> > consistent to use the same flags for everything. Why introduce a special
> > case?
> Another alternative would be to use a regular string instead of a
> docstring, ie:
> diff --git a/src/gallium/auxiliary/util/u_format_srgb.py
> index 3e8000f..3c49458 100644
> --- a/src/gallium/auxiliary/util/u_format_srgb.py
> +++ b/src/gallium/auxiliary/util/u_format_srgb.py
> @@ -1,6 +1,6 @@
> #!/usr/bin/env python
> +copyright = '''
> * Copyright 2010 VMware, Inc.
> @@ -89,7 +89,7 @@ def main():
> print '/* This file is autogenerated by u_format_srgb.py. Do not
> edit directly. */'
> # This will print the copyright message on the top of this file
> - print __doc__.strip()
> + print copyright.strip()
> print '#include "u_format_srgb.h"'
> It really doesn't affect readability, and avoids this dependency on the
> There are a few other __doc__ uses. If this works for you I can submit a
> patch that fixes them all.
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
'copyright' is a built-in Python variable. The Python documentation suggests not to shadow this variable name.
More information about the mesa-dev