3 # See README for usage instructions.
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
10 from setuptools
import setup
, Extension
11 from distutils
.spawn
import find_executable
16 maintainer_email
= "protobuf@googlegroups.com"
18 # Find the Protocol Compiler.
19 if os
.path
.exists("../src/protoc"):
20 protoc
= "../src/protoc"
21 elif os
.path
.exists("../src/protoc.exe"):
22 protoc
= "../src/protoc.exe"
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"
28 protoc
= find_executable("protoc")
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
35 output
= source
.replace(".proto", "_pb2.py").replace("../src/", "")
37 if not os
.path
.exists(source
):
38 print "Can't find required file: " + source
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
48 "protoc is not installed nor found in ../src. Please compile it "
49 "or install the binary package.\n")
52 protoc_command
= [ protoc
, "-I../src", "-I.", "--python_out=.", source
]
53 if subprocess
.call(protoc_command
) != 0:
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']
62 generate_proto("../src/google/protobuf/unittest.proto")
63 generate_proto("../src/google/protobuf/unittest_custom_options.proto")
64 generate_proto("../src/google/protobuf/unittest_import.proto")
65 generate_proto("../src/google/protobuf/unittest_mset.proto")
66 generate_proto("../src/google/protobuf/unittest_no_generic_services.proto")
67 generate_proto("google/protobuf/internal/more_extensions.proto")
68 generate_proto("google/protobuf/internal/more_messages.proto")
71 import google
.protobuf
.internal
.generator_test
as generator_test
72 import google
.protobuf
.internal
.descriptor_test
as descriptor_test
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
79 loader
= unittest
.defaultTestLoader
80 suite
= unittest
.TestSuite()
81 for test
in [ generator_test
,
84 service_reflection_test
,
87 suite
.addTest(loader
.loadTestsFromModule(test
))
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
)
98 if filepath
.endswith("_pb2.py") or filepath
.endswith(".pyc") or \
99 filepath
.endswith(".so") or filepath
.endswith(".o"):
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 generate_proto("../src/google/protobuf/compiler/plugin.proto")
109 # C++ implementation extension
110 if os
.getenv("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python") == "cpp":
111 print "Using EXPERIMENTAL C++ Implmenetation."
112 ext_module_list
.append(Extension(
113 "google.protobuf.internal._net_proto2___python",
114 [ "google/protobuf/pyext/python_descriptor.cc",
115 "google/protobuf/pyext/python_protobuf.cc",
116 "google/protobuf/pyext/python-proto2.cc" ],
117 include_dirs
= [ "." ],
118 libraries
= [ "protobuf" ]))
120 setup(name
= 'protobuf',
121 version
= '2.4.2-pre',
122 packages
= [ 'google' ],
123 namespace_packages
= [ 'google' ],
124 test_suite
= 'setup.MakeTestSuite',
125 # Must list modules explicitly so that we don't install tests.
127 'google.protobuf.internal.api_implementation',
128 'google.protobuf.internal.containers',
129 'google.protobuf.internal.cpp_message',
130 'google.protobuf.internal.decoder',
131 'google.protobuf.internal.encoder',
132 'google.protobuf.internal.message_listener',
133 'google.protobuf.internal.python_message',
134 'google.protobuf.internal.type_checkers',
135 'google.protobuf.internal.wire_format',
136 'google.protobuf.descriptor',
137 'google.protobuf.descriptor_pb2',
138 'google.protobuf.compiler.plugin_pb2',
139 'google.protobuf.message',
140 'google.protobuf.reflection',
141 'google.protobuf.service',
142 'google.protobuf.service_reflection',
143 'google.protobuf.text_format' ],
144 ext_modules
= ext_module_list
,
145 url
= 'http://code.google.com/p/protobuf/',
146 maintainer
= maintainer_email
,
147 maintainer_email
= 'protobuf@googlegroups.com',
148 license
= 'New BSD License',
149 description
= 'Protocol Buffers',
151 "Protocol Buffers are Google's data interchange format.",