开发者

Autofoo test for maximum version of Python

I'm trying to get autofoo to test for a maximum version of Python rather than a minimum. Example:

AC_REQUIRE([AM_PATH_PYTHON([2.7])])

... will test for Python >= 2.7, and will probably turn up with /usr/bin/python3. I want it to return nothing greater than python2.7, however.

Is there a straightforward way to do this? I asked around, and so far the best response I've gotten is, "rewrite the macro."

Than开发者_如何学Pythonks in advance!


1). Add to acinclude.m4

`# my_CHECK_MAJOR_VERSION(VARIABLE, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])`  
`# ---------------------------------------------------------------------------`  
`# Run ACTION-IF-TRUE if the VAR has a major version >= VERSION.`  
`# Run ACTION-IF-FALSE otherwise.`  
AC_DEFUN([my_CHECK_MAJOR_VERSION],  
[AC_MSG_CHECKING([whether $1 $$1 major version == $2])  
case $$1 in  
$2*)  
  AC_MSG_RESULT([yes])  
  ifelse([$3], [$3], [:])  
  ;;  
*)  
  AC_MSG_RESULT([no])  
  ifelse([$4], , [AC_MSG_ERROR([$$1 differs from $2])], [$4])  
  ;;  
esac])  

2.) Add to zconfigure.inz

my_CHECK_MAJOR_VERSION([PYTHON_VERSION], [2])  

3.) aclocal, automake, autoconf

That's it.


The version argument to AM_PATH_PYTHON is optional. If python is required, call it like this:

AM_PATH_PYTHON

If it's not required, call it like this:

AM_PATH_PYTHON(,, [:])

Now, AM_PATH_PYTHON sets the shell variable $PYTHON_VERSION to the value of sys.version[:3], which you can test yourself.


An alternative solution can be setting the default for _AM_PYTHON_INTERPRETER_LIST, to include only Python 2 binaries.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