-
Notifications
You must be signed in to change notification settings - Fork 15
/
setup.py
105 lines (84 loc) · 2.9 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
import os
from contextlib import contextmanager
from distutils.cmd import Command
from pathlib import Path
from shutil import copy2
from subprocess import check_output
from typing import Any, List
from setuptools import find_namespace_packages, setup
from setuptools.command.build_py import build_py
ROOT_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
PROTOBUF_INCLUDE_PATH = ROOT_DIR / "protobuf_srcs/"
OUTPUT_PATH = ROOT_DIR / "tensor_serving_client/"
PROTO_PATHS = [str(p) for p in PROTOBUF_INCLUDE_PATH.rglob("*.proto")]
@contextmanager
def cd(newdir):
prevdir = os.getcwd()
os.chdir(os.path.expanduser(newdir))
try:
yield
finally:
os.chdir(prevdir)
class CompileProtobufs(Command):
description = """
Compile .proto files in Tensorflow and Tensorflow Serving into python
libraries.
"""
user_options: List[Any] = []
def initialize_options(self):
...
def finalize_options(self):
...
def run(self) -> None:
pb_compile_command = [
"protoc",
f"-I={str(PROTOBUF_INCLUDE_PATH)}",
f"--python_out={str(OUTPUT_PATH)}",
]
with cd(str(PROTOBUF_INCLUDE_PATH)):
for proto_path in PROTO_PATHS:
check_output(pb_compile_command + [proto_path])
class CopyGRPCStubs(Command):
description = """
Copy GRPC Stubs from Tensorflow Serving APIs to the minified Tensorflow Serving APIs library
"""
user_options: List[Any] = []
def initialize_options(self):
...
def finalize_options(self):
...
def run(self):
predict_service_stub = (
PROTOBUF_INCLUDE_PATH / "tensorflow_serving/apis/prediction_service_pb2_grpc.py"
)
model_service_stub = (
PROTOBUF_INCLUDE_PATH / "tensorflow_serving/apis/model_service_pb2_grpc.py"
)
destination = ROOT_DIR / "tensor_serving_client/tensorflow_serving/apis/"
copy2(predict_service_stub, destination)
copy2(model_service_stub, destination)
class BuildPyCommand(build_py):
"""Custom build command."""
def run(self):
self.run_command("compile_pb")
self.run_command("copy_grpc")
build_py.run(self)
with open("README.md", "r") as fh:
long_description = fh.read()
setup(
name="min_tfs_client",
version="1.0.2",
description="A minified Tensor Serving Client for Python",
long_description=long_description,
long_description_content_type="text/markdown",
cmdclass={
"compile_pb": CompileProtobufs,
"copy_grpc": CopyGRPCStubs,
"build_py": BuildPyCommand,
},
package_dir={"": "tensor_serving_client"},
packages=find_namespace_packages(where="tensor_serving_client"),
install_requires=["grpcio>=1.21", "protobuf>=3.8", "numpy>=1.16.4"],
tests_require=["pytest"],
extras_require={"dev": ["black==19.10b0", "flake8", "mypy", "pytest"]},
)