[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Merging Ctypes Python Branch

From: Sage La Torra <sagelt_at_gmail.com>
Date: 2007-09-04 18:24:48 CEST

On 9/4/07, Ben Collins-Sussman <sussman@red-bean.com> wrote:
> On 8/30/07, Sage La Torra <sagelt@gmail.com> wrote:
>
> > To summarize what the branch is (and what it does):
> > The Ctypes Python bindings use the python ctypes module to wrap the
> > subversion API. This binding is cleaner and more python-ish then the
> > existing SWIG binding. The binding provides a python interface for all
> > of the subversion API, as well as providing classes to wrap much of
> > the most used functionality. Included in the branch is a brand new
> > test suite, which tests the new classes, including utility classes.
>
> Just curious: for those of us ignorant of bindings, can you paste
> some code snippet examples? I'd like to see what a code snippet
> currently looks like using our SWIG python bindings, and how much
> cooler it looks using the ctypes bindings instead. :-)
>
Sure! Here's a couple of quick examples:

This code snippet grabs log messages from a repository. While not
exactly the same, they have the same intent: get log messages for
specified revisions.

SWIG:
def addLog(paths, revision, author, date, message, pool):
      if paths is not None:
        logs.append(paths)

# Run get_logs
repos.get_logs(self.repos, ['/'], self.rev, 0, True, 0, addLog)

Ctypes:
# Use defaults for most arguments
logs = repos.log(start_rev, end_rev, '/')
# logs is an iter object, so we can now iterate over log messages

The things I like about this code: better use of python features
(default arguments, iterators, etc.), a little more 'magic' 9as much
as I dislike calling it that) in things like handling a list of paths
(the ctypes binding will make a single item into a list as needed).

Here's another example.

SWIG:
rev = core.svn_opt_revision_t()
rev.kind = core.svn_opt_revision_head

path = os.path.join(tempfile.gettempdir(), 'checkout')
client.checkout2(REPOS_URL, path, rev, rev, True, True, self.client_ctx)

Ctypes:
path = os.path.join(tempfile.gettempdir(), 'checkout')
wc = WC(path)
wc.checkout(REPOS_URL)

One thing that's really cool in this example: the python coder no
longer has to keep track of their client context (svn_client_ctx_t),
it's a built in part of the high level classes. if the user wanted to
do something not included in the classes (since ctypes exposes the
entire API but only parts of it are covered by the classes) they might
have to keep their own client. Additionally, the checkout method has
defaults for most of the arguments, so for a fairly standard checkout
like this one the coder can just rely on the defaults.

In general, when using the classes the user's experience should be
much better. For example, the ctypes WC class keeps track of where the
wc is, so the user doesn't have to keep on specifying the same path
for many operations. In the above example, since the WC instance was
created with a given path, the checkout will default to using that
path.

Anyway, those are a couple of examples of how I feel the ctypes
binding is better. Hope that gives you some idea of what's going on.

Sage

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Sep 4 18:21:42 2007

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.