forked from taichi-dev/taichi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
149 lines (125 loc) · 4.78 KB
/
build.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import argparse
import os
import platform
import re
import shutil
import sys
def get_os_name():
name = platform.platform()
# in python 3.8, platform.platform() uses mac_ver() on macOS
# it will return 'macOS-XXXX' instead of 'Darwin-XXXX'
if name.lower().startswith('darwin') or name.lower().startswith('macos'):
return 'osx'
if name.lower().startswith('windows'):
return 'win'
if name.lower().startswith('linux'):
return 'linux'
assert False, "Unknown platform name %s" % name
def get_python_executable():
return '"' + sys.executable.replace('\\', '/') + '"'
def build(project_name):
"""Build and package the wheel file in root `dist` dir"""
if platform.system() == 'Linux':
if re.search("^clang\+\+-*\d*", str(os.environ.get('CXX'))) is None:
raise RuntimeError(
'Only the wheel with clang will be released to PyPI')
print("Using python executable", get_python_executable())
os.system(
'{} -m pip install --user --upgrade twine setuptools wheel'.format(
get_python_executable()))
os.system(
f'{get_python_executable()} ../misc/make_changelog.py origin/master ../ True'
)
# This env var is used in setup.py below.
os.environ['PROJECT_NAME'] = project_name
project_tag = ''
if project_name == 'taichi-nightly':
project_tag = 'egg_info --tag-date'
if get_os_name() == 'linux':
os.system(
f'cd ..; {get_python_executable()} setup.py {project_tag} bdist_wheel -p manylinux1_x86_64'
)
else:
os.system(
f'cd .. && {get_python_executable()} setup.py {project_tag} bdist_wheel'
)
try:
os.remove('taichi/CHANGELOG.md')
except FileNotFoundError:
pass
def parse_args():
parser = argparse.ArgumentParser(description=(
'Build and uploads wheels to PyPI. Make sure to run this script '
'inside `python/`'))
parser.add_argument('mode',
type=str,
default='',
help=('Choose one of the modes: '
'[build, test, try_upload, upload]'))
parser.add_argument('--skip_build',
action='store_true',
help=('Skip the build process if this is enabled'))
parser.add_argument('--testpypi',
action='store_true',
help='Upload to test server if this is enabled')
parser.add_argument('--project_name',
action='store',
dest='project_name',
default='taichi',
help='Set the project name')
return parser.parse_args()
def main():
args = parse_args()
mode = args.mode
pypi_user = '__token__'
pypi_repo = ''
project_name = args.project_name
env_pypi_pwd = os.environ.get('PYPI_PWD', '')
if not args.skip_build:
shutil.rmtree('../dist', ignore_errors=True)
if mode == 'try_upload':
if env_pypi_pwd == '':
print("Missing environment variable PYPI_PWD")
print("Giving up and exiting 0 [try_upload mode]")
exit(0)
mode = 'upload'
if mode == 'upload' and env_pypi_pwd == '':
raise RuntimeError("Missing environment variable PYPI_PWD")
os.environ['TWINE_PASSWORD'] = env_pypi_pwd
if mode == 'upload' and args.testpypi:
pypi_repo = '--repository testpypi'
if not args.skip_build:
build(project_name)
if mode == 'build':
return
if mode == 'upload':
if os.system('{} -m twine upload {} ../dist/* --verbose -u {}'.format(
get_python_executable(), pypi_repo, pypi_user)) != 0:
raise SystemExit(1)
elif mode == 'test':
print('Uninstalling old taichi packages...')
os.system(
f'{get_python_executable()} -m pip uninstall -y taichi-nightly')
os.system(f'{get_python_executable()} -m pip uninstall -y taichi')
dists = os.listdir('../dist')
assert len(dists) == 1
dist = dists[0]
print('Installing ', dist)
os.environ['PYTHONPATH'] = ''
os.makedirs('test_env', exist_ok=True)
os.system(
'cd test_env && {} -m pip install ../../dist/{} --user'.format(
get_python_executable(), dist))
print('Entering test environment...')
if get_os_name() == 'win':
os.system(
'cmd /V /C "set PYTHONPATH=&& set TAICHI_REPO_DIR=&& cd test_env && cmd"'
)
else:
os.system(
'cd test_env && PYTHONPATH= TAICHI_REPO_DIR= bash --noprofile --norc '
)
else:
raise ValueError("Unknown mode: %s" % mode)
if __name__ == '__main__':
main()