Skip to content

Commit 0399263

Browse files
authored
fix(py): set cwd when get commit sha in setup.py (#14299)
`cwd` was not set before when get commit SHA. The default `cwd` is the current build directory. However, the build directory might not be the subdirectory of source. The `git` command will fail when that happened. test=develop
1 parent c28beb8 commit 0399263

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

python/setup.py.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ RC = 0
1414
def git_commit():
1515
try:
1616
cmd = ['git', 'rev-parse', 'HEAD']
17-
git_commit = subprocess.Popen(cmd, stdout = subprocess.PIPE).communicate()[0].strip()
17+
git_commit = subprocess.Popen(cmd, stdout = subprocess.PIPE,
18+
cwd="@PADDLE_SOURCE_DIR@").communicate()[0].strip()
1819
except:
1920
git_commit = 'Unknown'
2021
git_commit = git_commit.decode()
@@ -44,7 +45,7 @@ def get_patch():
4445
def is_taged():
4546
try:
4647
cmd = ['git', 'describe', '--exact-match', '--tags', 'HEAD', '2>/dev/null']
47-
git_tag = subprocess.Popen(cmd, stdout = subprocess.PIPE).communicate()[0].strip()
48+
git_tag = subprocess.Popen(cmd, stdout = subprocess.PIPE, cwd="@PADDLE_SOURCE_DIR@").communicate()[0].strip()
4849
git_tag = git_tag.decode()
4950
except:
5051
return False
@@ -55,8 +56,7 @@ def is_taged():
5556
return False
5657

5758
def write_version_py(filename='paddle/version.py'):
58-
cnt = '''
59-
# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
59+
cnt = '''# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
6060
#
6161
full_version = '%(major)d.%(minor)d.%(patch)s'
6262
major = '%(major)d'

0 commit comments

Comments
 (0)