1ffe3c632Sopenharmony_ci#! /usr/bin/env python 2ffe3c632Sopenharmony_ci# 3ffe3c632Sopenharmony_ciimport glob 4ffe3c632Sopenharmony_ciimport os 5ffe3c632Sopenharmony_ciimport subprocess 6ffe3c632Sopenharmony_ciimport sys 7ffe3c632Sopenharmony_ci 8ffe3c632Sopenharmony_cifrom setuptools import setup, Extension, find_packages 9ffe3c632Sopenharmony_ci 10ffe3c632Sopenharmony_ciif sys.version_info[0] == 3: 11ffe3c632Sopenharmony_ci # Python 3 12ffe3c632Sopenharmony_ci from distutils.command.build_py import build_py_2to3 as _build_py 13ffe3c632Sopenharmony_cielse: 14ffe3c632Sopenharmony_ci # Python 2 15ffe3c632Sopenharmony_ci from distutils.command.build_py import build_py as _build_py 16ffe3c632Sopenharmony_cifrom distutils.spawn import find_executable 17ffe3c632Sopenharmony_ci 18ffe3c632Sopenharmony_cidef generate_proto(source, code_gen): 19ffe3c632Sopenharmony_ci """Invokes the Protocol Compiler to generate a _pb2.py from the given 20ffe3c632Sopenharmony_ci .proto file.""" 21ffe3c632Sopenharmony_ci output = source.replace(".proto", "_pb2.py").replace("protos/src/proto/", "").replace("protos/python/", "") 22ffe3c632Sopenharmony_ci 23ffe3c632Sopenharmony_ci if not os.path.exists(source): 24ffe3c632Sopenharmony_ci sys.stderr.write("Can't find required file: %s\n" % source) 25ffe3c632Sopenharmony_ci sys.exit(-1) 26ffe3c632Sopenharmony_ci 27ffe3c632Sopenharmony_ci protoc_command = [ code_gen, "-Iprotos/src/proto", "-Iprotos/python", "--python_out=.", source ] 28ffe3c632Sopenharmony_ci if subprocess.call(protoc_command) != 0: 29ffe3c632Sopenharmony_ci sys.exit(-1) 30ffe3c632Sopenharmony_ci 31ffe3c632Sopenharmony_ciclass build_py(_build_py): 32ffe3c632Sopenharmony_ci def run(self): 33ffe3c632Sopenharmony_ci # generate .proto file 34ffe3c632Sopenharmony_ci protoc_1 = "./protoc_1" 35ffe3c632Sopenharmony_ci protoc_2 = "./protoc_2" 36ffe3c632Sopenharmony_ci generate_proto("protos/src/proto/google/protobuf/unittest.proto", protoc_2) 37ffe3c632Sopenharmony_ci generate_proto("protos/src/proto/google/protobuf/unittest_custom_options.proto", protoc_1) 38ffe3c632Sopenharmony_ci generate_proto("protos/src/proto/google/protobuf/unittest_import.proto", protoc_1) 39ffe3c632Sopenharmony_ci generate_proto("protos/src/proto/google/protobuf/unittest_import_public.proto", protoc_1) 40ffe3c632Sopenharmony_ci generate_proto("protos/src/proto/google/protobuf/unittest_mset.proto", protoc_1) 41ffe3c632Sopenharmony_ci generate_proto("protos/src/proto/google/protobuf/unittest_no_generic_services.proto", protoc_1) 42ffe3c632Sopenharmony_ci generate_proto("protos/python/google/protobuf/internal/factory_test1.proto", protoc_1) 43ffe3c632Sopenharmony_ci generate_proto("protos/python/google/protobuf/internal/factory_test2.proto", protoc_1) 44ffe3c632Sopenharmony_ci generate_proto("protos/python/google/protobuf/internal/more_extensions.proto", protoc_1) 45ffe3c632Sopenharmony_ci generate_proto("protos/python/google/protobuf/internal/more_extensions_dynamic.proto", protoc_1) 46ffe3c632Sopenharmony_ci generate_proto("protos/python/google/protobuf/internal/more_messages.proto", protoc_1) 47ffe3c632Sopenharmony_ci generate_proto("protos/python/google/protobuf/internal/test_bad_identifiers.proto", protoc_1) 48ffe3c632Sopenharmony_ci 49ffe3c632Sopenharmony_ci # _build_py is an old-style class, so super() doesn't work. 50ffe3c632Sopenharmony_ci _build_py.run(self) 51ffe3c632Sopenharmony_ci 52ffe3c632Sopenharmony_ciif __name__ == '__main__': 53ffe3c632Sopenharmony_ci # Keep this list of dependencies in sync with tox.ini. 54ffe3c632Sopenharmony_ci install_requires = ['six>=1.9', 'setuptools'] 55ffe3c632Sopenharmony_ci if sys.version_info <= (2,7): 56ffe3c632Sopenharmony_ci install_requires.append('ordereddict') 57ffe3c632Sopenharmony_ci install_requires.append('unittest2') 58ffe3c632Sopenharmony_ci 59ffe3c632Sopenharmony_ci setup( 60ffe3c632Sopenharmony_ci name='protobuf', 61ffe3c632Sopenharmony_ci description='Protocol Buffers', 62ffe3c632Sopenharmony_ci download_url='https://github.com/protocolbuffers/protobuf/releases', 63ffe3c632Sopenharmony_ci long_description="Protocol Buffers are Google's data interchange format", 64ffe3c632Sopenharmony_ci url='https://developers.google.com/protocol-buffers/', 65ffe3c632Sopenharmony_ci maintainer='protobuf@googlegroups.com', 66ffe3c632Sopenharmony_ci maintainer_email='protobuf@googlegroups.com', 67ffe3c632Sopenharmony_ci license='3-Clause BSD License', 68ffe3c632Sopenharmony_ci classifiers=[ 69ffe3c632Sopenharmony_ci "Programming Language :: Python", 70ffe3c632Sopenharmony_ci "Programming Language :: Python :: 2", 71ffe3c632Sopenharmony_ci "Programming Language :: Python :: 2.6", 72ffe3c632Sopenharmony_ci "Programming Language :: Python :: 2.7", 73ffe3c632Sopenharmony_ci "Programming Language :: Python :: 3", 74ffe3c632Sopenharmony_ci "Programming Language :: Python :: 3.3", 75ffe3c632Sopenharmony_ci "Programming Language :: Python :: 3.4", 76ffe3c632Sopenharmony_ci ], 77ffe3c632Sopenharmony_ci packages=find_packages( 78ffe3c632Sopenharmony_ci exclude=[ 79ffe3c632Sopenharmony_ci 'import_test_package', 80ffe3c632Sopenharmony_ci ], 81ffe3c632Sopenharmony_ci ), 82ffe3c632Sopenharmony_ci test_suite='tests.google.protobuf.internal', 83ffe3c632Sopenharmony_ci cmdclass={ 84ffe3c632Sopenharmony_ci 'build_py': build_py, 85ffe3c632Sopenharmony_ci }, 86ffe3c632Sopenharmony_ci install_requires=install_requires, 87ffe3c632Sopenharmony_ci ) 88