-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path_render_update_version.py
49 lines (42 loc) · 1.83 KB
/
_render_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
# NOTE: Is called by the build script
import os
import subprocess
import warnings
def git_rev(short=True):
"""Returns the git revision.
"""
cmd = ["git", "rev-parse"]
if short:
cmd.append("--short")
cmd.append("HEAD")
return subprocess.check_output(cmd).decode("utf-8").strip()
def git_branch_rev_count(branch):
"""Count the number of revisions on branch 'branch'.
"""
return int(subprocess.check_output(["git","rev-list",branch,"--count"]).decode("utf-8").strip())
def git_current_branch():
"""Return the name of the current branch."""
return subprocess.check_output(["git","branch","--show-current"]).decode("utf-8").strip()
def replace_version_placeholders(file_content: str) -> str:
return file_content.format(
HIP_PYTHON_VERSION_SHORT=git_branch_rev_count(git_current_branch()),
HIP_PYTHON_VERSION=git_branch_rev_count(git_current_branch()),
HIP_PYTHON_BRANCH=git_current_branch(),
HIP_PYTHON_REV=git_rev(),
)
# render read _version.py (requires git)
def render_version_py(parent_dir: str):
with open(os.path.join(parent_dir,"_version.py.in"),"r"
) as infile, open(os.path.join(parent_dir,"_version.py"),"w") as outfile:
rendered:str = replace_version_placeholders(infile.read())
outfile.write(rendered)
def render_hip_python_as_cuda_requirements_txt():
reqirements_file:str = os.path.join("hip-python-as-cuda","requirements.txt")
with open(reqirements_file+".in","r"
) as infile, open(reqirements_file,"w") as outfile:
rendered:str = replace_version_placeholders(infile.read())
outfile.write(rendered)
if __name__ == "__main__":
render_version_py(os.path.join("hip-python","hip"),)
render_version_py(os.path.join("hip-python-as-cuda","cuda"))
render_hip_python_as_cuda_requirements_txt()