2015-04-12 03:23:45 +00:00
|
|
|
#! /usr/bin/env python
|
2008-07-10 02:12:20 +00:00
|
|
|
#
|
|
|
|
# See README for usage instructions.
|
2018-11-29 00:45:16 +00:00
|
|
|
from distutils import util
|
2015-05-08 12:48:40 +00:00
|
|
|
import glob
|
2012-08-01 06:22:19 +00:00
|
|
|
import os
|
2018-11-29 00:45:16 +00:00
|
|
|
import pkg_resources
|
|
|
|
import re
|
2012-08-01 06:22:19 +00:00
|
|
|
import subprocess
|
2015-05-08 12:48:40 +00:00
|
|
|
import sys
|
2018-11-29 00:45:16 +00:00
|
|
|
import sysconfig
|
2017-01-31 17:17:32 +00:00
|
|
|
import platform
|
2008-07-10 02:12:20 +00:00
|
|
|
|
|
|
|
# We must use setuptools, not distutils, because we need to use the
|
|
|
|
# namespace_packages option for the "google" package.
|
2015-08-20 17:51:26 +00:00
|
|
|
from setuptools import setup, Extension, find_packages
|
2015-04-12 01:24:24 +00:00
|
|
|
|
2018-09-10 20:35:38 +00:00
|
|
|
from distutils.command.build_py import build_py as _build_py
|
2012-08-01 06:22:19 +00:00
|
|
|
from distutils.command.clean import clean as _clean
|
2008-07-10 02:12:20 +00:00
|
|
|
from distutils.spawn import find_executable
|
|
|
|
|
|
|
|
# Find the Protocol Compiler.
|
2012-12-05 01:25:12 +00:00
|
|
|
if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']):
|
|
|
|
protoc = os.environ['PROTOC']
|
2020-03-31 23:25:37 +00:00
|
|
|
elif os.path.exists("../src/protoc"):
|
|
|
|
protoc = "../src/protoc"
|
|
|
|
elif os.path.exists("../src/protoc.exe"):
|
|
|
|
protoc = "../src/protoc.exe"
|
|
|
|
elif os.path.exists("../vsprojects/Debug/protoc.exe"):
|
|
|
|
protoc = "../vsprojects/Debug/protoc.exe"
|
|
|
|
elif os.path.exists("../vsprojects/Release/protoc.exe"):
|
|
|
|
protoc = "../vsprojects/Release/protoc.exe"
|
2008-07-10 02:12:20 +00:00
|
|
|
else:
|
|
|
|
protoc = find_executable("protoc")
|
|
|
|
|
2015-04-12 01:24:24 +00:00
|
|
|
|
2015-03-05 00:45:13 +00:00
|
|
|
def GetVersion():
|
|
|
|
"""Gets the version from google/protobuf/__init__.py
|
|
|
|
|
2015-04-12 01:24:24 +00:00
|
|
|
Do not import google.protobuf.__init__ directly, because an installed
|
|
|
|
protobuf library may be loaded instead."""
|
2015-03-05 00:45:13 +00:00
|
|
|
|
2020-03-31 23:25:37 +00:00
|
|
|
with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file:
|
2015-05-07 17:04:56 +00:00
|
|
|
exec(version_file.read(), globals())
|
2018-06-25 17:50:40 +00:00
|
|
|
global __version__
|
2015-03-05 00:45:13 +00:00
|
|
|
return __version__
|
|
|
|
|
|
|
|
|
2015-05-26 07:11:09 +00:00
|
|
|
def generate_proto(source, require = True):
|
2008-07-10 02:12:20 +00:00
|
|
|
"""Invokes the Protocol Compiler to generate a _pb2.py from the given
|
|
|
|
.proto file. Does nothing if the output already exists and is newer than
|
|
|
|
the input."""
|
|
|
|
|
2015-05-26 07:11:09 +00:00
|
|
|
if not require and not os.path.exists(source):
|
|
|
|
return
|
|
|
|
|
2020-03-31 23:25:37 +00:00
|
|
|
output = source.replace(".proto", "_pb2.py").replace("../src/", "")
|
2008-07-10 02:12:20 +00:00
|
|
|
|
|
|
|
if (not os.path.exists(output) or
|
|
|
|
(os.path.exists(source) and
|
|
|
|
os.path.getmtime(source) > os.path.getmtime(output))):
|
2020-03-31 23:25:37 +00:00
|
|
|
print("Generating %s..." % output)
|
2008-07-10 02:12:20 +00:00
|
|
|
|
2012-08-01 06:22:19 +00:00
|
|
|
if not os.path.exists(source):
|
|
|
|
sys.stderr.write("Can't find required file: %s\n" % source)
|
|
|
|
sys.exit(-1)
|
|
|
|
|
2015-04-12 01:24:24 +00:00
|
|
|
if protoc is None:
|
2008-07-10 02:12:20 +00:00
|
|
|
sys.stderr.write(
|
|
|
|
"protoc is not installed nor found in ../src. Please compile it "
|
|
|
|
"or install the binary package.\n")
|
|
|
|
sys.exit(-1)
|
|
|
|
|
2020-03-31 23:25:37 +00:00
|
|
|
protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ]
|
2009-04-18 02:28:15 +00:00
|
|
|
if subprocess.call(protoc_command) != 0:
|
2008-07-10 02:12:20 +00:00
|
|
|
sys.exit(-1)
|
|
|
|
|
2012-09-22 02:40:50 +00:00
|
|
|
def GenerateUnittestProtos():
|
2016-06-29 22:23:27 +00:00
|
|
|
generate_proto("../src/google/protobuf/any_test.proto", False)
|
2017-09-12 17:32:01 +00:00
|
|
|
generate_proto("../src/google/protobuf/map_proto2_unittest.proto", False)
|
2015-05-26 07:11:09 +00:00
|
|
|
generate_proto("../src/google/protobuf/map_unittest.proto", False)
|
2016-12-03 16:51:25 +00:00
|
|
|
generate_proto("../src/google/protobuf/test_messages_proto3.proto", False)
|
2017-06-28 01:24:15 +00:00
|
|
|
generate_proto("../src/google/protobuf/test_messages_proto2.proto", False)
|
2015-08-21 18:18:45 +00:00
|
|
|
generate_proto("../src/google/protobuf/unittest_arena.proto", False)
|
|
|
|
generate_proto("../src/google/protobuf/unittest_no_arena.proto", False)
|
|
|
|
generate_proto("../src/google/protobuf/unittest_no_arena_import.proto", False)
|
2015-05-26 07:11:09 +00:00
|
|
|
generate_proto("../src/google/protobuf/unittest.proto", False)
|
|
|
|
generate_proto("../src/google/protobuf/unittest_custom_options.proto", False)
|
|
|
|
generate_proto("../src/google/protobuf/unittest_import.proto", False)
|
|
|
|
generate_proto("../src/google/protobuf/unittest_import_public.proto", False)
|
|
|
|
generate_proto("../src/google/protobuf/unittest_mset.proto", False)
|
2015-08-21 18:18:45 +00:00
|
|
|
generate_proto("../src/google/protobuf/unittest_mset_wire_format.proto", False)
|
2015-05-26 07:11:09 +00:00
|
|
|
generate_proto("../src/google/protobuf/unittest_no_generic_services.proto", False)
|
|
|
|
generate_proto("../src/google/protobuf/unittest_proto3_arena.proto", False)
|
2019-06-11 23:00:16 +00:00
|
|
|
generate_proto("../src/google/protobuf/util/json_format.proto", False)
|
2015-10-05 18:59:43 +00:00
|
|
|
generate_proto("../src/google/protobuf/util/json_format_proto3.proto", False)
|
2015-12-12 01:09:20 +00:00
|
|
|
generate_proto("google/protobuf/internal/any_test.proto", False)
|
2015-05-26 07:11:09 +00:00
|
|
|
generate_proto("google/protobuf/internal/descriptor_pool_test1.proto", False)
|
|
|
|
generate_proto("google/protobuf/internal/descriptor_pool_test2.proto", False)
|
|
|
|
generate_proto("google/protobuf/internal/factory_test1.proto", False)
|
|
|
|
generate_proto("google/protobuf/internal/factory_test2.proto", False)
|
2016-06-29 22:23:27 +00:00
|
|
|
generate_proto("google/protobuf/internal/file_options_test.proto", False)
|
2015-05-26 07:11:09 +00:00
|
|
|
generate_proto("google/protobuf/internal/import_test_package/inner.proto", False)
|
|
|
|
generate_proto("google/protobuf/internal/import_test_package/outer.proto", False)
|
|
|
|
generate_proto("google/protobuf/internal/missing_enum_values.proto", False)
|
2015-08-21 18:18:45 +00:00
|
|
|
generate_proto("google/protobuf/internal/message_set_extensions.proto", False)
|
2015-05-26 07:11:09 +00:00
|
|
|
generate_proto("google/protobuf/internal/more_extensions.proto", False)
|
|
|
|
generate_proto("google/protobuf/internal/more_extensions_dynamic.proto", False)
|
|
|
|
generate_proto("google/protobuf/internal/more_messages.proto", False)
|
2018-03-14 20:01:55 +00:00
|
|
|
generate_proto("google/protobuf/internal/no_package.proto", False)
|
2015-08-21 18:18:45 +00:00
|
|
|
generate_proto("google/protobuf/internal/packed_field_test.proto", False)
|
2015-05-26 07:11:09 +00:00
|
|
|
generate_proto("google/protobuf/internal/test_bad_identifiers.proto", False)
|
2020-04-08 17:30:17 +00:00
|
|
|
generate_proto("google/protobuf/internal/test_proto3_optional.proto", False)
|
2015-05-26 07:11:09 +00:00
|
|
|
generate_proto("google/protobuf/pyext/python.proto", False)
|
2012-08-01 06:22:19 +00:00
|
|
|
|
2015-04-12 01:24:24 +00:00
|
|
|
|
2012-08-01 06:22:19 +00:00
|
|
|
class clean(_clean):
|
|
|
|
def run(self):
|
|
|
|
# Delete generated files in the code tree.
|
2020-03-31 23:25:37 +00:00
|
|
|
for (dirpath, dirnames, filenames) in os.walk("."):
|
2008-07-10 02:12:20 +00:00
|
|
|
for filename in filenames:
|
|
|
|
filepath = os.path.join(dirpath, filename)
|
2010-11-02 13:14:58 +00:00
|
|
|
if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \
|
2018-04-09 19:43:10 +00:00
|
|
|
filepath.endswith(".so") or filepath.endswith(".o"):
|
2008-07-10 02:12:20 +00:00
|
|
|
os.remove(filepath)
|
2012-08-01 06:22:19 +00:00
|
|
|
# _clean is an old-style class, so super() doesn't work.
|
|
|
|
_clean.run(self)
|
|
|
|
|
|
|
|
class build_py(_build_py):
|
|
|
|
def run(self):
|
2008-07-10 02:12:20 +00:00
|
|
|
# Generate necessary .proto file if it doesn't exist.
|
|
|
|
generate_proto("../src/google/protobuf/descriptor.proto")
|
2010-12-08 03:45:27 +00:00
|
|
|
generate_proto("../src/google/protobuf/compiler/plugin.proto")
|
2015-10-06 21:20:26 +00:00
|
|
|
generate_proto("../src/google/protobuf/any.proto")
|
2015-10-06 21:26:00 +00:00
|
|
|
generate_proto("../src/google/protobuf/api.proto")
|
|
|
|
generate_proto("../src/google/protobuf/duration.proto")
|
|
|
|
generate_proto("../src/google/protobuf/empty.proto")
|
2015-10-06 21:20:26 +00:00
|
|
|
generate_proto("../src/google/protobuf/field_mask.proto")
|
2015-10-06 21:26:00 +00:00
|
|
|
generate_proto("../src/google/protobuf/source_context.proto")
|
|
|
|
generate_proto("../src/google/protobuf/struct.proto")
|
|
|
|
generate_proto("../src/google/protobuf/timestamp.proto")
|
|
|
|
generate_proto("../src/google/protobuf/type.proto")
|
|
|
|
generate_proto("../src/google/protobuf/wrappers.proto")
|
2014-08-12 21:10:30 +00:00
|
|
|
GenerateUnittestProtos()
|
|
|
|
|
2012-08-01 06:22:19 +00:00
|
|
|
# _build_py is an old-style class, so super() doesn't work.
|
|
|
|
_build_py.run(self)
|
2010-12-08 03:45:27 +00:00
|
|
|
|
2015-08-17 19:30:49 +00:00
|
|
|
class test_conformance(_build_py):
|
|
|
|
target = 'test_python'
|
|
|
|
def run(self):
|
2018-06-25 22:20:53 +00:00
|
|
|
# Python 2.6 dodges these extra failures.
|
|
|
|
os.environ["CONFORMANCE_PYTHON_EXTRA_FAILURES"] = (
|
|
|
|
"--failure_list failure_list_python-post26.txt")
|
2015-12-03 20:54:54 +00:00
|
|
|
cmd = 'cd ../conformance && make %s' % (test_conformance.target)
|
|
|
|
status = subprocess.check_call(cmd, shell=True)
|
2015-08-17 19:30:49 +00:00
|
|
|
|
2010-12-08 03:45:27 +00:00
|
|
|
|
2016-03-25 17:58:46 +00:00
|
|
|
def get_option_from_sys_argv(option_str):
|
|
|
|
if option_str in sys.argv:
|
|
|
|
sys.argv.remove(option_str)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2014-08-12 21:10:30 +00:00
|
|
|
if __name__ == '__main__':
|
2014-08-25 20:17:53 +00:00
|
|
|
ext_module_list = []
|
2015-10-06 21:13:09 +00:00
|
|
|
warnings_as_errors = '--warnings_as_errors'
|
2016-03-25 17:58:46 +00:00
|
|
|
if get_option_from_sys_argv('--cpp_implementation'):
|
|
|
|
# Link libprotobuf.a and libprotobuf-lite.a statically with the
|
|
|
|
# extension. Note that those libraries have to be compiled with
|
|
|
|
# -fPIC for this to work.
|
|
|
|
compile_static_ext = get_option_from_sys_argv('--compile_static_extension')
|
|
|
|
libraries = ['protobuf']
|
|
|
|
extra_objects = None
|
|
|
|
if compile_static_ext:
|
|
|
|
libraries = None
|
|
|
|
extra_objects = ['../src/.libs/libprotobuf.a',
|
|
|
|
'../src/.libs/libprotobuf-lite.a']
|
2015-08-17 19:30:49 +00:00
|
|
|
test_conformance.target = 'test_python_cpp'
|
2015-10-07 18:46:23 +00:00
|
|
|
|
2018-04-02 22:55:28 +00:00
|
|
|
extra_compile_args = []
|
|
|
|
|
|
|
|
if sys.platform != 'win32':
|
|
|
|
extra_compile_args.append('-Wno-write-strings')
|
|
|
|
extra_compile_args.append('-Wno-invalid-offsetof')
|
|
|
|
extra_compile_args.append('-Wno-sign-compare')
|
2018-08-10 04:21:01 +00:00
|
|
|
extra_compile_args.append('-Wno-unused-variable')
|
2018-07-23 20:35:15 +00:00
|
|
|
extra_compile_args.append('-std=c++11')
|
2018-04-02 22:55:28 +00:00
|
|
|
|
2018-08-10 04:21:01 +00:00
|
|
|
if sys.platform == 'darwin':
|
|
|
|
extra_compile_args.append("-Wno-shorten-64-to-32");
|
2019-02-26 23:47:09 +00:00
|
|
|
extra_compile_args.append("-Wno-deprecated-register");
|
2018-08-10 04:21:01 +00:00
|
|
|
|
2018-11-29 00:45:16 +00:00
|
|
|
# https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
|
|
|
|
# C++ projects must now migrate to libc++ and are recommended to set a
|
|
|
|
# deployment target of macOS 10.9 or later, or iOS 7 or later.
|
|
|
|
if sys.platform == 'darwin':
|
|
|
|
mac_target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
|
|
|
|
if mac_target and (pkg_resources.parse_version(mac_target) <
|
|
|
|
pkg_resources.parse_version('10.9.0')):
|
|
|
|
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.9'
|
|
|
|
os.environ['_PYTHON_HOST_PLATFORM'] = re.sub(
|
|
|
|
r'macosx-[0-9]+\.[0-9]+-(.+)', r'macosx-10.9-\1',
|
|
|
|
util.get_platform())
|
|
|
|
|
2018-04-02 22:55:28 +00:00
|
|
|
# https://github.com/Theano/Theano/issues/4926
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
extra_compile_args.append('-D_hypot=hypot')
|
|
|
|
|
|
|
|
# https://github.com/tpaviot/pythonocc-core/issues/48
|
|
|
|
if sys.platform == 'win32' and '64 bit' in sys.version:
|
|
|
|
extra_compile_args.append('-DMS_WIN64')
|
|
|
|
|
|
|
|
# MSVS default is dymanic
|
2018-04-06 22:43:32 +00:00
|
|
|
if (sys.platform == 'win32'):
|
2018-04-02 22:55:28 +00:00
|
|
|
extra_compile_args.append('/MT')
|
|
|
|
|
2015-12-22 19:13:03 +00:00
|
|
|
if "clang" in os.popen('$CC --version 2> /dev/null').read():
|
2015-10-07 18:46:23 +00:00
|
|
|
extra_compile_args.append('-Wno-shorten-64-to-32')
|
2015-10-06 21:13:09 +00:00
|
|
|
|
|
|
|
if warnings_as_errors in sys.argv:
|
|
|
|
extra_compile_args.append('-Werror')
|
|
|
|
sys.argv.remove(warnings_as_errors)
|
|
|
|
|
2014-08-25 20:17:53 +00:00
|
|
|
# C++ implementation extension
|
2016-03-25 17:58:46 +00:00
|
|
|
ext_module_list.extend([
|
2015-04-12 01:24:24 +00:00
|
|
|
Extension(
|
|
|
|
"google.protobuf.pyext._message",
|
2015-05-08 12:48:40 +00:00
|
|
|
glob.glob('google/protobuf/pyext/*.cc'),
|
2015-04-12 01:24:24 +00:00
|
|
|
include_dirs=[".", "../src"],
|
2016-03-25 17:58:46 +00:00
|
|
|
libraries=libraries,
|
|
|
|
extra_objects=extra_objects,
|
2015-04-12 01:24:24 +00:00
|
|
|
library_dirs=['../src/.libs'],
|
2015-10-06 21:13:09 +00:00
|
|
|
extra_compile_args=extra_compile_args,
|
2016-03-25 17:58:46 +00:00
|
|
|
),
|
|
|
|
Extension(
|
|
|
|
"google.protobuf.internal._api_implementation",
|
|
|
|
glob.glob('google/protobuf/internal/api_implementation.cc'),
|
2018-04-02 22:55:28 +00:00
|
|
|
extra_compile_args=extra_compile_args + ['-DPYTHON_PROTO2_CPP_IMPL_V2'],
|
2016-03-25 17:58:46 +00:00
|
|
|
),
|
|
|
|
])
|
2015-02-26 00:39:11 +00:00
|
|
|
os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp'
|
2010-11-02 13:14:58 +00:00
|
|
|
|
2015-08-21 00:49:45 +00:00
|
|
|
# Keep this list of dependencies in sync with tox.ini.
|
2015-12-29 22:36:46 +00:00
|
|
|
install_requires = ['six>=1.9', 'setuptools']
|
2015-08-15 02:54:53 +00:00
|
|
|
if sys.version_info <= (2,7):
|
|
|
|
install_requires.append('ordereddict')
|
|
|
|
install_requires.append('unittest2')
|
|
|
|
|
2015-04-12 01:24:24 +00:00
|
|
|
setup(
|
|
|
|
name='protobuf',
|
|
|
|
version=GetVersion(),
|
|
|
|
description='Protocol Buffers',
|
2018-08-22 18:55:30 +00:00
|
|
|
download_url='https://github.com/protocolbuffers/protobuf/releases',
|
2015-04-12 01:24:24 +00:00
|
|
|
long_description="Protocol Buffers are Google's data interchange format",
|
|
|
|
url='https://developers.google.com/protocol-buffers/',
|
|
|
|
maintainer='protobuf@googlegroups.com',
|
|
|
|
maintainer_email='protobuf@googlegroups.com',
|
2017-02-28 08:58:24 +00:00
|
|
|
license='3-Clause BSD License',
|
2015-04-12 01:24:24 +00:00
|
|
|
classifiers=[
|
2015-08-13 03:57:46 +00:00
|
|
|
"Programming Language :: Python",
|
|
|
|
"Programming Language :: Python :: 2",
|
|
|
|
"Programming Language :: Python :: 2.7",
|
|
|
|
"Programming Language :: Python :: 3",
|
|
|
|
"Programming Language :: Python :: 3.3",
|
|
|
|
"Programming Language :: Python :: 3.4",
|
2018-12-19 02:07:24 +00:00
|
|
|
"Programming Language :: Python :: 3.5",
|
|
|
|
"Programming Language :: Python :: 3.6",
|
|
|
|
"Programming Language :: Python :: 3.7",
|
2015-08-13 03:57:46 +00:00
|
|
|
],
|
2016-03-05 04:40:24 +00:00
|
|
|
namespace_packages=['google'],
|
2015-04-12 01:24:24 +00:00
|
|
|
packages=find_packages(
|
|
|
|
exclude=[
|
|
|
|
'import_test_package',
|
|
|
|
],
|
|
|
|
),
|
|
|
|
test_suite='google.protobuf.internal',
|
|
|
|
cmdclass={
|
|
|
|
'clean': clean,
|
|
|
|
'build_py': build_py,
|
2015-08-17 19:30:49 +00:00
|
|
|
'test_conformance': test_conformance,
|
2015-04-12 01:24:24 +00:00
|
|
|
},
|
2015-08-15 02:54:53 +00:00
|
|
|
install_requires=install_requires,
|
2015-04-12 01:24:24 +00:00
|
|
|
ext_modules=ext_module_list,
|
|
|
|
)
|