forked from dmlc/decord
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathupdate_version.py
57 lines (51 loc) · 1.87 KB
/
update_version.py
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
"""
This is the global script that set the version information of DECORD.
This script runs and update all the locations that related to versions
List of affected files:
- decord-root/python/decord/_ffi/libinfo.py
- decord-root/include/decord/runtime/c_runtime_api.h
- decord-root/src/runtime/file_util.cc
"""
import os
import re
# current version
# We use the version of the incoming release for code
# that is under development
__version__ = "0.6.0"
# Implementations
def update(file_name, pattern, repl):
update = []
hit_counter = 0
need_update = False
for l in open(file_name):
result = re.findall(pattern, l)
if result:
assert len(result) == 1
hit_counter += 1
if result[0] != repl:
l = re.sub(pattern, repl, l)
need_update = True
print("%s: %s->%s" % (file_name, result[0], repl))
else:
print("%s: version is already %s" % (file_name, repl))
update.append(l)
if hit_counter != 1:
raise RuntimeError("Cannot find version in %s" % file_name)
if need_update:
with open(file_name, "w") as output_file:
for l in update:
output_file.write(l)
def main():
curr_dir = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
proj_root = os.path.abspath(os.path.join(curr_dir, ".."))
# python path
update(os.path.join(proj_root, "python", "decord", "_ffi", "libinfo.py"),
r"(?<=__version__ = \")[.0-9a-z]+", __version__)
# C++ header
update(os.path.join(proj_root, "include", "decord", "runtime", "c_runtime_api.h"),
"(?<=DECORD_VERSION \")[.0-9a-z]+", __version__)
# file util
update(os.path.join(proj_root, "src", "runtime", "file_util.cc"),
"(?<=std::string version = \")[.0-9a-z]+", __version__)
if __name__ == "__main__":
main()