> In this case, Cython shines -- you can write those thick wrapper is a very
> Python-like language -- work with Python types natively, etc -- really nice.
>
> But you do end up with a lot of boilerplate to write, yes. As I said, I tend
> to want to write thick wrapper,s which require boilerplate anyway, so not so
> bad.
+1 to all of this.
Cython isn't a wrapper-generator. It's a tool that lets you invoke
C/C++as if from Python, which of course can be used to write wrappers
if desired (though often you want to simply use a library, not
necessarily wrap it).
> And aside from the boredom factor, you need to carefully work through
> everything to write tests, etc, so it's not all that much more work.
>
> I'd take a look at XDress too -- automatically writes Cython wrappers around
> C++ code -- best of both worlds! It looked really promising -- but alas,
> doesn't look like it's being actively developed :-(
>
>
https://github.com/xdress/xdress
See also
https://github.com/cython/cython/wiki/AutoPxd .
Unfortunately, there's no solid, actively developed solution for
automatically wrapping C++ in Python (with or without Cython)--all
require a fair amount of handholding/boilerplate for anything
non-trivial, though with Cython you can use this opportunity to craft
thick yet efficient bindings that span the impedance mismatch between
a typical C++ API and a natural, Pythonic one (which mismatch may be
part of the inherently difficulty in automatically wrapping C++).
> I think it comes down to how thick you want your wrappers to be.....
>
> And/or how much of the API you need to expose -- sometimes there is a lot
> going on under the hood, but you only need Python to talk to a higher level
> setup-the-model-and-run API.
And, looking at TAsK itself, this would likely be the case. The
primary user "API" for TAsK is to compile the binary and invoke it
with a set of text file inputs. Were I wrapping this library, I would
probably focus on a nice, Pythonic API for building up the
configuration (possibly with nice validation), and then run it by
spitting out the config as temporary files in the expected format,
invoking TAsK via subprocess, and the reading the results back in.
One could go a step further, essentially implementing
https://github.com/olga-perederieieva/TAsK/blob/master/src/main.cpp in
Cython (declaring just enough of the API do to so), but that may
involve changes to TAsK itself as the assumption that input and
outputs are via physical files seems pretty baked in. It's also
unclear what the benefit would be.
(If you're trying to wrap/expose the internal implementation details,
that's a different story and the more generic comments above are more
relevant).
- Robert