You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Hyrum K Wright <hy...@hyrumwright.org> on 2011/02/16 16:08:39 UTC

Bindings use is *painful*

I'm writing a script in which I simply want to retrieve a set of
arbitrary log message and then do stuff with them.  Using the Python
bindings seemed like the logical choice (whether is was or not is now
debatable, but that isn't the point of this mail).  Turns out that
using the Python bindings is a *painful* experience, for at least the
following reasons (and they may extend to the other swig-generated
bindings, I don't know):

 * This is little to no documentation.  What docs that do exist relate
to the C APIs, and have little bearing on Python types and their
conversions.
 * Because of the above, development with the bindings tends to be by
trial-and-error.
 * The bindings are verbose (client.svn_client_get_log5), and do
little to help the user.
 * They are still very C-like, not using common idioms from the target language.

I don't know how to solve these problems today or tomorrow, and they
may already be old news to many people here.  But to a new user of the
bindings, it sure was a frustrating experience (and I already know the
Subversion C infrastructure!)  I finally gave up and just used the
commandline, piping the results into my processing script.  I feel
sorry for folks trying to use the bindings from scratch.

-Hyrum (who feels better now)

Re: Bindings use is *painful*

Posted by "C. Michael Pilato" <cm...@collab.net>.
On 02/16/2011 10:47 AM, Stefan Sperling wrote:
> Also, there's an API built on top of the bindings that is easier to use
> and has better documentation: http://pysvn.tigris.org/

PySVN isn't built atop our bindings, IIRC.  It's a ground-up rewrite of
Python and CPP that calls directly into our C API.

-- 
C. Michael Pilato <cm...@collab.net>
CollabNet   <>   www.collab.net   <>   Distributed Development On Demand


Re: Bindings use is *painful*

Posted by Julian Foad <ju...@wandisco.com>.
Ramkumar Ramachandra wrote:
> Stefan Sperling writes:
> > On Wed, Feb 16, 2011 at 03:08:39PM +0000, Hyrum K Wright wrote:
> > This is because the bindings are generated with SWIG.
> > We cannot really fix this without using a different approach.
> > 
> > We could improve the documentation. An introductory document that
> > explains how to apply the C API docs to the python bindings would
> > be helpful. Maybe someone with some experience in using the python
> > bindings could write something like this?
> > 
> > Also, there's an API built on top of the bindings that is easier to use
> > and has better documentation: http://pysvn.tigris.org/
> 
> Does it make sense to write bindings ground up by hand and hand-craft
> a nice API? Since the C API is guaranteed to be relatively stable and
> backward compatible, maintainability shouldn't be much of an
> issue. Plus, it'll probably make a good GSoC project.

Isn't that the nature of our Python-Ctypes bindings?  I though that was
hand-crated and more idiomatic to Python and thus "cleaner" to use.

class RemoteRepository(object):

    def log(self, start_rev, end_rev, paths=None, limit=0,
            discover_changed_paths=FALSE, stop_on_copy=FALSE):
        """A generator function which returns information about the revisions
           between START_REV and END_REV. Each return value is a
           csvn.types.LogEntry object which describes a revision.

           For details on what fields are contained in a LogEntry object,
           please see the documentation from csvn.types.LogEntry.

           You can iterate through the log information for several revisions
           using a regular for loop. For example:
             for entry in session.log(start_rev, end_rev):
               print("Revision %d" % entry.revision)
               ...

           ARGUMENTS:

             If PATHS is not None and has one or more elements, then only
             show revisions in which at least one of PATHS was changed (i.e.,
             if file, text or props changed; if dir, props changed or an entry
             was added or deleted). Each PATH should be relative to the current
             session's root.

             If LIMIT is non-zero, only the first LIMIT logs are returned.

             If DISCOVER_CHANGED_PATHS is True, then changed_paths will contain
             a list of paths affected by this revision.

             If STOP_ON_COPY is True, then this function will not cross
             copies while traversing history.

             If START_REV or END_REV is a non-existent revision, we throw
             a SVN_ERR_FS_NO_SUCH_REVISION SubversionException, without
             returning any logs.

        """

- Julian



Re: Bindings use is *painful*

Posted by Hyrum K Wright <hy...@hyrumwright.org>.
On Wed, Feb 16, 2011 at 4:01 PM, Ramkumar Ramachandra
<ar...@gmail.com> wrote:
> Hi,
>
> Stefan Sperling writes:
>> On Wed, Feb 16, 2011 at 03:08:39PM +0000, Hyrum K Wright wrote:
>> This is because the bindings are generated with SWIG.
>> We cannot really fix this without using a different approach.
>>
>> We could improve the documentation. An introductory document that
>> explains how to apply the C API docs to the python bindings would
>> be helpful. Maybe someone with some experience in using the python
>> bindings could write something like this?
>>
>> Also, there's an API built on top of the bindings that is easier to use
>> and has better documentation: http://pysvn.tigris.org/
>
> Does it make sense to write bindings ground up by hand and hand-craft
> a nice API? Since the C API is guaranteed to be relatively stable and
> backward compatible, maintainability shouldn't be much of an
> issue. Plus, it'll probably make a good GSoC project.

We actually do this for Java, creating the JavaHL bindings.  And
really, it isn't that much work (after the initial infrastructure is
built).  They much better support Java idioms than any generated
wrapper could, and the maintenance burden is generally pretty low.

We could still use the swig-generated stuff to create most of the
boiler-plate between $TARGET_LANGUAGE and C, and then implement a
clean API on top of that.  Or we could do something like the
object-model branch, or some other idea.  (And then there are the
backward compat considerations...)

-Hyrum

Re: Bindings use is *painful*

Posted by Ramkumar Ramachandra <ar...@gmail.com>.
Hi,

Stefan Sperling writes:
> On Wed, Feb 16, 2011 at 03:08:39PM +0000, Hyrum K Wright wrote:
> This is because the bindings are generated with SWIG.
> We cannot really fix this without using a different approach.
> 
> We could improve the documentation. An introductory document that
> explains how to apply the C API docs to the python bindings would
> be helpful. Maybe someone with some experience in using the python
> bindings could write something like this?
> 
> Also, there's an API built on top of the bindings that is easier to use
> and has better documentation: http://pysvn.tigris.org/

Does it make sense to write bindings ground up by hand and hand-craft
a nice API? Since the C API is guaranteed to be relatively stable and
backward compatible, maintainability shouldn't be much of an
issue. Plus, it'll probably make a good GSoC project.

-- Ram

Re: Bindings use is *painful*

Posted by Stefan Sperling <st...@elego.de>.
On Wed, Feb 16, 2011 at 03:08:39PM +0000, Hyrum K Wright wrote:
> I'm writing a script in which I simply want to retrieve a set of
> arbitrary log message and then do stuff with them.  Using the Python
> bindings seemed like the logical choice (whether is was or not is now
> debatable, but that isn't the point of this mail).  Turns out that
> using the Python bindings is a *painful* experience, for at least the
> following reasons (and they may extend to the other swig-generated
> bindings, I don't know):
> 
>  * This is little to no documentation.  What docs that do exist relate
> to the C APIs, and have little bearing on Python types and their
> conversions.
>  * Because of the above, development with the bindings tends to be by
> trial-and-error.
>  * The bindings are verbose (client.svn_client_get_log5), and do
> little to help the user.
>  * They are still very C-like, not using common idioms from the target language.
> 
> I don't know how to solve these problems today or tomorrow, and they
> may already be old news to many people here.  But to a new user of the
> bindings, it sure was a frustrating experience (and I already know the
> Subversion C infrastructure!)  I finally gave up and just used the
> commandline, piping the results into my processing script.  I feel
> sorry for folks trying to use the bindings from scratch.
> 
> -Hyrum (who feels better now)

This is because the bindings are generated with SWIG.
We cannot really fix this without using a different approach.

We could improve the documentation. An introductory document that
explains how to apply the C API docs to the python bindings would
be helpful. Maybe someone with some experience in using the python
bindings could write something like this?

Also, there's an API built on top of the bindings that is easier to use
and has better documentation: http://pysvn.tigris.org/

Re: Bindings use is *painful*

Posted by André Malo <nd...@perlig.de>.
* Hyrum K Wright wrote:

> I'm writing a script in which I simply want to retrieve a set of
> arbitrary log message and then do stuff with them.  Using the Python
> bindings seemed like the logical choice (whether is was or not is now
> debatable, but that isn't the point of this mail).  Turns out that
> using the Python bindings is a *painful* experience,

Back then, when using them, I often ended up looking through the generated 
swig sources to get essential information about how exactly something was 
mapped. So it was basically about at least 4 editor windows on the screen: 
my script, some header file(s), the generated swig sources, the 
implementation of the mapped function(s).

It was painful, yes, but also fascinating. I learned a lot about the whole 
subversion code ;-)
Granted, that's not helpful if you just want to get something done fast...

nd
-- 
>kann mir jemand sagen, was genau @-Domains sind?
Ein Mythos. Ein Werbetrick. Verarsche. Nenn es wie du willst...

                 -- Alexandra Buss und Björn Höhrmann in dciwam

Re: Bindings use is *painful*

Posted by John Szakmeister <jo...@szakmeister.net>.
Subvertpy might be a useful alternative as well.  Jelmer wrote them
for the same reason... the swig ones just weren't very Pythonic:
   <https://launchpad.net/subvertpy>

-John

On Wed, Feb 16, 2011 at 10:08 AM, Hyrum K Wright <hy...@hyrumwright.org> wrote:
> I'm writing a script in which I simply want to retrieve a set of
> arbitrary log message and then do stuff with them.  Using the Python
> bindings seemed like the logical choice (whether is was or not is now
> debatable, but that isn't the point of this mail).  Turns out that
> using the Python bindings is a *painful* experience, for at least the
> following reasons (and they may extend to the other swig-generated
> bindings, I don't know):
>
>  * This is little to no documentation.  What docs that do exist relate
> to the C APIs, and have little bearing on Python types and their
> conversions.
>  * Because of the above, development with the bindings tends to be by
> trial-and-error.
>  * The bindings are verbose (client.svn_client_get_log5), and do
> little to help the user.
>  * They are still very C-like, not using common idioms from the target language.
>
> I don't know how to solve these problems today or tomorrow, and they
> may already be old news to many people here.  But to a new user of the
> bindings, it sure was a frustrating experience (and I already know the
> Subversion C infrastructure!)  I finally gave up and just used the
> commandline, piping the results into my processing script.  I feel
> sorry for folks trying to use the bindings from scratch.
>
> -Hyrum (who feels better now)
>