On Wednesday 11 March 2015 15:08:32 Jean-Marc Lasgouttes wrote:
> Dear José,
>
> I took a quick look and I need help. The complicated macro for python
> eventually calls:
>
> # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE],
> [ACTION-IF-FALSE])
> #
> ---------------------------------------------------------------------------
> # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
> # Run ACTION-IF-FALSE otherwise.
> # This test uses sys.hexversion instead of the string equivalent (first
> # word of sys.version), in order to cope with versions such as 2.2c1.
> # This supports Python 2.0 or higher. (2.0 was released on October 16,
> 2000).
> AC_DEFUN([AM_PYTHON_CHECK_VERSION],
> [prog="import sys
> # split strings by '.' and convert to numeric. Append some zeros
> # because we need at least 4 digits for the hex conversion.
> # map returns an iterator in Python 3.0 and a list in 2.x
> minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]]
> minverhex = 0
> # xrange is not present in Python 3.0 and range returns an iterator
> for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]]
> sys.exit(sys.hexversion < minverhex)"
> AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])
>
>
> Of course this is horrible autoconf code, but in the middle your can see
> some nice python code, that returns true or false depending on whether
> the version is greater in $2 (the one in the python code).
>
> Now, assume that I want to define
> # AM_PYTHON23_CHECK_VERSION(PROG, VERSION2, VERSION3, [ACTION-IF-TRUE],
> [ACTION-IF-FALSE])
>
> Could you give me the python code (that now relies on $2 and $3) that
> will return the right result? If you prefer to check by function (is
> such or such feature available?), I will probably be able to do
> something with it too.
>
> JMarc
The code attached does this. For the moment I am ignoring the arguments $2 and
$3.
The plan is to have code that supports both versions either 2.7.x (eventually
2.6 if some kind soul tests thoroughly) and 3.3+.
So the code returns 1 if the python version is in the needed range and 0 if it
is not.
Regards,
--
José Abílio
import sys
version = sys.version_info[:3]
sys.exit((2,7,0) <= version < (3,0,0) or version >= (3,3,0))