find_version.py 3.56 KB
Newer Older
fengzch-das's avatar
fengzch-das committed
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import sys
import subprocess
from datetime import date
import os

UNKNOWN = "Unknown"

def dtk_version_value():
    try:
        dtk_path=os.getenv('ROCM_PATH')
        dtk_version_path = os.path.join(dtk_path, '.info', "version-dev")
        with open(dtk_version_path, 'r',encoding='utf-8') as file:
            lines = file.readlines()
        dtk_version="dtk"+lines[0][:].replace(".", "")
        return dtk_version
    except Exception:
       return UNKNOWN

def opencv_whl_name():
    try:
        if (os.getenv('DAS_VERSION')):
            das_version=str(os.getenv('DAS_VERSION'))
        else:
            das_version= "1.1"
        if (os.getenv('OPT_VERSION')):
            opt_version=str(os.getenv('OPT_VERSION'))
        else:
            opt_version= "1"
        whl_name = "das"+ "." + "opt" + opt_version
        return whl_name
    except Exception:
        return UNKNOWN

if __name__ == "__main__":
    contrib = sys.argv[1]
    headless = sys.argv[2]
    rolling = sys.argv[3]
    ci_build = sys.argv[4]

    opencv_version = ""
    # dig out the version from OpenCV sources
    version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp"

    with open(version_file_path, "r") as f:
        for line in f:
            words = line.split()

            if "CV_VERSION_MAJOR" in words:
                opencv_version += words[2]
                opencv_version += "."

            if "CV_VERSION_MINOR" in words:
                opencv_version += words[2]
                opencv_version += "."

            if "CV_VERSION_REVISION" in words:
                opencv_version += words[2]
                break

    # # used in local dev releases
    # git_hash = (
    #     subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
    #     .splitlines()[0]
    #     .decode()
    # )
    # # this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
    # try:
    #     tag = (
    #         subprocess.check_output(
    #             ["git", "describe", "--tags"], stderr=subprocess.STDOUT
    #         )
    #         .splitlines()[0]
    #         .decode()
    #         .split("-")
    #     )
    # except subprocess.CalledProcessError as e:
    #     # no tags reachable (e.g. on a topic branch in a fork), see
    #     # https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything
    #     if e.output.rstrip() == b"fatal: No names found, cannot describe anything.":
    #         tag = []
    #     else:
    #         print(e.output)
    #         raise

    # if len(tag) == 1:
    #     # tag identifies the build and should be a sequential revision number
    #     version = tag[0]
    #     opencv_version += ".{}".format(version)
    # # rolling has converted into string using get_and_set_info() function in setup.py
    # elif rolling == "True":
    #     # rolling version identifier, will be published in a dedicated rolling PyPI repository
    #     version = date.today().strftime('%Y%m%d')
    #     opencv_version += ".{}".format(version)
    # else:
    #     # local version identifier, not to be published on PyPI
    #     version = git_hash
    #     opencv_version += "+{}".format(version)

    opencv_version += f"+{opencv_whl_name()}.{dtk_version_value()}"

    with open("cv2/version.py", "w") as f:
        f.write('opencv_version = "{}"\n'.format(opencv_version))
        f.write("contrib = {}\n".format(contrib))
        f.write("headless = {}\n".format(headless))
        f.write("rolling = {}\n".format(rolling))
        f.write("ci_build = {}".format(ci_build))