[Piglit] [PATCH 04/20] framework: Update import statements to support Python 3.x in addition to 2.x.

Jon Severinsson jon at severinsson.net
Wed Apr 17 06:01:55 PDT 2013

onsdagen den 17 april 2013 11:52:28 skrev du:
> Hi Jon,
> There's a lot going on in this patch, for example:
> 1. Search and replace of, say, ConfigParser with configparser
> 2. try/expect blocks for using both Python 2/3 names for various things
> 3. Modifying the path all over the place.
> 4. Reorganizing imports
> It'd be nice to split this into multiple patches.  I've taken a stab at
> that, and will send that out shortly.  I retained your authorship on the
> patches since you actually wrote 98% of the code in them, so you deserve
> the credit.  Let me know what you think!

Yes, a lot is going on in this patch, but in the context of my twenty-patch 
long series, I though I had found a good middle ground in splitting, but 
apparently not ;-).

Your further split makes sense though, so I'll use it when I resend my updated 
patch series next. However, for the sake of consistency, I'm going to reorder 
some of the updated includes while I'm at it...

> One thing I didn't understand was the change from:
>     os.path.dirname(os.path.realpath(sys.argv[0]))
> to:
>     os.path.dirname(__file__)
> I created a /home/kwg/Projects/piglit/foo.py script and ran it via both
> "python2 foo.py" and "python3 foo.py" and got:
> /home/kwg/Projects/piglit
> (nothing)
> So they don't seem to be the same, and the old code appears to work fine
> on both Python 2 and Python 3.
> I think we can avoid this, however, by using explicit relative imports.
>   I'll send the patch out for that.

Yes, both works in the main files, but only the later works in the framework 
files, and I thought consistency was more important than conservativity.

Of course, explicitly relative imports (I didn't know those existed, thanks) 
in the framework files are even better, so that makes the consistency point 

However, considering PIOSIX allows calling an application with a argv[0] 
unrelated to it's pathname, I think using __file__ is slightly better, but I'll 
move that to a separate patch in the cleanup section of the series.

/ Jon

More information about the Piglit mailing list