File size: 580 Bytes
4ad9219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""代码版本号:优先读 CGVM_CODE_COMMIT,其次 git,最后 unknown。

集群作业把代码打成 tar 后没有 .git,直接 `git rev-parse HEAD` 会让 Stage0/评测
在执行任何推理之前就崩掉。
"""
import os
import subprocess


def code_commit(root):
    env = os.environ.get('CGVM_CODE_COMMIT')
    if env:
        return env
    try:
        return subprocess.check_output(['git', '-C', str(root), 'rev-parse', 'HEAD'],
                                       text=True, stderr=subprocess.DEVNULL).strip()
    except Exception:
        return 'unknown'