11from setuptools import setup, Distribution, Extension
22import subprocess
3- import shutil
43import os
4+ import re
5+ import shutil
56class BinaryDistribution(Distribution):
67 def has_ext_modules(foo):
78 return True
89
9- MAJOR = 0
10- MINOR = 14
11- PATCH = 0
1210RC = 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+
2555def 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 '
3060major = '%(major)d'
3161minor = '%(minor)d'
32- patch = '%(patch)d '
62+ patch = '%(patch)s '
3363rc = '%(rc)d'
3464istaged = %(istaged)s
3565commit = '%(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
6393write_version_py(filename='@PADDLE_BINARY_DIR@/python/paddle/version.py')
0 commit comments