[liblouis-liblouisxml] Re: Python bindings for liblouisxml

  • From: Michael Whapples <mwhapples@xxxxxxx>
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Thu, 26 Nov 2009 15:14:20 +0000

Hello,
Quick explanation of how cython and ctypes differ. Cython is a python like language based on pyrex, and so you actually create a standard python C extension, it just saves you having to use C syntax. As cython compiles it to C first, you can do nearly anything you could do in a standard python C extension, this includes detecting compile time stuff, including headers, etc. Its for this reason my bindings can work between python and liblouisxml using different unicode sizes. Ctypes does some clever stuff as your code is all python code and need not be compiled before release, it works out how to call the C library you are using at runtime. This has the advantage of being used from a python interactive shell but comes at the cost that you can't detect some things in header files (eg. the size of widechar). I guess you could do what the liblouis bindings do for tracking the library file name and have part of the build file insert the information and then use that to define how to encode and decode from widechar. Somehow this modifying source in a build file doesn't seem to sit with me very well (possibly I just worry about the possibility that the build process fails or worse goes wrong but shows no error and leaves you with a nonsense python file). I think that is the main things relevant here, there are other uses for cython but they aren't relevant (eg. creating a C extension to speed up part of a python application but without you needing to write any C or I believe it is possible to use cython to embed python in a C application).

I was going to ask about how I would maintain the bindings if they are in liblouisxml's SVN. There are some immediate things I feel need dealing with, making them more natural to use in python3, eg. string in python2.x was like char in C (just single bytes) but string in python3 is unicode and so for some calls you need to use bytes (like for translation table name), a string would be more natural. In some ways these changes are only cosmetic, they can still be used fully in python3, the code using them may just look a bit odd.

Michael Whapples
On 26/11/09 12:26, Christian Egli wrote:
Hi Michael

No, I haven't tried the bindings for liblouisxml (yet). If I'd try them
it would be on Linux. If have simply looked at the source. That answered
one of my questions regarding the license: The artistic license 2.0 is
compatible with GPL and even allows for relicensing into it, so I'm fine
with it.

On Wed, 2009-11-25 at 16:34 +0000, Michael Whapples wrote:
I have my view about using ctypes for the liblouis python bindings,
ctypes is fine for a quick try of something but not so good for the
long term (eg. ctypes is unable to tell whether liblouis uses ucs2 or
ucs4 for widechar and so relies on python and liblouis being matched,
cython can tell this, admittedly only at compile time).
That seems to answer the other question I had: They do use different
technology (ctypes and cython) but cython is apparently better.

Now for me the question is: does it make sense to maintain the bindings
within liblouisxml svn? I think it does, but if so then we should
probably 1) integrate it in the build system and 2) give you commit
access to liblouisxml svn.

Thoughts?

Christian

For a description of the software and to download it go to
http://www.jjb-software.com

Other related posts: