import os.path
release = False
__version__ = '0.1'

_repository_path = os.path.split(__file__)[0]
_svn_file_path = os.path.join(_repository_path, '__svn_version__.py')

def get_svn_revision():
    '''
    Gets the "global" SVN revision number for the repository, using the
    path to this file.
    '''
    from subprocess import Popen, PIPE
    rev = ''
    try:
        proc = Popen(['svnversion', '-n', _repository_path], stdout=PIPE)
        text = proc.stdout.readline()
        if text != 'exported':
            if ':' in text:
                text = text[text.find(':')+1:]
            rev = '.dev' + text
    except OSError:
        # SVN not installed, don't worry about finding the revision
        pass
    return rev

def write_svn_version():
    'Write the SVN revision to a file.'
    svnfile = open(_svn_file_path, 'w')
    svnfile.write('rev = "%s"\n' % get_svn_revision())
    svnfile.close()

def get_version():
    '''
    Get the version of the package, including the SVN revision if this
    is an actual release.
    '''
    version = __version__
    if not release:
        try:
            import __svn_version__
            version += __svn_version__.rev
        except ImportError:
            version += get_svn_revision()
            pass
    return version

import os.path
import subprocess
release = False
__version__ = '0.1'


_repository_path = os.path.split(__file__)[0]
_git_file_path = os.path.join(_repository_path, '__git_version__.py')


def _minimal_ext_cmd(cmd):
    # construct minimal environment
    env = {}
    for k in ['SYSTEMROOT', 'PATH']:
        v = os.environ.get(k)
        if v is not None:
            env[k] = v
    # LANGUAGE is used on win32
    env['LANGUAGE'] = 'C'
    env['LANG'] = 'C'
    env['LC_ALL'] = 'C'
    out = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
    return out

def get_git_hash():
    '''
    Gets the last GIT commit hash and date for the repository, using the
    path to this file.
    '''
    try:
        out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
        GIT_REVISION = out.strip().decode('ascii')
    except:
        GIT_REVISION = None

    return GIT_REVISION

def get_git_revision():
    hash = get_git_hash()
    if hash :
        rev = '.dev.' + hash[:7]
        try:
            cmd = ['git', 'show', '%s' % (hash), '--date=short',
                   '--format="(%ad)"']
            date = _minimal_ext_cmd(cmd).split('"')[1]
            rev += date
        except:
            pass
    else:
        rev = ".dev.Unknown"

    return rev

def write_git_version():
    'Write the GIT revision to a file.'
    rev = get_git_revision()
    if rev == ".dev.Unknown":
        if os.path.isfile(_git_file_path):
            return
    gitfile = open(_git_file_path, 'w')
    gitfile.write('rev = "%s"\n' % rev)
    gitfile.close()


def get_version():
    '''
    Get the version of the package, including the GIT revision if this
    is an actual release.
    '''
    version = __version__
    if not release:
        try:
            import __git_version__
            version += __git_version__.rev
        except ImportError:
            version += get_git_revision()
    
    return version

Convert this file to one that uses GIT instead of SVN. This is a modified version of the Numpy versioning routine.