-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
59 lines (46 loc) · 1.8 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
#!/usr/bin/env python
from distutils.core import setup
from distutils.command.build_py import build_py as _build_py
from distutils.command.clean import clean as _clean
import subprocess, os, sys
protoc = "protoc"
def generate_proto(source):
"""Invokes the Protocol Compiler to generate a _pb2.py from the given
.proto file. Does nothing if the output already exists and is newer than
the input."""
output = source.replace(".proto", "_pb2.py")
if (not os.path.exists(output) or
(os.path.exists(source) and
os.path.getmtime(source) > os.path.getmtime(output))):
print("Generating %s..." % output)
if not os.path.exists(source):
sys.stderr.write("Can't find required file: %s\n" % source)
sys.exit(-1)
if protoc == None:
sys.stderr.write(
"protoc is not installed nor found in ../src. Please compile it "
"or install the binary package.\n")
sys.exit(-1)
protoc_command = [ protoc, "-I.", "--python_out=.", source ]
if subprocess.call(protoc_command) != 0:
sys.exit(-1)
class clean(_clean):
def run(self):
subprocess.call(["rm","tests/test_pb2.py"])
# _clean is an old-style class, so super() doesn't work.
_clean.run(self)
class build_py(_build_py):
def run(self):
# Generate necessary .proto file if it doesn't exist.
generate_proto("tests/test.proto")
# _build_py is an old-style class, so super() doesn't work.
_build_py.run(self)
setup(name='protowrapper',
version='0.0.1',
description='Protowrapper is a helper class that monkey patches protobuffer classes to assist validation.',
author='Kitten Tofu',
author_email='[email protected]',
url='http://eudemonia.io/protowrapper/',
packages=['protowrapper'],
cmdclass={'build_py': build_py, 'clean': clean},
)