utils.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:crema 作者: bmcfee 项目源码 文件源码
def git_version():
    '''Return the git revision as a string

    Returns
    -------
    git_version : str
        The current git revision
    '''
    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'

        output = subprocess.check_output(cmd,
                                         stderr=subprocess.DEVNULL,
                                         env=env)
        return output

    try:
        out = _minimal_ext_cmd(['git', 'rev-parse', '--verify', '--quiet', '--short', 'HEAD'])
        GIT_REVISION = out.strip().decode('ascii')
    except subprocess.CalledProcessError:
        GIT_REVISION = 'UNKNOWN'

    return GIT_REVISION
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号