Skip to content

Commit 1bd9fe8

Browse files
authored
Merge pull request PaddlePaddle#11834 from velconia/update_version_via_git_branch
Update version via git tag
2 parents 091ab63 + b8ff38a commit 1bd9fe8

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

cmake/version.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# Get the latest git tag.
22
set(PADDLE_VERSION $ENV{PADDLE_VERSION})
33
set(tmp_version "HEAD")
4+
set(TAG_VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(\\.(a|b|rc)\\.[0-9]+)?")
5+
set(COMMIT_VERSION_REGEX "[0-9a-f]+[0-9a-f]+[0-9a-f]+[0-9a-f]+[0-9a-f]+")
46
while ("${PADDLE_VERSION}" STREQUAL "")
57
execute_process(
6-
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 ${tmp_version}
8+
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 --always ${tmp_version}
79
WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
810
OUTPUT_VARIABLE GIT_TAG_NAME
911
RESULT_VARIABLE GIT_RESULT
1012
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
1113
if (NOT ${GIT_RESULT})
1214
# Check the tag is a correct version
13-
if (${GIT_TAG_NAME} MATCHES "v[0-9]+\\.[0-9]+\\.[0-9]+(\\.(a|b|rc)\\.[0-9]+)?")
15+
if (${GIT_TAG_NAME} MATCHES "${COMMIT_VERSION_REGEX}")
16+
# if no tag was found, set PADDLE_VERSION to latest
17+
set(PADDLE_VERSION "latest")
18+
elseif (${GIT_TAG_NAME} MATCHES "v${TAG_VERSION_REGEX}")
1419
string(REPLACE "v" "" PADDLE_VERSION ${GIT_TAG_NAME})
1520
else() # otherwise, get the previous git tag name.
1621
set(tmp_version "${GIT_TAG_NAME}~1")

python/setup.py.in

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
from setuptools import setup, Distribution, Extension
22
import subprocess
3-
import shutil
43
import os
4+
import re
5+
import shutil
56
class BinaryDistribution(Distribution):
67
def has_ext_modules(foo):
78
return True
89

9-
MAJOR = 0
10-
MINOR = 14
11-
PATCH = 0
1210
RC = 0
13-
ISTAGED = False
1411

1512

1613

@@ -22,14 +19,47 @@ def git_commit():
2219
git_commit = 'Unknown'
2320
return git_commit
2421

22+
def _get_version_detail(idx):
23+
assert idx < 3, "vesion info consists of %(major)d.%(minor)d.%(patch)d, \
24+
so detail index must less than 3"
25+
26+
if re.match('@TAG_VERSION_REGEX@', '@PADDLE_VERSION@'):
27+
version_details = '@PADDLE_VERSION@'.split('.')
28+
29+
if len(version_details) == 3:
30+
return version_details[idx]
31+
32+
return 0
33+
34+
def get_major():
35+
return int(_get_version_detail(0))
36+
37+
def get_minor():
38+
return int(_get_version_detail(1))
39+
40+
def get_patch():
41+
return str(_get_version_detail(2))
42+
43+
def is_taged():
44+
try:
45+
cmd = ['git', 'describe', '--exact-match', '--tags']
46+
git_tag = subprocess.Popen(cmd, stdout = subprocess.PIPE).communicate()[0].strip()
47+
except:
48+
return False
49+
50+
if git_tag.replace('v', '') == '@PADDLE_VERSION@':
51+
return True
52+
else:
53+
return False
54+
2555
def write_version_py(filename='paddle/version.py'):
2656
cnt = '''
2757
# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
2858
#
29-
full_version = '%(major)d.%(minor)d.%(patch)d'
59+
full_version = '%(major)d.%(minor)d.%(patch)s'
3060
major = '%(major)d'
3161
minor = '%(minor)d'
32-
patch = '%(patch)d'
62+
patch = '%(patch)s'
3363
rc = '%(rc)d'
3464
istaged = %(istaged)s
3565
commit = '%(commit)s'
@@ -51,13 +81,13 @@ def mkl():
5181
commit = git_commit()
5282
with open(filename, 'w') as f:
5383
f.write(cnt % {
54-
'major': MAJOR,
55-
'minor': MINOR,
56-
'patch': PATCH,
84+
'major': get_major(),
85+
'minor': get_minor(),
86+
'patch': get_patch(),
5787
'rc': RC,
5888
'version': '${PADDLE_VERSION}',
5989
'commit': commit,
60-
'istaged': ISTAGED,
90+
'istaged': is_taged(),
6191
'with_mkl': '@WITH_MKL@'})
6292

6393
write_version_py(filename='@PADDLE_BINARY_DIR@/python/paddle/version.py')

0 commit comments

Comments
 (0)