3 # See README for usage instructions.
8 # We must use setuptools, not distutils, because we need to use the
9 # namespace_packages option for the "google" package.
11 from setuptools
import setup
, Extension
14 from ez_setup
import use_setuptools
16 from setuptools
import setup
, Extension
19 "Could not import setuptools; make sure you have setuptools or "
20 "ez_setup installed.\n")
22 from distutils
.command
.clean
import clean
as _clean
23 from distutils
.command
.build_py
import build_py
as _build_py
24 from distutils
.spawn
import find_executable
26 maintainer_email
= "protobuf@googlegroups.com"
28 # Find the Protocol Compiler.
29 if 'PROTOC' in os
.environ
and os
.path
.exists(os
.environ
['PROTOC']):
30 protoc
= os
.environ
['PROTOC']
31 elif os
.path
.exists("../src/protoc"):
32 protoc
= "../src/protoc"
33 elif os
.path
.exists("../src/protoc.exe"):
34 protoc
= "../src/protoc.exe"
35 elif os
.path
.exists("../vsprojects/Debug/protoc.exe"):
36 protoc
= "../vsprojects/Debug/protoc.exe"
37 elif os
.path
.exists("../vsprojects/Release/protoc.exe"):
38 protoc
= "../vsprojects/Release/protoc.exe"
40 protoc
= find_executable("protoc")
42 def generate_proto(source
):
43 """Invokes the Protocol Compiler to generate a _pb2.py from the given
44 .proto file. Does nothing if the output already exists and is newer than
47 output
= source
.replace(".proto", "_pb2.py").replace("../src/", "")
49 if (not os
.path
.exists(output
) or
50 (os
.path
.exists(source
) and
51 os
.path
.getmtime(source
) > os
.path
.getmtime(output
))):
52 print "Generating %s..." % output
54 if not os
.path
.exists(source
):
55 sys
.stderr
.write("Can't find required file: %s\n" % source
)
60 "protoc is not installed nor found in ../src. Please compile it "
61 "or install the binary package.\n")
64 protoc_command
= [ protoc
, "-I../src", "-I.", "--python_out=.", source
]
65 if subprocess
.call(protoc_command
) != 0:
68 def GenerateUnittestProtos():
69 generate_proto("../src/google/protobuf/unittest.proto")
70 generate_proto("../src/google/protobuf/unittest_custom_options.proto")
71 generate_proto("../src/google/protobuf/unittest_import.proto")
72 generate_proto("../src/google/protobuf/unittest_import_public.proto")
73 generate_proto("../src/google/protobuf/unittest_mset.proto")
74 generate_proto("../src/google/protobuf/unittest_no_generic_services.proto")
75 generate_proto("google/protobuf/internal/test_bad_identifiers.proto")
76 generate_proto("google/protobuf/internal/more_extensions.proto")
77 generate_proto("google/protobuf/internal/more_extensions_dynamic.proto")
78 generate_proto("google/protobuf/internal/more_messages.proto")
79 generate_proto("google/protobuf/internal/factory_test1.proto")
80 generate_proto("google/protobuf/internal/factory_test2.proto")
83 # This is apparently needed on some systems to make sure that the tests
84 # work even if a previous version is already installed.
85 if 'google' in sys
.modules
:
86 del sys
.modules
['google']
87 GenerateUnittestProtos()
90 import google
.protobuf
.internal
.generator_test
as generator_test
91 import google
.protobuf
.internal
.descriptor_test
as descriptor_test
92 import google
.protobuf
.internal
.reflection_test
as reflection_test
93 import google
.protobuf
.internal
.service_reflection_test \
94 as service_reflection_test
95 import google
.protobuf
.internal
.text_format_test
as text_format_test
96 import google
.protobuf
.internal
.wire_format_test
as wire_format_test
97 import google
.protobuf
.internal
.unknown_fields_test
as unknown_fields_test
98 import google
.protobuf
.internal
.descriptor_database_test \
99 as descriptor_database_test
100 import google
.protobuf
.internal
.descriptor_pool_test
as descriptor_pool_test
101 import google
.protobuf
.internal
.message_factory_test
as message_factory_test
102 import google
.protobuf
.internal
.message_cpp_test
as message_cpp_test
103 import google
.protobuf
.internal
.reflection_cpp_generated_test \
104 as reflection_cpp_generated_test
106 loader
= unittest
.defaultTestLoader
107 suite
= unittest
.TestSuite()
108 for test
in [ generator_test
,
111 service_reflection_test
,
114 suite
.addTest(loader
.loadTestsFromModule(test
))
121 # Delete generated files in the code tree.
122 for (dirpath
, dirnames
, filenames
) in os
.walk("."):
123 for filename
in filenames
:
124 filepath
= os
.path
.join(dirpath
, filename
)
125 if filepath
.endswith("_pb2.py") or filepath
.endswith(".pyc") or \
126 filepath
.endswith(".so") or filepath
.endswith(".o") or \
127 filepath
.endswith('google/protobuf/compiler/__init__.py'):
129 # _clean is an old-style class, so super() doesn't work.
132 class build_py(_build_py
):
134 # Generate necessary .proto file if it doesn't exist.
135 generate_proto("../src/google/protobuf/descriptor.proto")
136 generate_proto("../src/google/protobuf/compiler/plugin.proto")
138 GenerateUnittestProtos()
139 # Make sure google.protobuf.compiler is a valid package.
140 open('google/protobuf/compiler/__init__.py', 'a').close()
141 # _build_py is an old-style class, so super() doesn't work.
144 if __name__
== '__main__':
147 # C++ implementation extension
148 if os
.getenv("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python") == "cpp":
149 print "Using EXPERIMENTAL C++ Implmenetation."
150 ext_module_list
.append(Extension(
151 "google.protobuf.internal._net_proto2___python",
152 [ "google/protobuf/pyext/python_descriptor.cc",
153 "google/protobuf/pyext/python_protobuf.cc",
154 "google/protobuf/pyext/python-proto2.cc" ],
155 include_dirs
= [ "." ],
156 libraries
= [ "protobuf" ]))
158 setup(name
= 'protobuf',
159 version
= '2.5.0-pre',
160 packages
= [ 'google' ],
161 namespace_packages
= [ 'google' ],
162 test_suite
= 'setup.MakeTestSuite',
163 # Must list modules explicitly so that we don't install tests.
165 'google.protobuf.internal.api_implementation',
166 'google.protobuf.internal.containers',
167 'google.protobuf.internal.cpp_message',
168 'google.protobuf.internal.decoder',
169 'google.protobuf.internal.encoder',
170 'google.protobuf.internal.enum_type_wrapper',
171 'google.protobuf.internal.message_listener',
172 'google.protobuf.internal.python_message',
173 'google.protobuf.internal.type_checkers',
174 'google.protobuf.internal.wire_format',
175 'google.protobuf.descriptor',
176 'google.protobuf.descriptor_pb2',
177 'google.protobuf.compiler.plugin_pb2',
178 'google.protobuf.message',
179 'google.protobuf.descriptor_database',
180 'google.protobuf.descriptor_pool',
181 'google.protobuf.message_factory',
182 'google.protobuf.reflection',
183 'google.protobuf.service',
184 'google.protobuf.service_reflection',
185 'google.protobuf.text_format' ],
186 cmdclass
= { 'clean': clean
, 'build_py': build_py
},
187 install_requires
= ['setuptools'],
188 ext_modules
= ext_module_list
,
189 url
= 'http://code.google.com/p/protobuf/',
190 maintainer
= maintainer_email
,
191 maintainer_email
= 'protobuf@googlegroups.com',
192 license
= 'New BSD License',
193 description
= 'Protocol Buffers',
195 "Protocol Buffers are Google's data interchange format.",