temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 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. |
| 7 | from ez_setup import use_setuptools |
| 8 | use_setuptools() |
| 9 | |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame^] | 10 | from setuptools import setup, Extension |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 11 | from distutils.spawn import find_executable |
| 12 | import sys |
| 13 | import os |
kenton@google.com | a6de64a | 2009-04-18 02:28:15 +0000 | [diff] [blame] | 14 | import subprocess |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 15 | |
| 16 | maintainer_email = "protobuf@googlegroups.com" |
| 17 | |
| 18 | # Find the Protocol Compiler. |
| 19 | if os.path.exists("../src/protoc"): |
| 20 | protoc = "../src/protoc" |
kenton@google.com | 4152d55 | 2009-04-22 03:20:21 +0000 | [diff] [blame] | 21 | elif os.path.exists("../src/protoc.exe"): |
| 22 | protoc = "../src/protoc.exe" |
kenton@google.com | 80aa23d | 2010-09-28 21:58:36 +0000 | [diff] [blame] | 23 | elif os.path.exists("../vsprojects/Debug/protoc.exe"): |
| 24 | protoc = "../vsprojects/Debug/protoc.exe" |
| 25 | elif os.path.exists("../vsprojects/Release/protoc.exe"): |
| 26 | protoc = "../vsprojects/Release/protoc.exe" |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 27 | else: |
| 28 | protoc = find_executable("protoc") |
| 29 | |
| 30 | def generate_proto(source): |
| 31 | """Invokes the Protocol Compiler to generate a _pb2.py from the given |
| 32 | .proto file. Does nothing if the output already exists and is newer than |
| 33 | the input.""" |
| 34 | |
| 35 | output = source.replace(".proto", "_pb2.py").replace("../src/", "") |
| 36 | |
| 37 | if not os.path.exists(source): |
| 38 | print "Can't find required file: " + source |
| 39 | sys.exit(-1) |
| 40 | |
| 41 | if (not os.path.exists(output) or |
| 42 | (os.path.exists(source) and |
| 43 | os.path.getmtime(source) > os.path.getmtime(output))): |
| 44 | print "Generating %s..." % output |
| 45 | |
| 46 | if protoc == None: |
| 47 | sys.stderr.write( |
| 48 | "protoc is not installed nor found in ../src. Please compile it " |
| 49 | "or install the binary package.\n") |
| 50 | sys.exit(-1) |
| 51 | |
kenton@google.com | a6de64a | 2009-04-18 02:28:15 +0000 | [diff] [blame] | 52 | protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ] |
| 53 | if subprocess.call(protoc_command) != 0: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 54 | sys.exit(-1) |
| 55 | |
| 56 | def MakeTestSuite(): |
temporal | bf86b54 | 2008-09-15 17:58:05 +0000 | [diff] [blame] | 57 | # This is apparently needed on some systems to make sure that the tests |
| 58 | # work even if a previous version is already installed. |
| 59 | if 'google' in sys.modules: |
| 60 | del sys.modules['google'] |
| 61 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 62 | generate_proto("../src/google/protobuf/unittest.proto") |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame^] | 63 | generate_proto("../src/google/protobuf/unittest_custom_options.proto") |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 64 | generate_proto("../src/google/protobuf/unittest_import.proto") |
| 65 | generate_proto("../src/google/protobuf/unittest_mset.proto") |
kenton@google.com | fccb146 | 2009-12-18 02:11:36 +0000 | [diff] [blame] | 66 | generate_proto("../src/google/protobuf/unittest_no_generic_services.proto") |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 67 | generate_proto("google/protobuf/internal/more_extensions.proto") |
| 68 | generate_proto("google/protobuf/internal/more_messages.proto") |
| 69 | |
| 70 | import unittest |
| 71 | import google.protobuf.internal.generator_test as generator_test |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 72 | import google.protobuf.internal.descriptor_test as descriptor_test |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 73 | import google.protobuf.internal.reflection_test as reflection_test |
| 74 | import google.protobuf.internal.service_reflection_test \ |
| 75 | as service_reflection_test |
| 76 | import google.protobuf.internal.text_format_test as text_format_test |
| 77 | import google.protobuf.internal.wire_format_test as wire_format_test |
| 78 | |
| 79 | loader = unittest.defaultTestLoader |
| 80 | suite = unittest.TestSuite() |
| 81 | for test in [ generator_test, |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 82 | descriptor_test, |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 83 | reflection_test, |
| 84 | service_reflection_test, |
| 85 | text_format_test, |
| 86 | wire_format_test ]: |
| 87 | suite.addTest(loader.loadTestsFromModule(test)) |
| 88 | |
| 89 | return suite |
| 90 | |
| 91 | if __name__ == '__main__': |
| 92 | # TODO(kenton): Integrate this into setuptools somehow? |
| 93 | if len(sys.argv) >= 2 and sys.argv[1] == "clean": |
| 94 | # Delete generated _pb2.py files and .pyc files in the code tree. |
| 95 | for (dirpath, dirnames, filenames) in os.walk("."): |
| 96 | for filename in filenames: |
| 97 | filepath = os.path.join(dirpath, filename) |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame^] | 98 | if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \ |
| 99 | filepath.endswith(".so") or filepath.endswith(".o"): |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 100 | os.remove(filepath) |
| 101 | else: |
| 102 | # Generate necessary .proto file if it doesn't exist. |
| 103 | # TODO(kenton): Maybe we should hook this into a distutils command? |
| 104 | generate_proto("../src/google/protobuf/descriptor.proto") |
| 105 | |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame^] | 106 | python_c_extension = Extension("google.protobuf.internal._net_proto2___python", |
| 107 | [ "google/protobuf/pyext/python_descriptor.cc", |
| 108 | "google/protobuf/pyext/python_protobuf.cc", |
| 109 | "google/protobuf/pyext/python-proto2.cc", |
| 110 | ], |
| 111 | include_dirs = [ "../src", ".", ], |
| 112 | libraries = [ "protobuf" ], |
| 113 | runtime_library_dirs = [ "../src/.libs" ], |
| 114 | library_dirs = [ "../src/.libs" ], |
| 115 | ) |
| 116 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 117 | setup(name = 'protobuf', |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame^] | 118 | version = '2.4.0-pre', |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 119 | packages = [ 'google' ], |
| 120 | namespace_packages = [ 'google' ], |
| 121 | test_suite = 'setup.MakeTestSuite', |
| 122 | # Must list modules explicitly so that we don't install tests. |
| 123 | py_modules = [ |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame^] | 124 | 'google.protobuf.internal.api_implementation', |
kenton@google.com | 26bd9ee | 2008-11-21 00:06:27 +0000 | [diff] [blame] | 125 | 'google.protobuf.internal.containers', |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame^] | 126 | 'google.protobuf.internal.cpp_message', |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 127 | 'google.protobuf.internal.decoder', |
| 128 | 'google.protobuf.internal.encoder', |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 129 | 'google.protobuf.internal.message_listener', |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame^] | 130 | 'google.protobuf.internal.python_message', |
temporal | ea9d0d8 | 2008-08-18 22:38:20 +0000 | [diff] [blame] | 131 | 'google.protobuf.internal.type_checkers', |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 132 | 'google.protobuf.internal.wire_format', |
| 133 | 'google.protobuf.descriptor', |
| 134 | 'google.protobuf.descriptor_pb2', |
| 135 | 'google.protobuf.message', |
| 136 | 'google.protobuf.reflection', |
| 137 | 'google.protobuf.service', |
| 138 | 'google.protobuf.service_reflection', |
temporal | ea9d0d8 | 2008-08-18 22:38:20 +0000 | [diff] [blame] | 139 | 'google.protobuf.text_format' ], |
liujisi@google.com | 33165fe | 2010-11-02 13:14:58 +0000 | [diff] [blame^] | 140 | ext_modules = [ python_c_extension ], |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 141 | url = 'http://code.google.com/p/protobuf/', |
| 142 | maintainer = maintainer_email, |
| 143 | maintainer_email = 'protobuf@googlegroups.com', |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 144 | license = 'New BSD License', |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 145 | description = 'Protocol Buffers', |
| 146 | long_description = |
| 147 | "Protocol Buffers are Google's data interchange format.", |
| 148 | ) |