setup.py.in 4.9 KB
Newer Older
T
typhoonzero 已提交
1
from setuptools import setup, Distribution, Extension
Y
Yancey 已提交
2
import subprocess
3
import re
4 5 6
class BinaryDistribution(Distribution):
    def has_ext_modules(foo):
        return True
Z
zhangjinchao01 已提交
7

Y
Yancey 已提交
8 9 10 11 12 13 14 15 16 17 18 19
RC      = 0



def git_commit():
    try:
        cmd = ['git', 'rev-parse', 'HEAD']
        git_commit = subprocess.Popen(cmd, stdout = subprocess.PIPE).communicate()[0].strip()
    except:
        git_commit = 'Unknown'
    return git_commit

20
def _get_version_detail(idx):
21 22
    assert idx < 3, "vesion info consists of %(major)d.%(minor)d.%(patch)d, \
        so detail index must less than 3"
23

24
    version_details = '@PADDLE_VERSION@'.split('.')
25 26 27 28 29 30 31
    if len(version_details) == 3:
        if re.match('[0-9]+', version_details[idx]):
            return int(version_details[idx])

    return None

def get_major():
32
    major = _get_version_detail(0)
33 34 35
    if major is not None:
        return major

36
    return 'UNKNOWN'
37

38 39 40 41 42
def get_minor():
    minor = _get_version_detail(1)
    if minor is not None:
        return minor

43
    return 'UNKNOWN'
44

45 46 47 48 49
def get_patch():
    patch = _get_version_detail(2)
    if patch is not None:
        return patch

50
    return 'UNKNOWN'
51 52

def is_taged():
M
minqiyang 已提交
53
    try:
54 55
        cmd = ['git', 'describe', '--exact-match', '--tags']
        git_tag = subprocess.Popen(cmd, stdout = subprocess.PIPE).communicate()[0].strip()
M
minqiyang 已提交
56
    except:
57 58 59 60 61
        return False

    if git_tag.replace('v', '') == '@PADDLE_VERSION@':
        return True
    else:
M
minqiyang 已提交
62
        return False
63

Y
Yancey 已提交
64 65 66 67 68 69 70 71 72 73 74
def write_version_py(filename='paddle/version.py'):
    cnt = '''
# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
#
full_version    = '%(major)d.%(minor)d.%(patch)d'
major           = '%(major)d'
minor           = '%(minor)d'
patch           = '%(patch)d'
rc              = '%(rc)d'
istaged         = %(istaged)s
commit          = '%(commit)s'
L
Luo Tao 已提交
75
with_mkl        = '%(with_mkl)s'
Y
Yancey 已提交
76 77 78 79 80 81 82 83 84 85

def show():
    if istaged:
        print 'full_version:', full_version
        print 'major:', major
        print 'minor:', minor
        print 'patch:', patch
        print 'rc:', rc
    else:
        print 'commit:', commit
L
Luo Tao 已提交
86 87 88

def mkl():
    return with_mkl
Y
Yancey 已提交
89 90 91 92
'''
    commit = git_commit()
    with open(filename, 'w') as f:
        f.write(cnt % {
93 94 95
            'major': get_major(),
            'minor': get_minor(),
            'patch': get_patch(),
Y
Yancey 已提交
96 97 98
            'rc': RC,
            'version': '${PADDLE_VERSION}',
            'commit': commit,
99
            'istaged': is_taged(),
L
Luo Tao 已提交
100
            'with_mkl': '@WITH_MKL@'})
Y
Yancey 已提交
101

102
write_version_py(filename='@PADDLE_BINARY_DIR@/python/paddle/version.py')
Y
Yancey 已提交
103 104


Z
zhangjinchao01 已提交
105
packages=['paddle',
Q
qiaolongfei 已提交
106
          'paddle.utils',
107 108
          'paddle.dataset',
          'paddle.reader',
109 110
          'paddle.fluid',
          'paddle.fluid.proto',
X
Xin Pan 已提交
111
          'paddle.fluid.proto.profiler',
Y
Yancey 已提交
112
          'paddle.fluid.layers',
Q
qiaolongfei 已提交
113 114
          'paddle.fluid.transpiler',
          'paddle.fluid.transpiler.details']
