8

I'm looking for a Python library that can do basic manipulation of repositories, but is independent of the backend version control system.

By basic manipulation, I'm referring to: initialize a repo, add files, commit, pull, push, get current revision number.

Users of the library could do something this:

import dvcs_wrapper as dvcs
dvcs.set_backend('hg')  # could choose 'git', 'bzr'

repo = dvcs.init('/home/me/my_repo')
repo.add('/home/me/my_repo/*.py')
repo.commit('Initial commit')
repo.push('http://bitbucket.org/....')
print('At revision %d' % repo.revision_num)

Any pointers to something like the above? My Google searches turn up nothing...

Update: for what it's worth, I've started working on something like this: code is here with unit tests for Hg repositories. I might get around to Git and Bazaar; contributions welcome.

Kevin Dunn
  • 244
  • 2
  • 6
  • What's the use case for this? Assuming I have Python libraries for accessing SVN, Mercurial, and Bazaar (which I do) what does this library do for me? The above script doesn't really seem like something you're going to reuse. – stderr May 10 '11 at 04:01
  • Makes sense for me for fabric-based installation of a variety of sub-repos, that may be different dvcs. I currently convert everything to hg, but a generic wrapper would be useful. – Matthew Schinckel May 10 '11 at 05:08
  • 1
    @Mike - the use case is Django code powering a code snippet website. Snippets are revised by the web users and stored in a VCS to track history. Website operators using this code might prefer one DVCS over another. Another use case I had last year was software for document management (writing books in reStructuredText). Some authors prefer Git over Hg over Bazaar, etc. I prefer writing the code once, and they can choose their DVCS in the software settings. – Kevin Dunn May 10 '11 at 11:08

2 Answers2

5

There's also the VCS module, which advertises:

vcs is abstraction layer over various version control systems. It is designed as feature-rich Python library with clean API.

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
RyanWilcox
  • 13,890
  • 1
  • 36
  • 60
  • thanks for the pointer. Their documentation indicates they have Git and Mercurial backends already - exactly the two I need! – Kevin Dunn May 12 '11 at 00:19
4

I think you are out of luck.

There are Python wrappers for git but according to this the quality is still less than optimal. Hg and bzr are Python projects but their infrastructure is quite different, so API level integration is not easy. Also different SCMs have different design philosophies, which makes a unified wrapper less plausible.

That being said, if you do need a simple wrapper, you can use the subprocess module and wrap the command lines to get the result you want.

Community
  • 1
  • 1
Wang Dingwei
  • 4,661
  • 6
  • 32
  • 43
  • that's the answer I was hoping not to hear! I finished the Mercurial wrapper for a project (https://bitbucket.org/kevindunn/ucommentapp/src/c0b839e548b7/hgwrapper.py) using `subprocess`, I guess I will have to write the wrappers for Git and Bazaar using a similar command-line approach – Kevin Dunn May 10 '11 at 11:15
  • @Kevin Are you going to make your wrapper available when it is done (e.g. on github)? – Judge Maygarden May 11 '11 at 15:33
  • @Judge: absolutely! A basic wrapper for Hg with some unit tests is available already - see the links in the original question above (under the **Update** section). But I just saw @RyanWilcox's post below about [VCS](http://packages.python.org/vcs/), which seems to do what I want. About to test it myself now ... – Kevin Dunn May 12 '11 at 00:16