1#! /usr/bin/python 2# 3# See README for usage instructions. 4 5# We must use setuptools, not distutils, because we need to use the 6# namespace_packages option for the "google" package. 7from ez_setup import use_setuptools 8use_setuptools() 9 10from setuptools import setup 11from distutils.spawn import find_executable 12import sys 13import os 14import subprocess 15 16maintainer_email = "protobuf@googlegroups.com" 17 18# Find the Protocol Compiler. 19if os.path.exists("../src/protoc"): 20 protoc = "../src/protoc" 21elif os.path.exists("../src/protoc.exe"): 22 protoc = "../src/protoc.exe" 23else: 24 protoc = find_executable("protoc") 25 26def generate_proto(source): 27 """Invokes the Protocol Compiler to generate a _pb2.py from the given 28 .proto file. Does nothing if the output already exists and is newer than 29 the input.""" 30 31 output = source.replace(".proto", "_pb2.py").replace("../src/", "") 32 33 if not os.path.exists(source): 34 print "Can't find required file: " + source 35 sys.exit(-1) 36 37 if (not os.path.exists(output) or 38 (os.path.exists(source) and 39 os.path.getmtime(source) > os.path.getmtime(output))): 40 print "Generating %s..." % output 41 42 if protoc == None: 43 sys.stderr.write( 44 "protoc is not installed nor found in ../src. Please compile it " 45 "or install the binary package.\n") 46 sys.exit(-1) 47 48 protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ] 49 if subprocess.call(protoc_command) != 0: 50 sys.exit(-1) 51 52def MakeTestSuite(): 53 # This is apparently needed on some systems to make sure that the tests 54 # work even if a previous version is already installed. 55 if 'google' in sys.modules: 56 del sys.modules['google'] 57 58 generate_proto("../src/google/protobuf/unittest.proto") 59 generate_proto("../src/google/protobuf/unittest_import.proto") 60 generate_proto("../src/google/protobuf/unittest_mset.proto") 61 generate_proto("../src/google/protobuf/unittest_no_generic_services.proto") 62 generate_proto("google/protobuf/internal/more_extensions.proto") 63 generate_proto("google/protobuf/internal/more_messages.proto") 64 65 import unittest 66 import google.protobuf.internal.generator_test as generator_test 67 import google.protobuf.internal.descriptor_test as descriptor_test 68 import google.protobuf.internal.reflection_test as reflection_test 69 import google.protobuf.internal.service_reflection_test \ 70 as service_reflection_test 71 import google.protobuf.internal.text_format_test as text_format_test 72 import google.protobuf.internal.wire_format_test as wire_format_test 73 74 loader = unittest.defaultTestLoader 75 suite = unittest.TestSuite() 76 for test in [ generator_test, 77 descriptor_test, 78 reflection_test, 79 service_reflection_test, 80 text_format_test, 81 wire_format_test ]: 82 suite.addTest(loader.loadTestsFromModule(test)) 83 84 return suite 85 86if __name__ == '__main__': 87 # TODO(kenton): Integrate this into setuptools somehow? 88 if len(sys.argv) >= 2 and sys.argv[1] == "clean": 89 # Delete generated _pb2.py files and .pyc files in the code tree. 90 for (dirpath, dirnames, filenames) in os.walk("."): 91 for filename in filenames: 92 filepath = os.path.join(dirpath, filename) 93 if filepath.endswith("_pb2.py") or filepath.endswith(".pyc"): 94 os.remove(filepath) 95 else: 96 # Generate necessary .proto file if it doesn't exist. 97 # TODO(kenton): Maybe we should hook this into a distutils command? 98 generate_proto("../src/google/protobuf/descriptor.proto") 99 100 setup(name = 'protobuf', 101 version = '2.3.0', 102 packages = [ 'google' ], 103 namespace_packages = [ 'google' ], 104 test_suite = 'setup.MakeTestSuite', 105 # Must list modules explicitly so that we don't install tests. 106 py_modules = [ 107 'google.protobuf.internal.containers', 108 'google.protobuf.internal.decoder', 109 'google.protobuf.internal.encoder', 110 'google.protobuf.internal.message_listener', 111 'google.protobuf.internal.type_checkers', 112 'google.protobuf.internal.wire_format', 113 'google.protobuf.descriptor', 114 'google.protobuf.descriptor_pb2', 115 'google.protobuf.message', 116 'google.protobuf.reflection', 117 'google.protobuf.service', 118 'google.protobuf.service_reflection', 119 'google.protobuf.text_format' ], 120 url = 'http://code.google.com/p/protobuf/', 121 maintainer = maintainer_email, 122 maintainer_email = 'protobuf@googlegroups.com', 123 license = 'New BSD License', 124 description = 'Protocol Buffers', 125 long_description = 126 "Protocol Buffers are Google's data interchange format.", 127 ) 128