L
Luo Tao 已提交
115

116
if '${WITH_FLUID_ONLY}'== 'OFF':
L
Luo Tao 已提交
117 118 119 120 121 122
    packages+=['paddle.proto',
               'paddle.trainer',
               'paddle.trainer_config_helpers',
               'paddle.v2',
               'paddle.v2.master',
               'paddle.v2.plot',
123 124
               'paddle.v2.reader',
               'paddle.v2.dataset',
L
Luo Tao 已提交
125
               'py_paddle']
Z
zhangjinchao01 已提交
126

127 128
with open('@PADDLE_SOURCE_DIR@/python/requirements.txt') as f:
    setup_requires = f.read().splitlines()
129 130

if '${CMAKE_SYSTEM_PROCESSOR}' not in ['arm', 'armv7-a', 'aarch64']:
Y
Yancey 已提交
131
    setup_requires+=['opencv-python']
132

133
# the prefix is sys.prefix which should always be usr
L
Luo Tao 已提交
134
paddle_bins = ''
135
if '${WITH_FLUID_ONLY}'== 'OFF':
L
Luo Tao 已提交
136 137 138 139 140 141 142
    paddle_bin_dir = 'opt/paddle/bin'
    paddle_bins = ['${PADDLE_BINARY_DIR}/paddle/trainer/paddle_trainer',
                   '${PADDLE_BINARY_DIR}/paddle/trainer/paddle_merge_model',
                   '${PADDLE_BINARY_DIR}/paddle/pserver/paddle_pserver_main',
                   '${PADDLE_BINARY_DIR}/paddle/scripts/paddle']

package_data={'paddle.fluid': ['core.so']}
143
if '${WITH_FLUID_ONLY}'== 'OFF':
L
Luo Tao 已提交
144 145 146 147
    package_data['paddle.v2.master']=['libpaddle_master.so']
    package_data['py_paddle']=['*.py','_swig_paddle.so']

package_dir={
148
    '': '${PADDLE_BINARY_DIR}/python',
L
Luo Tao 已提交
149 150 151 152
    # The paddle.fluid.proto will be generated while compiling.
    # So that package points to other directory.
    'paddle.fluid.proto.profiler': '${PADDLE_BINARY_DIR}/paddle/fluid/platform',
    'paddle.fluid.proto': '${PADDLE_BINARY_DIR}/paddle/fluid/framework',
Q
qiaolongfei 已提交
153
    'paddle.fluid': '${PADDLE_BINARY_DIR}/python/paddle/fluid',
L
Luo Tao 已提交
154
}
155
if '${WITH_FLUID_ONLY}'== 'OFF':
156
    package_dir['py_paddle']='${PADDLE_BINARY_DIR}/python/py_paddle'
157

158

159
paddle_rt_lib_dir = 'lib'
L
Luo Tao 已提交
160 161 162
paddle_rt_libs = ['${WARPCTC_LIBRARIES}']
if '${MKL_SHARED_LIBS}'!= '':
  paddle_rt_libs += '${MKL_SHARED_LIBS}'.split(';')
T
tensor-tang 已提交
163

T
typhoonzero 已提交
164
setup(name='${PACKAGE_NAME}',
Z
zhangjinchao01 已提交
165 166
      version='${PADDLE_VERSION}',
      description='Parallel Distributed Deep Learning',
167
      install_requires=setup_requires,
L
Luo Tao 已提交
168
      packages=packages,
T
typhoonzero 已提交
169
      ext_modules=[Extension('_foo', ['stub.cc'])],
L
Luo Tao 已提交
170 171
      package_data=package_data,
      package_dir=package_dir,
172 173
      scripts=paddle_bins,
      data_files=[(paddle_rt_lib_dir, paddle_rt_libs)]
Z
zhangjinchao01 已提交
174
)