-
Notifications
You must be signed in to change notification settings - Fork 864
/
setup.py
187 lines (149 loc) · 5.54 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
# To build and upload a new version, follow the steps below.
# Notes:
# - this is a "Universal Wheels" package that is pure Python and supports Python3
# - Twine is a secure PyPi upload package
# - Make sure you have bumped the version! at ts/version.py
# $ pip install twine
# $ pip install wheel
# $ python setup.py bdist_wheel --universal
# *** TEST YOUR PACKAGE WITH TEST PI ******
# twine upload --repository-url https://test.pypi.org/legacy/ dist/*
# If this is successful then push it to actual pypi
# $ twine upload dist/*
"""
Setup.py for the model server package
"""
import errno
import os
import platform
import subprocess
import sys
from datetime import date
from shutil import copy2, rmtree
import setuptools.command.build_py
from setuptools import Command, find_packages, setup
import ts
pkgs = find_packages(exclude=["ts_scripts", "test"])
build_frontend_command = {
"Windows": ".\\frontend\\gradlew.bat -p frontend clean assemble",
"Darwin": "frontend/gradlew -p frontend clean assemble",
"Linux": "frontend/gradlew -p frontend clean assemble",
}
build_plugins_command = {
"Windows": ".\\plugins\\gradlew.bat -p plugins clean bS",
"Darwin": "plugins/gradlew -p plugins clean bS",
"Linux": "plugins/gradlew -p plugins clean bS",
}
def pypi_description():
"""
Imports the long description for the project page
"""
with open("PyPiDescription.rst") as df:
return df.read()
def get_nightly_version():
today = date.today()
return today.strftime("%Y.%m.%d")
def detect_model_server_version():
sys.path.append(os.path.abspath("ts"))
if "--release" in sys.argv:
sys.argv.remove("--release")
return ts.__version__.strip()
return ts.__version__.strip() + "b" + str(date.today()).replace("-", "")
class BuildFrontEnd(setuptools.command.build_py.build_py):
"""
Class defined to run custom commands.
"""
description = "Build Model Server Frontend"
source_server_file = os.path.abspath("frontend/server/build/libs/server-1.0.jar")
dest_file_name = os.path.abspath("ts/frontend/model-server.jar")
# noinspection PyMethodMayBeStatic
def run(self):
"""
Actual method called to run the build command
:return:
"""
front_end_bin_dir = os.path.abspath(".") + "/ts/frontend"
try:
os.mkdir(front_end_bin_dir)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(front_end_bin_dir):
pass
else:
raise
if os.path.exists(self.source_server_file):
os.remove(self.source_server_file)
try:
subprocess.check_call(build_frontend_command[platform.system()], shell=True)
except OSError:
assert 0, "build failed"
copy2(self.source_server_file, self.dest_file_name)
class BuildPy(setuptools.command.build_py.build_py):
"""
Class to invoke the custom command defined above.
"""
def run(self):
sys.stderr.flush()
self.run_command("build_frontend")
setuptools.command.build_py.build_py.run(self)
class BuildPlugins(Command):
description = "Build Model Server Plugins"
user_options = [("plugins=", "p", "Plugins installed")]
source_plugin_dir = os.path.abspath("plugins/build/plugins")
def initialize_options(self):
self.plugins = None
def finalize_options(self):
if self.plugins is None:
print("No plugin option provided. Defaulting to 'default'")
self.plugins = "default"
# noinspection PyMethodMayBeStatic
def run(self):
if os.path.isdir(self.source_plugin_dir):
rmtree(self.source_plugin_dir)
try:
if self.plugins == "endpoints":
subprocess.check_call(
build_plugins_command[platform.system()], shell=True
)
else:
raise OSError("No such rule exists")
except OSError:
assert 0, "build failed"
self.run_command("build_py")
if __name__ == "__main__":
# Get nightly version if nightly in name
name = "torchserve"
# Clever code to figure out if setup.py was trigger by ts_scripts/push_nightly.sh
NAME_ARG = "--override-name"
if NAME_ARG in sys.argv:
idx = sys.argv.index(NAME_ARG)
name = sys.argv.pop(idx + 1)
sys.argv.pop(idx)
is_nightly = "nightly" in name
version = get_nightly_version() if is_nightly else detect_model_server_version()
print(f"-- {name} building version: {version}")
requirements = ["Pillow", "psutil", "packaging", "wheel"]
setup(
name=name,
version=version,
description="TorchServe is a tool for serving neural net models for inference",
author="PyTorch Serving team",
author_email="noreply@noreply.com",
long_description=pypi_description(),
long_description_content_type="text/x-rst",
url="https://github.com/pytorch/serve.git",
keywords="TorchServe PyTorch Serving Deep Learning Inference AI",
packages=pkgs,
cmdclass={
"build_frontend": BuildFrontEnd,
"build_plugins": BuildPlugins,
"build_py": BuildPy,
},
install_requires=requirements,
extras_require={
"onnx": ["numpy", "onnx", "onnx-runtime"],
"ipex": ["intel_extension_for_pytorch"],
},
entry_points={"console_scripts": ["torchserve=ts.model_server:start"]},
include_package_data=True,
license="Apache License Version 2.0",
)