apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Stein <gst...@gmail.com>
Subject Re: python3.1
Date Fri, 21 May 2010 05:14:22 GMT
On Fri, May 21, 2010 at 00:23, Philip M. Gollucci
<pgollucci@ridecharge.com> wrote:
> Howdy,
>
> So
> http://docs.python.org/release/3.0.1/whatsnew/3.0.html#porting-to-python-3-0
>
> specifically says not to try to
> if 2.x
>  stuff
> else 3.x
>  other stuff
> fi
>
> Attached is a diff for gen-build.py using 2to3. I'm not exactly sure how
> to fanagle this without duplicating the into 2 files gen-build2.py and
> gen-build3.py.  configure.in would need to me modded to call the right
> one based on the python version.
>
> I'm looking at this specifically b/c
> http://www.freebsd.org/cgi/query-pr.cgi?pr=146621&cat=
>
> Also you need this diff to build/buildcheck.sh
> $ svn diff
> Index: buildcheck.sh
> ===================================================================
> --- buildcheck.sh       (revision 946860)
> +++ buildcheck.sh       (working copy)
> @@ -10,7 +10,7 @@
>  echo "           to build APR from SVN."
>  exit 1
>  else
> -py_version=`python -c 'import sys; print sys.version' 2>&1|sed 's/ .*//;q'`
> +py_version=`python -c 'import sys; print(sys.version)' 2>&1|sed 's/
> .*//;q'`
>  echo "buildconf: python version $py_version (ok)"
>  fi

This patch is safe to apply. In 2.x, you're simply printing a
parenthesized expression. In 3.x, you're invoking the print function.
No problem.

>...

In your patch, everything is safe to apply except for the "import"
changes. For that, I would suggest:

try:
  import ConfigParser from ConfigParser
except ImportError:
  # try the 3.0 equivalent
  import ConfigParser from configparser

and then change the code to simply instantiate ConfigParser() rather
than $x.ConfigParser()

The try/except is a very minor "weirdness" in order to support both
Python versions.

Cheers,
-g

Mime
View raw message