File size: 1,022 Bytes
47aff61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# coding: utf-8
# Copyright (c) 2025 inclusionAI.

import os
import getpass
import time

__version__ = '0.2.2'

version_template = \
    """# auto generated
class VersionInfo:
    BUILD_DATE = "{BUILD_DATE}"
    BUILD_VERSION = "{BUILD_VERSION}"
    BUILD_USER = "{BUILD_USER}" 
    SCENARIO = "{SCENARIO}"
"""


def generate_version_info(directory_path: str = None, scenario: str = "", version: str = None):
    if directory_path is None:
        directory_path = os.path.dirname(__file__)
    with open(os.path.join(directory_path, "version_info.py"), "w") as f:
        version_info = _build_version_template(scenario=scenario, version=version)
        f.write(version_info)


def _build_version_template(scenario: str = "", version: str = None) -> str:
    if version is None:
        version = __version__
    return version_template.format(
        BUILD_USER=getpass.getuser(),
        BUILD_VERSION=version,
        BUILD_DATE=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
        SCENARIO=scenario,
    )