[vtkusers] VTK Python3 support

David Gobbi david.gobbi at gmail.com
Tue Mar 10 09:37:42 EDT 2015


Hi All,

I think that it is a very good point that py3k support is needed in
order for vtk-python to move forward as a teaching tool for new
students.  We're actually very lucky that the scientific computing
community has decided to stick with python, because moving
to a whole new language would be _really_ tough.

As far as the wrappers go, currently the C++ PyVTKClass and
PyVTKObject extension types provide an old-style (python 1.5)
metaclass mechanism.  Moving forward, each VTK class can
be its own extension type... I looked at the wrapper code over
the weekend, and it's a few days' work that I can probably get
done sometime in May or June.

After that, the wrappers will have to be modified to handle the
changes that py3k made to PyInt and PyLong, and then all the
necessary #ifdefs will have to be added so that both py2 and
py3k versions of the wrappers will compile.

Fortunately, VTK has an abundance of python tests, including
many tests in Common/Core/Testing/Python for special features
of the wrappers.  So I don't think we're likely to break anything
(e.g. numpy support) in the transition.

 - David

On Tue, Mar 10, 2015 at 5:55 AM, Berk Geveci <berk.geveci at kitware.com>
wrote:

> Hi Arnd,
>
> Your assessment sounds in the right ballpark. I don't foresee more issues.
> In fact, most of the Python code in VTK is in the testing suite. I'd hope
> that any errors there would be caught easily. The huge majority of
> non-testing Python code is in Wrapping/Python/vtk, which is something like
> 40 files. I volunteer taking care of most of those files. I am pretty sure
> that we can find volunteers to fix the tests. So upgrading the Python files
> is really not that hard. Wrapping is the main challenge.
>
> Best,
> -berk
>
>
> On Tue, Mar 10, 2015 at 3:45 AM, Arnd Baecker <arnd.baecker at web.de> wrote:
>
>> As a follow-up concerning the conversion of the .py files:
>> I have run the current 6.2 release through pylint
>> with --py3k option.
>>
>> Excluding everything from the ThirdParty directory
>> (which for example contains Twisted 14.0.0 which
>> is not yet ported to Python 3)
>> this is only approx 780 python files.
>>
>> One gets a total of 3130 violations spread over 745 files.
>>
>> Out of these there are:
>> - 2325 violations W1618
>>   (missing `from __future__ import absolute_import`)
>>   Adding this line actually might not be necessary, it just indicates
>>   that this behaviour is the default on python 3.
>> - 552 violations E1601
>>   print statement.
>>   This can be easily solved using
>>    from __future__ import print_function
>>   and converting all print-statements to  print(...)
>> - 53 violations  E1604
>>   syntax change in raise
>>
>> So this leaves some further 200 violations spread over 72 files.
>> These have to be looked at individually.
>> Several warn about the change in division
>> (which can be solved using ``from __future__ import division``
>> and using // instead of the current usage of /.
>>
>> Overall that part seems doable with reasonable effort
>> (But maybe I am seeing things too optimistic
>> or I am overlooking something ...).
>> In the end this would mean that all examples and tests
>> could (in principle) be run both on python 2 and python 3
>> without any further code changes.
>> Moreover, ThirdParty already contains SixPython
>> which could be used if there are changes like range vs. xrange etc.
>>
>> Are there automatic tests runs
>> a) for the python code?
>> b) to determine code-coverage for VTK
>>    (including the python side)?
>> This would help to prevent any regression
>> during the above steps.
>>
>> Concerning the first two points of David:
>>
>>> 1) VTK wrapping still uses old-style classes.  I've been meaning to fix
>>> this.
>>> 2) Basic compile issues and cross-compatibility for py3 and py2 -
>>>    we received a patch that fixes some of these issues.
>>>
>> I have no clue how much work this is...
>>
>> Best, Arnd
>>
>> _______________________________________________
>> 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 VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150310/bc6e31c6/attachment.html>


More information about the vtkusers mailing list