On 21. Jul, 2010, at 18:59 , Alan W. Irwin wrote:
> On 2010-07-21 08:50-0700 Alan W. Irwin wrote:
>
>> To draw this subthread to a definite conclusion, here is what works
>> for me now to get python version for either python2 or python3.
>>
>> softw...@raven> python -c \
>> 'import sys; print("%s.%s.%s" % sys.version_info[0:3])'
>> 2.6.5
>>
>> softw...@raven> python3 -c \
>> 'import sys; print("%s.%s.%s" % sys.version_info[0:3])'
>> 3.1.2
>>
>> So I would recommend this command form to determined the python
>> version corresponding to the found interpreter for CMake.
>
> Hmm. It turns out you have to swap double and single quotes to get
> this to work from cmake. So here (subject to my mailer wrapping the
> lines) is what PLplot uses now:
>
> # Get the Python version.
> execute_process(
> COMMAND
> ${PYTHON_EXECUTABLE} -c "import sys; print('%s.%s.%s' %
> sys.version_info[0:3])"
> OUTPUT_VARIABLE PYTHON_VERSION
> OUTPUT_STRIP_TRAILING_WHITESPACE
> )
> message(STATUS "PYTHON_VERSION = ${PYTHON_VERSION}")
>
> Alan
Wouldn't using
import sys; sys.stdout.write('%s.%s.%s\n' % sys.version_info[0:3])
be safer? Because for python < 3 the parenthesis are grouping an expression,
not surrounding a list of arguments. This is no problem as long as nobody adds
a "," inside the parenthesis, because then the thing would become a tuple
constructor.
Michael
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake