update_version.py 833 Bytes
Newer Older
赵小蒙's avatar
赵小蒙 committed
1
2
3
4
5
6
7
8
9
import os
import subprocess


def get_version():
    command = ["git", "describe", "--tags"]
    try:
        version = subprocess.check_output(command).decode().strip()
        version_parts = version.split("-")
10
        if len(version_parts) > 1 and version_parts[0].startswith("mineru"):
赵小蒙's avatar
赵小蒙 committed
11
12
            return version_parts[1]
        else:
13
            raise ValueError(f"Invalid version tag {version}. Expected format is mineru-<version>-released.")
赵小蒙's avatar
赵小蒙 committed
14
15
16
17
18
19
    except Exception as e:
        print(e)
        return "0.0.0"


def write_version_to_commons(version):
20
    commons_path = os.path.join(os.path.dirname(__file__), 'mineru', 'version.py')
赵小蒙's avatar
赵小蒙 committed
21
    with open(commons_path, 'w') as f:
赵小蒙's avatar
赵小蒙 committed
22
23
24
25
26
27
        f.write(f'__version__ = "{version}"\n')


if __name__ == '__main__':
    version_name = get_version()
    write_version_to_commons(version_name)