threads / discuss / 13425

Using git from Python

Subject: Using git from Python

## tl;dr

7 messages between May 8, 2008 and May 14, 2008.

replies: 6people: 5as markdown or json

Asheesh Laroia· May 8, 2008, 00:18 UTC · lore
>From a Python app, I want to read and write a git repository.  It seems 

from Luiz Fernando's post at http://blog.cpu.eti.br/?p=91 that the efforts to Pythonize libgit have stalled.

On #git, I was advised to simply call the git command suite. That's fine, and I can do it using the subprocess module in Python - but since I figured others may have done this also, does anyone know of a Python module that wraps some git commands? I'm thinking if others have gone down this path, they might have code that e.g. raises Exceptions when the git commands fail for some reason.

What have others on this list done lately for using git from Python?
-- Asheesh.
-- 
You will reach the highest possible point in your business or profession.
Eric Hanchrow· May 8, 2008, 03:54 UTC · re: Asheesh Laroia · lore

Re: Using git from Python

>>>>> "Asheesh" == Asheesh Laroia <asheesh@asheesh.org> writes:
    Asheesh> On #git, I was advised to simply call the git command
    Asheesh> suite.  
That's what I'd do ...  (I wonder if it was me who so advised you :-)
    Asheesh> That's fine ... but since I figured others may have done
    Asheesh> this also
As far as I can tell, there is exactly no downside to simply forking a
subprocess.  Why are you trying to avoid that?
                      
    Asheesh> raises Exceptions when the git commands fail for some
    Asheesh> reason.

If Popen doesn't already raise an exception when the child process fails, then it's surely a simple matter to check the exit code, and raise the exception yourself.

-- 
I write [from 5 AM to 7 AM] to discover what I think.  After
all, the bars aren't open that early.
        -- Daniel Boorstin, former Librarian of Congress
David Aguilar· May 8, 2008, 04:23 UTC · re: Eric Hanchrow · lore

Re: Using git from Python

On Wed, May 7, 2008 at 8:54 PM, Eric Hanchrow <offby1@blarg.net> wrote:
Show 13 quoted lines
>     Asheesh> That's fine ... but since I figured others may have done
>     Asheesh> this also
>
>  As far as I can tell, there is exactly no downside to simply forking a
>  subprocess.  Why are you trying to avoid that?
>
>     Asheesh> raises Exceptions when the git commands fail for some
>     Asheesh> reason.
>
>  If Popen doesn't already raise an exception when the child process
>  fails, then it's surely a simple matter to check the exit code, and
>  raise the exception yourself.
>

There have been many questions about this lately. For the impatient, grab git.py from the python-git directory of the ugit project:

http://repo.or.cz/w/ugit.git?a=tree;f=python-git;h=1ef75cef116ce750b5bdf5dd38a4cf1ab2c1ce79;hb=b393c428cf156a7c5c75b18379676dbb534a76d8
http://repo.or.cz/w/ugit.git

I will work on making git.py a separate python-git project, upload it to pypi, and create a separate repo for it very soon.

The interface is blazingly simple. It is a 1:1 correspondance to the git command line interface. e.g. git.commit(F='/some/path.txt', s=True)

There are many examples in the t/ directory and within the ugit project itself. Let me know offline if you have any questions. The documentation could probably use some work.

-- 
 David
Dill· May 10, 2008, 06:52 UTC · re: Asheesh Laroia · lore

Re: Using git from Python

Also check out: http://gitorious.org/projects/git-python/
Asheesh Laroia wrote:
Show 21 quoted lines
> From a Python app, I want to read and write a git repository.  It seems
> from Luiz Fernando's post at http://blog.cpu.eti.br/?p=91 that the efforts
> to Pythonize libgit have stalled.
>
> On #git, I was advised to simply call the git command suite.  That's fine,
> and I can do it using the subprocess module in Python - but since I
> figured others may have done this also, does anyone know of a Python
> module that wraps some git commands?  I'm thinking if others have gone
> down this path, they might have code that e.g. raises Exceptions when the
> git commands fail for some reason.
>
> What have others on this list done lately for using git from Python?
>
> -- Asheesh.
>
> --
> You will reach the highest possible point in your business or profession.
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Asheesh Laroia· May 12, 2008, 18:17 UTC · re: Dill · lore

Re: Using git from Python

On Fri, 9 May 2008, Dill wrote:
> Also check out: http://gitorious.org/projects/git-python/

That looks very friendly and object-oriented. It doesn't seem to have write support, based on a quick look - is that right? Is write support a feature you're considering adding?

-- Asheesh.
-- 
Is a person who blows up banks an econoclast?
Steve Frécinaux· May 13, 2008, 07:39 UTC · re: Asheesh Laroia · lore

Re: Using git from Python

Hi,

It is very fun, because I started my own project ten days ago with similar goals: making python bindings for git. Since I didn't have much imagination at that time, I called it "pygit", eventually renaming it later with a better name.

While being quite similar to git-python at first glance, its primary goal is to feel as pythonic as possible, and to be suitable for porcelainish scripts (in such, it is quite low-level wrt the operations it allows, and has repository writing at the top of its todo list)...

Despite it seems a bit older than gitpython if you look at the commit history, it seems less mature, probably because it's written mostly from scratch and not a raw port of the ruby bindings. For instance, docs are still missing, which is why I didn't announce it to this list yet. It seems it is roughly on par with git-python feature-wise, though.

I hope you'll like this one too ;-)
Ah, I forgot: here it is: http://code.istique.net/?p=pygit.git
(If you get an error, try reloading the page, the server gets crappy sometimes)
PS. Comments welcome.
On Mon, May 12, 2008 at 8:17 PM, Asheesh Laroia <asheesh@asheesh.org> wrote:
Show 9 quoted lines
> On Fri, 9 May 2008, Dill wrote:
>
>
> > Also check out: http://gitorious.org/projects/git-python/
> >
>
>  That looks very friendly and object-oriented.  It doesn't seem to have
> write support, based on a quick look - is that right?  Is write support a
> feature you're considering adding?
Steve Frécinaux· May 14, 2008, 06:10 UTC · lore

Re: Using git from Python

On Tue, May 13, 2008 at 10:50 PM, Todd Zullinger <tmz@pobox.com> wrote:
Show 6 quoted lines
> Hi Steve,
>
> I saw that you started some python bindings for git and thought I'd
> take a peak (even though I don't have a need for such a thing at the
> moment :).  I notice that the COPYING file is GPLv2, but the comments
> in all the files say License: LGPL 2.  Which one is incorrect?

Mmh. The LGPL one. I think I've copied the wrong file in and forgot to double-test ;-)

← back to recent threads