/
setup.py
243 lines (206 loc) · 7.31 KB
/
setup.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2020 Alibaba Group Holding Limited. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import shutil
import subprocess
import sys
from distutils.cmd import Command
from setuptools import find_packages
from setuptools import setup
from setuptools.command.build_py import build_py
from setuptools.command.develop import develop
from setuptools.command.sdist import sdist
repo_root = os.path.dirname(os.path.abspath(__file__))
class BuildBuiltin(Command):
description = "Build builtin app gar file"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
shutil.rmtree(
os.path.join(
repo_root, "gscoordinator", "builtin", "app", "builtin_app.gar"
),
ignore_errors=True,
)
shutil.rmtree(
os.path.join(
repo_root, "gscoordinator", "builtin", "app", "builtin_app.zip"
),
ignore_errors=True,
)
shutil.make_archive(
os.path.join(repo_root, "gscoordinator", "builtin", "app", "builtin_app"),
format="zip",
root_dir=os.path.join(repo_root, "gscoordinator", "builtin", "app"),
base_dir=None,
)
shutil.move(
src=os.path.join(
repo_root, "gscoordinator", "builtin", "app", "builtin_app.zip"
),
dst=os.path.join(
repo_root, "gscoordinator", "builtin", "app", "builtin_app.gar"
),
)
class FormatAndLint(Command):
description = "Format and lint code"
user_options = []
user_options = [("inplace=", "i", "Run code formatter and linter inplace")]
def initialize_options(self):
self.inplace = False
def finalize_options(self):
if self.inplace or self.inplace == "True" or self.inplace == "true":
self.inplace = True
else:
self.inplace = False
def run(self):
if self.inplace:
subprocess.check_call(["python3", "-m", "isort", "."], cwd=repo_root)
subprocess.check_call(["python3", "-m", "black", "."], cwd=repo_root)
subprocess.check_call(["python3", "-m", "flake8", "."], cwd=repo_root)
else:
subprocess.check_call(
["python3", "-m", "isort", "--check", "--diff", "."], cwd=repo_root
)
subprocess.check_call(
["python3", "-m", "black", "--check", "--diff", "."], cwd=repo_root
)
subprocess.check_call(["python3", "-m", "flake8", "."], cwd=repo_root)
class CustomBuildPy(build_py):
def run(self):
self.run_command("build_builtin")
build_py.run(self)
class CustomDevelop(develop):
def run(self):
self.run_command("build_builtin")
develop.run(self)
class CustomSDist(sdist):
def run(self):
self.run_command("build_builtin")
sdist.run(self)
with open(
os.path.join(os.path.abspath(os.path.dirname(__file__)), "README.md"),
encoding="utf-8",
mode="r",
) as fp:
long_description = fp.read()
def parsed_reqs():
with open(os.path.join(repo_root, "requirements.txt"), "r", encoding="utf-8") as fp:
return fp.read().splitlines()
def parsed_dev_reqs():
with open(
os.path.join(repo_root, "requirements-dev.txt"), "r", encoding="utf-8"
) as fp:
return fp.read().splitlines()
def parse_version(root, **kwargs):
"""
Parse function for setuptools_scm that first tries to read '../VERSION' file
to get a version number.
"""
from setuptools_scm.git import parse
from setuptools_scm.version import meta
version_file = os.path.join(repo_root, "..", "VERSION")
if os.path.isfile(version_file):
with open(version_file, "r", encoding="utf-8") as fp:
return meta(fp.read().strip())
return parse(root, **kwargs)
version_template = """#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2020 Alibaba Group Holding Limited. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
version_file_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "..", "VERSION"
)
if os.path.isfile(version_file_path):
with open(version_file_path, "r", encoding="utf-8") as fp:
__version__ = fp.read().strip()
__version_tuple__ = (int(v) for v in __version__.split("."))
else:
__version__ = "{version}"
__version_tuple__ = {version_tuple}
del version_file_path
"""
setup(
name="gscoordinator",
description="",
long_description=long_description,
long_description_content_type="text/markdown",
author="GRAPE Team, Damo Academy",
author_email="7br@alibaba-inc.com",
url="https://code.aone.alibaba-inc.com/7br/pygrape",
license="Apache License 2.0",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Topic :: Software Development :: Libraries",
"Topic :: System :: Distributed Computing",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
keywords="GRAPE, Graph Computations",
use_scm_version={
"root": repo_root,
"parse": parse_version,
"write_to": os.path.join(repo_root, "gscoordinator/version.py"),
"write_to_template": version_template,
},
setup_requires=["setuptools_scm>=5.0.0", "grpcio", "grpcio-tools"],
package_dir={".": "."},
packages=find_packages("."),
package_data={
"gscoordinator": [
"builtin/app/builtin_app.gar",
"builtin/app/*.yaml",
"template/*.template",
]
},
cmdclass={
"build_builtin": BuildBuiltin,
"build_py": CustomBuildPy,
"sdist": CustomSDist,
"develop": CustomDevelop,
"lint": FormatAndLint,
},
install_requires=parsed_reqs(),
extras_require={
"dev": parsed_dev_reqs(),
},
)