4 from distutils
import util
16 from setuptools
import setup, Extension, find_packages
18 from distutils.command.build_py
import build_py
as _build_py
19 from distutils.command.clean
import clean
as _clean
20 from distutils.spawn
import find_executable
23 if 'PROTOC' in os.environ
and os.path.exists(os.environ[
'PROTOC']):
24 protoc = os.environ[
'PROTOC']
25 elif os.path.exists(
"../src/protoc"):
26 protoc =
"../src/protoc"
27 elif os.path.exists(
"../src/protoc.exe"):
28 protoc =
"../src/protoc.exe"
29 elif os.path.exists(
"../vsprojects/Debug/protoc.exe"):
30 protoc =
"../vsprojects/Debug/protoc.exe"
31 elif os.path.exists(
"../vsprojects/Release/protoc.exe"):
32 protoc =
"../vsprojects/Release/protoc.exe"
38 """Gets the version from google/protobuf/__init__.py
40 Do not import google.protobuf.__init__ directly, because an installed
41 protobuf library may be loaded instead."""
43 with open(os.path.join(
'google',
'protobuf',
'__init__.py'))
as version_file:
44 exec(version_file.read(), globals())
50 """Invokes the Protocol Compiler to generate a _pb2.py from the given
51 .proto file. Does nothing if the output already exists and is newer than
54 if not require
and not os.path.exists(source):
57 output = source.replace(
".proto",
"_pb2.py").replace(
"../src/",
"")
59 if (
not os.path.exists(output)
or
60 (os.path.exists(source)
and
61 os.path.getmtime(source) > os.path.getmtime(output))):
62 print(
"Generating %s..." % output)
64 if not os.path.exists(source):
65 sys.stderr.write(
"Can't find required file: %s\n" % source)
70 "protoc is not installed nor found in ../src. Please compile it "
71 "or install the binary package.\n")
74 protoc_command = [ protoc,
"-I../src",
"-I.",
"--python_out=.", source ]
75 if subprocess.call(protoc_command) != 0:
80 generate_proto(
"../src/google/protobuf/map_proto2_unittest.proto",
False)
82 generate_proto(
"../src/google/protobuf/test_messages_proto3.proto",
False)
83 generate_proto(
"../src/google/protobuf/test_messages_proto2.proto",
False)
84 generate_proto(
"../src/google/protobuf/unittest_arena.proto",
False)
85 generate_proto(
"../src/google/protobuf/unittest_no_arena.proto",
False)
86 generate_proto(
"../src/google/protobuf/unittest_no_arena_import.proto",
False)
88 generate_proto(
"../src/google/protobuf/unittest_custom_options.proto",
False)
89 generate_proto(
"../src/google/protobuf/unittest_import.proto",
False)
90 generate_proto(
"../src/google/protobuf/unittest_import_public.proto",
False)
91 generate_proto(
"../src/google/protobuf/unittest_mset.proto",
False)
92 generate_proto(
"../src/google/protobuf/unittest_mset_wire_format.proto",
False)
93 generate_proto(
"../src/google/protobuf/unittest_no_generic_services.proto",
False)
94 generate_proto(
"../src/google/protobuf/unittest_proto3_arena.proto",
False)
95 generate_proto(
"../src/google/protobuf/util/json_format.proto",
False)
96 generate_proto(
"../src/google/protobuf/util/json_format_proto3.proto",
False)
98 generate_proto(
"google/protobuf/internal/descriptor_pool_test1.proto",
False)
99 generate_proto(
"google/protobuf/internal/descriptor_pool_test2.proto",
False)
100 generate_proto(
"google/protobuf/internal/factory_test1.proto",
False)
101 generate_proto(
"google/protobuf/internal/factory_test2.proto",
False)
102 generate_proto(
"google/protobuf/internal/file_options_test.proto",
False)
103 generate_proto(
"google/protobuf/internal/import_test_package/inner.proto",
False)
104 generate_proto(
"google/protobuf/internal/import_test_package/outer.proto",
False)
105 generate_proto(
"google/protobuf/internal/missing_enum_values.proto",
False)
106 generate_proto(
"google/protobuf/internal/message_set_extensions.proto",
False)
107 generate_proto(
"google/protobuf/internal/more_extensions.proto",
False)
108 generate_proto(
"google/protobuf/internal/more_extensions_dynamic.proto",
False)
109 generate_proto(
"google/protobuf/internal/more_messages.proto",
False)
110 generate_proto(
"google/protobuf/internal/no_package.proto",
False)
111 generate_proto(
"google/protobuf/internal/packed_field_test.proto",
False)
112 generate_proto(
"google/protobuf/internal/test_bad_identifiers.proto",
False)
119 for (dirpath, dirnames, filenames)
in os.walk(
"."):
120 for filename
in filenames:
121 filepath = os.path.join(dirpath, filename)
122 if filepath.endswith(
"_pb2.py")
or filepath.endswith(
".pyc")
or \
123 filepath.endswith(
".so")
or filepath.endswith(
".o"):
149 target =
'test_python'
152 os.environ[
"CONFORMANCE_PYTHON_EXTRA_FAILURES"] = (
153 "--failure_list failure_list_python-post26.txt")
154 cmd =
'cd ../conformance && make %s' % (test_conformance.target)
155 status = subprocess.check_call(cmd, shell=
True)
159 if option_str
in sys.argv:
160 sys.argv.remove(option_str)
165 if __name__ ==
'__main__':
167 warnings_as_errors =
'--warnings_as_errors'
173 libraries = [
'protobuf']
175 if compile_static_ext:
177 extra_objects = [
'../src/.libs/libprotobuf.a',
178 '../src/.libs/libprotobuf-lite.a']
179 test_conformance.target =
'test_python_cpp'
181 extra_compile_args = []
183 if sys.platform !=
'win32':
184 extra_compile_args.append(
'-Wno-write-strings')
185 extra_compile_args.append(
'-Wno-invalid-offsetof')
186 extra_compile_args.append(
'-Wno-sign-compare')
187 extra_compile_args.append(
'-Wno-unused-variable')
188 extra_compile_args.append(
'-std=c++11')
190 if sys.platform ==
'darwin':
191 extra_compile_args.append(
"-Wno-shorten-64-to-32");
192 extra_compile_args.append(
"-Wno-deprecated-register");
197 if sys.platform ==
'darwin':
198 mac_target = sysconfig.get_config_var(
'MACOSX_DEPLOYMENT_TARGET')
199 if mac_target
and (pkg_resources.parse_version(mac_target) <
200 pkg_resources.parse_version(
'10.9.0')):
201 os.environ[
'MACOSX_DEPLOYMENT_TARGET'] =
'10.9'
202 os.environ[
'_PYTHON_HOST_PLATFORM'] = re.sub(
203 r'macosx-[0-9]+\.[0-9]+-(.+)',
r'macosx-10.9-\1',
207 if sys.platform ==
'win32':
208 extra_compile_args.append(
'-D_hypot=hypot')
211 if sys.platform ==
'win32' and '64 bit' in sys.version:
212 extra_compile_args.append(
'-DMS_WIN64')
215 if (sys.platform ==
'win32'):
216 extra_compile_args.append(
'/MT')
218 if "clang" in os.popen(
'$CC --version 2> /dev/null').
read():
219 extra_compile_args.append(
'-Wno-shorten-64-to-32')
221 if warnings_as_errors
in sys.argv:
222 extra_compile_args.append(
'-Werror')
223 sys.argv.remove(warnings_as_errors)
226 ext_module_list.extend([
228 "google.protobuf.pyext._message",
229 glob.glob(
'google/protobuf/pyext/*.cc'),
230 include_dirs=[
".",
"../src"],
232 extra_objects=extra_objects,
233 library_dirs=[
'../src/.libs'],
234 extra_compile_args=extra_compile_args,
237 "google.protobuf.internal._api_implementation",
238 glob.glob(
'google/protobuf/internal/api_implementation.cc'),
239 extra_compile_args=extra_compile_args + [
'-DPYTHON_PROTO2_CPP_IMPL_V2'],
242 os.environ[
'PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] =
'cpp'
245 install_requires = [
'six>=1.9',
'setuptools']
246 if sys.version_info <= (2,7):
247 install_requires.append(
'ordereddict')
248 install_requires.append(
'unittest2')
253 description=
'Protocol Buffers',
254 download_url=
'https://github.com/protocolbuffers/protobuf/releases',
255 long_description=
"Protocol Buffers are Google's data interchange format",
256 url=
'https://developers.google.com/protocol-buffers/',
257 maintainer=
'protobuf@googlegroups.com',
258 maintainer_email=
'protobuf@googlegroups.com',
259 license=
'3-Clause BSD License',
261 "Programming Language :: Python",
262 "Programming Language :: Python :: 2",
263 "Programming Language :: Python :: 2.7",
264 "Programming Language :: Python :: 3",
265 "Programming Language :: Python :: 3.3",
266 "Programming Language :: Python :: 3.4",
267 "Programming Language :: Python :: 3.5",
268 "Programming Language :: Python :: 3.6",
269 "Programming Language :: Python :: 3.7",
271 namespace_packages=[
'google'],
272 packages=find_packages(
274 'import_test_package',
277 test_suite=
'google.protobuf.internal',
280 'build_py': build_py,
281 'test_conformance': test_conformance,
283 install_requires=install_requires,
284 ext_modules=ext_module_list,