|
3 | 3 | import subprocess |
4 | 4 |
|
5 | 5 | if __name__ == "__main__": |
6 | | - contrib = sys.argv[1] |
7 | | - headless = sys.argv[2] |
8 | | - ci_build = sys.argv[3] |
9 | | - |
10 | | - opencv_version = "" |
11 | | - # dig out the version from OpenCV sources |
12 | | - version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp" |
13 | | - |
14 | | - with open(version_file_path, 'r') as f: |
15 | | - for line in f: |
16 | | - words = line.split() |
17 | | - |
18 | | - if "CV_VERSION_MAJOR" in words: |
19 | | - opencv_version += words[2] |
20 | | - opencv_version += "." |
21 | | - |
22 | | - if "CV_VERSION_MINOR" in words: |
23 | | - opencv_version += words[2] |
24 | | - opencv_version += "." |
25 | | - |
26 | | - if "CV_VERSION_REVISION" in words: |
27 | | - opencv_version += words[2] |
28 | | - break |
29 | | - |
30 | | - # used in local dev releases |
31 | | - git_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).splitlines()[0].decode() |
32 | | - # this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1> |
33 | | - try: |
34 | | - tag = subprocess.check_output(['git', 'describe', '--tags'], stderr = subprocess.STDOUT).splitlines()[0].decode().split('-') |
35 | | - except subprocess.CalledProcessError as e: |
36 | | - # no tags reachable (e.g. on a topic branch in a fork), see |
37 | | - # https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything |
38 | | - if e.output.rstrip() == b"fatal: No names found, cannot describe anything.": |
39 | | - tag=[] |
40 | | - else: |
41 | | - print(e.output); raise |
42 | | - |
43 | | - if len(tag) == 1: |
44 | | - # tag identifies the build and should be a sequential revision number |
45 | | - version = tag[0] |
46 | | - opencv_version += ".{}".format(version) |
47 | | - else: |
48 | | - # local version identifier, not to be published on PyPI |
49 | | - version = git_hash |
50 | | - opencv_version += "+{}".format(version) |
51 | | - |
52 | | - with open('cv2/version.py', 'w') as f: |
53 | | - f.write("opencv_version = \"{}\"\n".format(opencv_version)) |
54 | | - f.write("contrib = {}\n".format(contrib)) |
55 | | - f.write("headless = {}\n".format(headless)) |
56 | | - f.write("ci_build = {}".format(ci_build)) |
| 6 | + contrib = sys.argv[1] |
| 7 | + headless = sys.argv[2] |
| 8 | + ci_build = sys.argv[3] |
| 9 | + |
| 10 | + opencv_version = "" |
| 11 | + # dig out the version from OpenCV sources |
| 12 | + version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp" |
| 13 | + |
| 14 | + with open(version_file_path, "r") as f: |
| 15 | + for line in f: |
| 16 | + words = line.split() |
| 17 | + |
| 18 | + if "CV_VERSION_MAJOR" in words: |
| 19 | + opencv_version += words[2] |
| 20 | + opencv_version += "." |
| 21 | + |
| 22 | + if "CV_VERSION_MINOR" in words: |
| 23 | + opencv_version += words[2] |
| 24 | + opencv_version += "." |
| 25 | + |
| 26 | + if "CV_VERSION_REVISION" in words: |
| 27 | + opencv_version += words[2] |
| 28 | + break |
| 29 | + |
| 30 | + # used in local dev releases |
| 31 | + git_hash = ( |
| 32 | + subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]) |
| 33 | + .splitlines()[0] |
| 34 | + .decode() |
| 35 | + ) |
| 36 | + # this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1> |
| 37 | + try: |
| 38 | + tag = ( |
| 39 | + subprocess.check_output( |
| 40 | + ["git", "describe", "--tags"], stderr=subprocess.STDOUT |
| 41 | + ) |
| 42 | + .splitlines()[0] |
| 43 | + .decode() |
| 44 | + .split("-") |
| 45 | + ) |
| 46 | + except subprocess.CalledProcessError as e: |
| 47 | + # no tags reachable (e.g. on a topic branch in a fork), see |
| 48 | + # https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything |
| 49 | + if e.output.rstrip() == b"fatal: No names found, cannot describe anything.": |
| 50 | + tag = [] |
| 51 | + else: |
| 52 | + print(e.output) |
| 53 | + raise |
| 54 | + |
| 55 | + if len(tag) == 1: |
| 56 | + # tag identifies the build and should be a sequential revision number |
| 57 | + version = tag[0] |
| 58 | + opencv_version += ".{}".format(version) |
| 59 | + else: |
| 60 | + # local version identifier, not to be published on PyPI |
| 61 | + version = git_hash |
| 62 | + opencv_version += "+{}".format(version) |
| 63 | + |
| 64 | + with open("cv2/version.py", "w") as f: |
| 65 | + f.write('opencv_version = "{}"\n'.format(opencv_version)) |
| 66 | + f.write("contrib = {}\n".format(contrib)) |
| 67 | + f.write("headless = {}\n".format(headless)) |
| 68 | + f.write("ci_build = {}".format(ci_build)) |
0 commit comments