-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
76 lines (61 loc) · 2.56 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
import os
import sys
import pkg_resources
import setuptools
import re
from setuptools import setup
class BuildProtos(setuptools.Command):
description = "build grpc protobuf modules"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
proto_files = {("../../proto/fabric.proto", "perper/protocol/proto/")}
from grpc_tools import protoc
package_root = os.path.dirname(os.path.abspath(__file__))
well_known_protos_include = pkg_resources.resource_filename("grpc_tools", "_proto")
for proto_file, python_path in proto_files:
proto_file = os.path.join(package_root, proto_file)
python_path = os.path.join(package_root, python_path)
proto_path = os.path.dirname(proto_file)
command = [
"grpc_tools.protoc",
"--proto_path={}".format(proto_path),
"--proto_path={}".format(well_known_protos_include),
"--python_out={}".format(python_path),
"--grpc_python_out={}".format(python_path),
] + [proto_file]
if protoc.main(command) != 0:
if self.strict_mode:
raise Exception("error: {} failed".format(command))
else:
sys.stderr.write("warning: {} failed".format(command))
grpc_generated_path = os.path.join(python_path, os.path.splitext(os.path.basename(proto_file))[0] + "_pb2_grpc.py")
with open(grpc_generated_path, "r") as grpc_generated_file:
grpc_content = grpc_generated_file.read()
grpc_content = re.sub("(?m)^(import.*_pb2)", "from . \\1", grpc_content)
with open(grpc_generated_path, "w") as grpc_generated_file:
grpc_generated_file.write(grpc_content)
with open("README.md") as f:
long_description = f.read()
setup(
name="Perper",
version="0.8.0rc1",
packages=setuptools.find_packages(),
long_description=long_description,
long_description_content_type="text/markdown",
license="MIT License",
author="Obecto EOOD",
url="https://github.com/obecto/perper",
setup_requires=["grpcio-tools>=1.33.2"],
install_requires=["pyignite>=0.3.4", "grpcio>=1.33.2", "protobuf>=3.17.3", "backoff>=1.11.1"],
classifiers=[
"Development Status :: 3 - Alpha",
"Programming Language :: Python",
"Operating System :: OS Independent",
"License :: OSI Approved :: MIT License",
],
cmdclass={"build_protos": BuildProtos},
)