... |
... |
@@ -17,6 +17,8 @@ |
17
|
17
|
# Authors:
|
18
|
18
|
# Finn Ball <finn ball codethink co uk>
|
19
|
19
|
|
|
20
|
+import os
|
|
21
|
+import re
|
20
|
22
|
import setuptools
|
21
|
23
|
import sys
|
22
|
24
|
|
... |
... |
@@ -27,19 +29,69 @@ if sys.version_info[0] != 3 or sys.version_info[1] < 5: |
27
|
29
|
sys.exit(1)
|
28
|
30
|
|
29
|
31
|
try:
|
30
|
|
- from setuptools import setup
|
|
32
|
+ from setuptools import setup, find_packages, Command
|
|
33
|
+
|
31
|
34
|
except ImportError:
|
32
|
35
|
print("BuildGrid requires setuptools in order to build. Install it using"
|
33
|
36
|
" your package manager (usually python3-setuptools) or via pip (pip3"
|
34
|
37
|
" install setuptools).")
|
35
|
38
|
sys.exit(1)
|
36
|
39
|
|
|
40
|
+class BuildGRPC(Command):
|
|
41
|
+ """Command to generate project *_pb2.py modules from proto files."""
|
|
42
|
+
|
|
43
|
+ description = 'build gRPC protobuf modules'
|
|
44
|
+ user_options = []
|
|
45
|
+
|
|
46
|
+ def initialize_options(self):
|
|
47
|
+ pass
|
|
48
|
+
|
|
49
|
+ def finalize_options(self):
|
|
50
|
+ pass
|
|
51
|
+
|
|
52
|
+ def run(self):
|
|
53
|
+ try:
|
|
54
|
+ import grpc_tools.command
|
|
55
|
+ except ImportError:
|
|
56
|
+ print("BuildGrid requires grpc_tools in order to build gRPC modules.\n"
|
|
57
|
+ "Install it via pip (pip3 install grpcio-tools).")
|
|
58
|
+ exit(1)
|
|
59
|
+
|
|
60
|
+ protos_root = 'buildgrid/_protos'
|
|
61
|
+
|
|
62
|
+ grpc_tools.command.build_package_protos(protos_root)
|
|
63
|
+
|
|
64
|
+ # Postprocess imports in generated code
|
|
65
|
+ for root, _, files in os.walk(protos_root):
|
|
66
|
+ for filename in files:
|
|
67
|
+ if filename.endswith('.py'):
|
|
68
|
+ path = os.path.join(root, filename)
|
|
69
|
+ with open(path, 'r') as f:
|
|
70
|
+ code = f.read()
|
|
71
|
+
|
|
72
|
+ # All protos are in buildgrid._protos
|
|
73
|
+ code = re.sub(r'^from ', r'from buildgrid._protos.',
|
|
74
|
+ code, flags=re.MULTILINE)
|
|
75
|
+ # Except for the core google.protobuf protos
|
|
76
|
+ code = re.sub(r'^from buildgrid._protos.google.protobuf', r'from google.protobuf',
|
|
77
|
+ code, flags=re.MULTILINE)
|
|
78
|
+
|
|
79
|
+ with open(path, 'w') as f:
|
|
80
|
+ f.write(code)
|
|
81
|
+def get_cmdclass():
|
|
82
|
+ cmdclass = {
|
|
83
|
+ 'build_grpc': BuildGRPC,
|
|
84
|
+ }
|
|
85
|
+ return cmdclass
|
|
86
|
+
|
|
87
|
+
|
37
|
88
|
setup(
|
38
|
89
|
name="BuildGrid",
|
39
|
90
|
version=__version__,
|
|
91
|
+ cmdclass=get_cmdclass(),
|
40
|
92
|
license="Apache License, Version 2.0",
|
41
|
93
|
description="A remote execution service",
|
42
|
|
- packages=setuptools.find_packages(),
|
|
94
|
+ packages=find_packages(),
|
43
|
95
|
install_requires=[
|
44
|
96
|
'protobuf',
|
45
|
97
|
'grpcio',
|