Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: third_party/protobuf/python/setup.py

Issue 1842653006: Update //third_party/protobuf to version 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/protobuf/python/mox.py ('k') | third_party/protobuf/python/tox.ini » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/protobuf/python/setup.py
diff --git a/third_party/protobuf/python/setup.py b/third_party/protobuf/python/setup.py
index 8a986298664eb676459f5ea0c51e35c2c0fcb097..2a5513b7176a21f27e860915eaa9beb5d9c0cc45 100755
--- a/third_party/protobuf/python/setup.py
+++ b/third_party/protobuf/python/setup.py
@@ -1,29 +1,24 @@
-#! /usr/bin/python
+#! /usr/bin/env python
#
# See README for usage instructions.
-import sys
+import glob
import os
import subprocess
+import sys
# We must use setuptools, not distutils, because we need to use the
# namespace_packages option for the "google" package.
-try:
- from setuptools import setup, Extension
-except ImportError:
- try:
- from ez_setup import use_setuptools
- use_setuptools()
- from setuptools import setup, Extension
- except ImportError:
- sys.stderr.write(
- "Could not import setuptools; make sure you have setuptools or "
- "ez_setup installed.\n")
- raise
+from setuptools import setup, Extension, find_packages
+
from distutils.command.clean import clean as _clean
-from distutils.command.build_py import build_py as _build_py
-from distutils.spawn import find_executable
-maintainer_email = "protobuf@googlegroups.com"
+if sys.version_info[0] == 3:
+ # Python 3
+ from distutils.command.build_py import build_py_2to3 as _build_py
+else:
+ # Python 2
+ from distutils.command.build_py import build_py as _build_py
+from distutils.spawn import find_executable
# Find the Protocol Compiler.
if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']):
@@ -39,23 +34,38 @@ elif os.path.exists("../vsprojects/Release/protoc.exe"):
else:
protoc = find_executable("protoc")
-def generate_proto(source):
+
+def GetVersion():
+ """Gets the version from google/protobuf/__init__.py
+
+ Do not import google.protobuf.__init__ directly, because an installed
+ protobuf library may be loaded instead."""
+
+ with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file:
+ exec(version_file.read(), globals())
+ return __version__
+
+
+def generate_proto(source, require = True):
"""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."""
+ if not require and not os.path.exists(source):
+ return
+
output = source.replace(".proto", "_pb2.py").replace("../src/", "")
if (not os.path.exists(output) or
(os.path.exists(source) and
os.path.getmtime(source) > os.path.getmtime(output))):
- print "Generating %s..." % output
+ print("Generating %s..." % output)
if not os.path.exists(source):
sys.stderr.write("Can't find required file: %s\n" % source)
sys.exit(-1)
- if protoc == None:
+ if protoc is None:
sys.stderr.write(
"protoc is not installed nor found in ../src. Please compile it "
"or install the binary package.\n")
@@ -66,54 +76,34 @@ def generate_proto(source):
sys.exit(-1)
def GenerateUnittestProtos():
- generate_proto("../src/google/protobuf/unittest.proto")
- generate_proto("../src/google/protobuf/unittest_custom_options.proto")
- generate_proto("../src/google/protobuf/unittest_import.proto")
- generate_proto("../src/google/protobuf/unittest_import_public.proto")
- generate_proto("../src/google/protobuf/unittest_mset.proto")
- generate_proto("../src/google/protobuf/unittest_no_generic_services.proto")
- generate_proto("google/protobuf/internal/test_bad_identifiers.proto")
- generate_proto("google/protobuf/internal/more_extensions.proto")
- generate_proto("google/protobuf/internal/more_extensions_dynamic.proto")
- generate_proto("google/protobuf/internal/more_messages.proto")
- generate_proto("google/protobuf/internal/factory_test1.proto")
- generate_proto("google/protobuf/internal/factory_test2.proto")
-
-def MakeTestSuite():
- # This is apparently needed on some systems to make sure that the tests
- # work even if a previous version is already installed.
- if 'google' in sys.modules:
- del sys.modules['google']
- GenerateUnittestProtos()
-
- import unittest
- import google.protobuf.internal.generator_test as generator_test
- import google.protobuf.internal.descriptor_test as descriptor_test
- import google.protobuf.internal.reflection_test as reflection_test
- import google.protobuf.internal.service_reflection_test \
- as service_reflection_test
- import google.protobuf.internal.text_format_test as text_format_test
- import google.protobuf.internal.wire_format_test as wire_format_test
- import google.protobuf.internal.unknown_fields_test as unknown_fields_test
- import google.protobuf.internal.descriptor_database_test \
- as descriptor_database_test
- import google.protobuf.internal.descriptor_pool_test as descriptor_pool_test
- import google.protobuf.internal.message_factory_test as message_factory_test
- import google.protobuf.internal.message_cpp_test as message_cpp_test
- import google.protobuf.internal.reflection_cpp_generated_test \
- as reflection_cpp_generated_test
-
- loader = unittest.defaultTestLoader
- suite = unittest.TestSuite()
- for test in [ generator_test,
- descriptor_test,
- reflection_test,
- service_reflection_test,
- text_format_test,
- wire_format_test ]:
- suite.addTest(loader.loadTestsFromModule(test))
-
- return suite
+ generate_proto("../src/google/protobuf/map_unittest.proto", False)
+ 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)
+ 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)
+ generate_proto("../src/google/protobuf/unittest_mset_wire_format.proto", False)
+ generate_proto("../src/google/protobuf/unittest_no_generic_services.proto", False)
+ generate_proto("../src/google/protobuf/unittest_proto3_arena.proto", False)
+ generate_proto("../src/google/protobuf/util/json_format_proto3.proto", False)
+ generate_proto("google/protobuf/internal/any_test.proto", False)
+ 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)
+ 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)
+ generate_proto("google/protobuf/internal/message_set_extensions.proto", False)
+ 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)
+ generate_proto("google/protobuf/internal/packed_field_test.proto", False)
+ generate_proto("google/protobuf/internal/test_bad_identifiers.proto", False)
+ generate_proto("google/protobuf/pyext/python.proto", False)
class clean(_clean):
@@ -124,7 +114,8 @@ class clean(_clean):
filepath = os.path.join(dirpath, filename)
if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \
filepath.endswith(".so") or filepath.endswith(".o") or \
- filepath.endswith('google/protobuf/compiler/__init__.py'):
+ filepath.endswith('google/protobuf/compiler/__init__.py') or \
+ filepath.endswith('google/protobuf/util/__init__.py'):
os.remove(filepath)
# _clean is an old-style class, so super() doesn't work.
_clean.run(self)
@@ -134,63 +125,99 @@ class build_py(_build_py):
# Generate necessary .proto file if it doesn't exist.
generate_proto("../src/google/protobuf/descriptor.proto")
generate_proto("../src/google/protobuf/compiler/plugin.proto")
-
+ generate_proto("../src/google/protobuf/any.proto")
+ generate_proto("../src/google/protobuf/api.proto")
+ generate_proto("../src/google/protobuf/duration.proto")
+ generate_proto("../src/google/protobuf/empty.proto")
+ generate_proto("../src/google/protobuf/field_mask.proto")
+ 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")
GenerateUnittestProtos()
- # Make sure google.protobuf.compiler is a valid package.
- open('google/protobuf/compiler/__init__.py', 'a').close()
+
+ # Make sure google.protobuf/** are valid packages.
+ for path in ['', 'internal/', 'compiler/', 'pyext/', 'util/']:
+ try:
+ open('google/protobuf/%s__init__.py' % path, 'a').close()
+ except EnvironmentError:
+ pass
# _build_py is an old-style class, so super() doesn't work.
_build_py.run(self)
+class test_conformance(_build_py):
+ target = 'test_python'
+ def run(self):
+ cmd = 'cd ../conformance && make %s' % (test_conformance.target)
+ status = subprocess.check_call(cmd, shell=True)
+
+
if __name__ == '__main__':
ext_module_list = []
-
- # C++ implementation extension
- if os.getenv("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python") == "cpp":
- print "Using EXPERIMENTAL C++ Implmenetation."
- ext_module_list.append(Extension(
- "google.protobuf.internal._net_proto2___python",
- [ "google/protobuf/pyext/python_descriptor.cc",
- "google/protobuf/pyext/python_protobuf.cc",
- "google/protobuf/pyext/python-proto2.cc" ],
- include_dirs = [ "." ],
- libraries = [ "protobuf" ]))
-
- setup(name = 'protobuf',
- version = '2.5.0-pre',
- packages = [ 'google' ],
- namespace_packages = [ 'google' ],
- test_suite = 'setup.MakeTestSuite',
- # Must list modules explicitly so that we don't install tests.
- py_modules = [
- 'google.protobuf.internal.api_implementation',
- 'google.protobuf.internal.containers',
- 'google.protobuf.internal.cpp_message',
- 'google.protobuf.internal.decoder',
- 'google.protobuf.internal.encoder',
- 'google.protobuf.internal.enum_type_wrapper',
- 'google.protobuf.internal.message_listener',
- 'google.protobuf.internal.python_message',
- 'google.protobuf.internal.type_checkers',
- 'google.protobuf.internal.wire_format',
- 'google.protobuf.descriptor',
- 'google.protobuf.descriptor_pb2',
- 'google.protobuf.compiler.plugin_pb2',
- 'google.protobuf.message',
- 'google.protobuf.descriptor_database',
- 'google.protobuf.descriptor_pool',
- 'google.protobuf.message_factory',
- 'google.protobuf.reflection',
- 'google.protobuf.service',
- 'google.protobuf.service_reflection',
- 'google.protobuf.text_format' ],
- cmdclass = { 'clean': clean, 'build_py': build_py },
- install_requires = ['setuptools'],
- ext_modules = ext_module_list,
- url = 'http://code.google.com/p/protobuf/',
- maintainer = maintainer_email,
- maintainer_email = 'protobuf@googlegroups.com',
- license = 'New BSD License',
- description = 'Protocol Buffers',
- long_description =
- "Protocol Buffers are Google's data interchange format.",
+ cpp_impl = '--cpp_implementation'
+ warnings_as_errors = '--warnings_as_errors'
+ if cpp_impl in sys.argv:
+ sys.argv.remove(cpp_impl)
+ extra_compile_args = ['-Wno-write-strings', '-Wno-invalid-offsetof']
+ test_conformance.target = 'test_python_cpp'
+
+ if "clang" in os.popen('$CC --version').read():
+ extra_compile_args.append('-Wno-shorten-64-to-32')
+
+ if warnings_as_errors in sys.argv:
+ extra_compile_args.append('-Werror')
+ sys.argv.remove(warnings_as_errors)
+
+ # C++ implementation extension
+ ext_module_list.append(
+ Extension(
+ "google.protobuf.pyext._message",
+ glob.glob('google/protobuf/pyext/*.cc'),
+ include_dirs=[".", "../src"],
+ libraries=['protobuf'],
+ library_dirs=['../src/.libs'],
+ extra_compile_args=extra_compile_args,
)
+ )
+ os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp'
+
+ # Keep this list of dependencies in sync with tox.ini.
+ install_requires = ['six>=1.9', 'setuptools']
+ if sys.version_info <= (2,7):
+ install_requires.append('ordereddict')
+ install_requires.append('unittest2')
+
+ setup(
+ name='protobuf',
+ version=GetVersion(),
+ description='Protocol Buffers',
+ 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',
+ license='New BSD License',
+ classifiers=[
+ "Programming Language :: Python",
+ "Programming Language :: Python :: 2",
+ "Programming Language :: Python :: 2.6",
+ "Programming Language :: Python :: 2.7",
+ "Programming Language :: Python :: 3",
+ "Programming Language :: Python :: 3.3",
+ "Programming Language :: Python :: 3.4",
+ ],
+ namespace_packages=['google'],
+ packages=find_packages(
+ exclude=[
+ 'import_test_package',
+ ],
+ ),
+ test_suite='google.protobuf.internal',
+ cmdclass={
+ 'clean': clean,
+ 'build_py': build_py,
+ 'test_conformance': test_conformance,
+ },
+ install_requires=install_requires,
+ ext_modules=ext_module_list,
+ )
« no previous file with comments | « third_party/protobuf/python/mox.py ('k') | third_party/protobuf/python/tox.ini » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698