forked from Blizzard/s2client-proto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·95 lines (78 loc) · 2.72 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
#!/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
import s2clientprotocol.build
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=s2clientprotocol.build.game_version(),
description='StarCraft II - client protocol.',
author='Blizzard Entertainment',
author_email='[email protected]',
license='MIT',
url='https://github.com/Blizzard/s2client-proto',
packages=[
's2clientprotocol',
],
install_requires=[
'protobuf',
],
cmdclass={
'build_py': BuildPy,
},
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Operating System :: POSIX',
'Operating System :: Microsoft :: Windows',
'Operating System :: MacOS :: MacOS X',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Topic :: Games/Entertainment :: Real Time Strategy',
'Topic :: Software Development :: Libraries',
],
)