forked from Blizzard/s2client-proto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·76 lines (60 loc) · 1.92 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
#!/usr/bin/python
"""Module setuptools script."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import subprocess
import sys
from distutils.spawn import find_executable
from setuptools import setup
from setuptools.command.build_py import build_py
SETUP_DIR = os.path.dirname(os.path.abspath(__file__))
PROTO_DIR = os.path.join(SETUP_DIR, 's2clientprotocol')
if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']):
protoc = os.environ['PROTOC']
else:
protoc = find_executable('protoc')
def proto_files(root):
"""Yields the path of all .proto files under the root."""
for (dirpath, _, filenames) in os.walk(root):
for filename in filenames:
if filename.endswith('.proto'):
yield os.path.join(dirpath, filename)
def compile_proto(source, python_out, proto_path):
"""Invoke Protocol Compiler to generate python from given source .proto."""
if not protoc:
sys.exit('protoc not found. Is the protobuf-compiler installed?\n')
protoc_command = [
protoc,
'--proto_path', proto_path,
'--python_out', python_out,
source,
]
if subprocess.call(protoc_command) != 0:
sys.exit('Make sure your protoc version >= 2.6. You can use a custom '
'protoc by setting the PROTOC environment variable.')
class BuildPy(build_py):
def run(self):
for proto_file in proto_files(PROTO_DIR):
compile_proto(proto_file, python_out=SETUP_DIR, proto_path=SETUP_DIR)
with open(os.path.join(PROTO_DIR, '__init__.py'), 'a') as f:
pass
build_py.run(self)
setup(
name='s2clientprotocol',
version='1.0',
description='StarCraft II - client protocol.',
author='Blizzard',
author_email='[email protected]',
license='MIT',
packages=[
's2clientprotocol',
],
install_requires=[
'protobuf',
],
cmdclass={
'build_py': BuildPy,
},
)