From e17f78bbbf16bc318a9aa8776a100271936efb43 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Tue, 13 Jan 2015 14:09:54 -0500 Subject: Noramlize 'setup.py' to fit conventions: - Move human-centric metadata to top of 'setup()' call. - Add Trove classifiers for supported Python versions. - Use 'find_packages()' + MANIFEST.in to avoid errors in listing modules and packages. --- python/setup.py | 55 ++++++++++++++++++------------------------------------- 1 file changed, 18 insertions(+), 37 deletions(-) (limited to 'python/setup.py') diff --git a/python/setup.py b/python/setup.py index cfe25cc0..61ae8eac 100755 --- a/python/setup.py +++ b/python/setup.py @@ -8,12 +8,12 @@ import subprocess # 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 + from setuptools import setup, Extension, find_packages except ImportError: try: from ez_setup import use_setuptools use_setuptools() - from setuptools import setup, Extension + from setuptools import setup, Extension, find_packages except ImportError: sys.stderr.write( "Could not import setuptools; make sure you have setuptools or " @@ -164,37 +164,25 @@ if __name__ == '__main__': setup(name = 'protobuf', version = '3.0.0-pre', - packages = [ 'google' ], + description = 'Protocol Buffers', + long_description = + "Protocol Buffers are Google's data interchange format.", + url = 'https://developers.google.com/protocol-buffers/', + maintainer = maintainer_email, + maintainer_email = 'protobuf@googlegroups.com', + license = 'New BSD License', + classifiers=[ + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.6", + "Programming Language :: Python :: 2.7", + ], namespace_packages = [ 'google' ], + packages = find_packages( + exclude=[ + "import_test_package", + ]), test_suite = 'setup.MakeTestSuite', google_test_dir = "google/protobuf/internal", - # 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.proto_builder', - 'google.protobuf.pyext.cpp_message', - 'google.protobuf.reflection', - 'google.protobuf.service', - 'google.protobuf.service_reflection', - 'google.protobuf.symbol_database', - 'google.protobuf.text_encoding', - 'google.protobuf.text_format'], cmdclass = { 'clean': clean, 'build_py': build_py }, install_requires = ['setuptools'], # TODO: Restore dependency once a Python 3 compatible google-apputils @@ -203,11 +191,4 @@ if __name__ == '__main__': if sys.version_info[0] < 3 else []), ext_modules = ext_module_list, - url = 'https://developers.google.com/protocol-buffers/', - 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.", ) -- cgit v1.2.3 From 7ee25830c6707540242f441df5cd1c2a2000ca58 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Tue, 13 Jan 2015 14:47:32 -0500 Subject: Drop dependency on 'google.apputils'. Use stdlib's 'unittest' instead. --- .../internal/api_implementation_default_test.py | 6 ++--- .../protobuf/internal/descriptor_database_test.py | 7 +++--- .../protobuf/internal/descriptor_pool_test.py | 7 +++--- .../protobuf/internal/descriptor_python_test.py | 6 ++--- python/google/protobuf/internal/descriptor_test.py | 11 ++++----- python/google/protobuf/internal/generator_test.py | 9 ++++---- .../internal/message_factory_python_test.py | 6 ++--- .../protobuf/internal/message_factory_test.py | 26 ++++++++++++---------- .../protobuf/internal/message_python_test.py | 6 ++--- python/google/protobuf/internal/message_test.py | 8 +++---- .../google/protobuf/internal/proto_builder_test.py | 6 ++--- python/google/protobuf/internal/reflection_test.py | 26 +++++++++++----------- .../protobuf/internal/service_reflection_test.py | 7 +++--- .../protobuf/internal/symbol_database_test.py | 7 +++--- .../google/protobuf/internal/text_encoding_test.py | 7 +++--- .../google/protobuf/internal/text_format_test.py | 8 +++---- .../protobuf/internal/unknown_fields_test.py | 13 ++++++----- .../google/protobuf/internal/wire_format_test.py | 7 +++--- .../google/protobuf/pyext/descriptor_cpp2_test.py | 6 ++--- .../protobuf/pyext/message_factory_cpp2_test.py | 6 ++--- .../pyext/reflection_cpp2_generated_test.py | 6 ++--- python/setup.py | 5 ----- 22 files changed, 100 insertions(+), 96 deletions(-) (limited to 'python/setup.py') diff --git a/python/google/protobuf/internal/api_implementation_default_test.py b/python/google/protobuf/internal/api_implementation_default_test.py index 78d5cf23..cb29e443 100644 --- a/python/google/protobuf/internal/api_implementation_default_test.py +++ b/python/google/protobuf/internal/api_implementation_default_test.py @@ -34,16 +34,16 @@ import os import sys +import unittest # Clear environment implementation settings before the google3 imports. os.environ.pop('PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION', None) os.environ.pop('PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION', None) # pylint: disable=g-import-not-at-top -from google.apputils import basetest from google.protobuf.internal import api_implementation -class ApiImplementationDefaultTest(basetest.TestCase): +class ApiImplementationDefaultTest(unittest.TestCase): if sys.version_info.major <= 2: @@ -60,4 +60,4 @@ class ApiImplementationDefaultTest(basetest.TestCase): if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/descriptor_database_test.py b/python/google/protobuf/internal/descriptor_database_test.py index 8970f5c2..edf66a63 100644 --- a/python/google/protobuf/internal/descriptor_database_test.py +++ b/python/google/protobuf/internal/descriptor_database_test.py @@ -34,13 +34,14 @@ __author__ = 'matthewtoia@google.com (Matt Toia)' -from google.apputils import basetest +import unittest + from google.protobuf import descriptor_pb2 from google.protobuf.internal import factory_test2_pb2 from google.protobuf import descriptor_database -class DescriptorDatabaseTest(basetest.TestCase): +class DescriptorDatabaseTest(unittest.TestCase): def testAdd(self): db = descriptor_database.DescriptorDatabase() @@ -62,4 +63,4 @@ class DescriptorDatabaseTest(basetest.TestCase): 'google.protobuf.python.internal.MessageWithNestedEnumOnly.NestedEnum')) if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/descriptor_pool_test.py b/python/google/protobuf/internal/descriptor_pool_test.py index 11ef61c5..6d04ebaa 100644 --- a/python/google/protobuf/internal/descriptor_pool_test.py +++ b/python/google/protobuf/internal/descriptor_pool_test.py @@ -37,7 +37,6 @@ __author__ = 'matthewtoia@google.com (Matt Toia)' import os import unittest -from google.apputils import basetest from google.protobuf import unittest_pb2 from google.protobuf import descriptor_pb2 from google.protobuf.internal import api_implementation @@ -51,7 +50,7 @@ from google.protobuf import descriptor_pool from google.protobuf import symbol_database -class DescriptorPoolTest(basetest.TestCase): +class DescriptorPoolTest(unittest.TestCase): def setUp(self): self.pool = descriptor_pool.DescriptorPool() @@ -426,7 +425,7 @@ class ExtensionField(object): test.assertEqual(self.extended_type, field_desc.containing_type.name) -class AddDescriptorTest(basetest.TestCase): +class AddDescriptorTest(unittest.TestCase): def _TestMessage(self, prefix): pool = descriptor_pool.DescriptorPool() @@ -588,4 +587,4 @@ TEST2_FILE = ProtoFile( if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/descriptor_python_test.py b/python/google/protobuf/internal/descriptor_python_test.py index 5471ae02..573c1b9d 100644 --- a/python/google/protobuf/internal/descriptor_python_test.py +++ b/python/google/protobuf/internal/descriptor_python_test.py @@ -33,22 +33,22 @@ """Unittest for descriptor.py for the pure Python implementation.""" import os +import unittest os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python' # We must set the implementation version above before the google3 imports. # pylint: disable=g-import-not-at-top -from google.apputils import basetest from google.protobuf.internal import api_implementation # Run all tests from the original module by putting them in our namespace. # pylint: disable=wildcard-import from google.protobuf.internal.descriptor_test import * -class ConfirmPurePythonTest(basetest.TestCase): +class ConfirmPurePythonTest(unittest.TestCase): def testImplementationSetting(self): self.assertEqual('python', api_implementation.Type()) if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/descriptor_test.py b/python/google/protobuf/internal/descriptor_test.py index 3924f21a..13de7e1e 100755 --- a/python/google/protobuf/internal/descriptor_test.py +++ b/python/google/protobuf/internal/descriptor_test.py @@ -34,7 +34,8 @@ __author__ = 'robinson@google.com (Will Robinson)' -from google.apputils import basetest +import unittest + from google.protobuf import unittest_custom_options_pb2 from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_pb2 @@ -48,7 +49,7 @@ name: 'TestEmptyMessage' """ -class DescriptorTest(basetest.TestCase): +class DescriptorTest(unittest.TestCase): def setUp(self): self.my_file = descriptor.FileDescriptor( @@ -395,7 +396,7 @@ class DescriptorTest(basetest.TestCase): self.assertEqual(self.my_file.package, 'protobuf_unittest') -class DescriptorCopyToProtoTest(basetest.TestCase): +class DescriptorCopyToProtoTest(unittest.TestCase): """Tests for CopyTo functions of Descriptor.""" def _AssertProtoEqual(self, actual_proto, expected_class, expected_ascii): @@ -594,7 +595,7 @@ class DescriptorCopyToProtoTest(basetest.TestCase): TEST_SERVICE_ASCII) -class MakeDescriptorTest(basetest.TestCase): +class MakeDescriptorTest(unittest.TestCase): def testMakeDescriptorWithNestedFields(self): file_descriptor_proto = descriptor_pb2.FileDescriptorProto() @@ -676,4 +677,4 @@ class MakeDescriptorTest(basetest.TestCase): options.Extensions[unittest_custom_options_pb2.msgopt].i) if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/generator_test.py b/python/google/protobuf/internal/generator_test.py index 03361e66..6aaefe3b 100755 --- a/python/google/protobuf/internal/generator_test.py +++ b/python/google/protobuf/internal/generator_test.py @@ -41,7 +41,8 @@ further ensures that we can use Python protocol message objects as we expect. __author__ = 'robinson@google.com (Will Robinson)' -from google.apputils import basetest +import unittest + from google.protobuf.internal import test_bad_identifiers_pb2 from google.protobuf import unittest_custom_options_pb2 from google.protobuf import unittest_import_pb2 @@ -55,7 +56,7 @@ from google.protobuf import symbol_database MAX_EXTENSION = 536870912 -class GeneratorTest(basetest.TestCase): +class GeneratorTest(unittest.TestCase): def testNestedMessageDescriptor(self): field_name = 'optional_nested_message' @@ -301,7 +302,7 @@ class GeneratorTest(basetest.TestCase): self.assertIsNone(field_desc.containing_oneof) -class SymbolDatabaseRegistrationTest(basetest.TestCase): +class SymbolDatabaseRegistrationTest(unittest.TestCase): """Checks that messages, enums and files are correctly registered.""" def testGetSymbol(self): @@ -340,4 +341,4 @@ class SymbolDatabaseRegistrationTest(basetest.TestCase): 'google/protobuf/unittest.proto').name) if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/message_factory_python_test.py b/python/google/protobuf/internal/message_factory_python_test.py index 85e02b25..eeb164b1 100644 --- a/python/google/protobuf/internal/message_factory_python_test.py +++ b/python/google/protobuf/internal/message_factory_python_test.py @@ -33,22 +33,22 @@ """Tests for ..public.message_factory for the pure Python implementation.""" import os +import unittest os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python' # We must set the implementation version above before the google3 imports. # pylint: disable=g-import-not-at-top -from google.apputils import basetest from google.protobuf.internal import api_implementation # Run all tests from the original module by putting them in our namespace. # pylint: disable=wildcard-import from google.protobuf.internal.message_factory_test import * -class ConfirmPurePythonTest(basetest.TestCase): +class ConfirmPurePythonTest(unittest.TestCase): def testImplementationSetting(self): self.assertEqual('python', api_implementation.Type()) if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/message_factory_test.py b/python/google/protobuf/internal/message_factory_test.py index fcf13410..45ddcd26 100644 --- a/python/google/protobuf/internal/message_factory_test.py +++ b/python/google/protobuf/internal/message_factory_test.py @@ -34,7 +34,8 @@ __author__ = 'matthewtoia@google.com (Matt Toia)' -from google.apputils import basetest +import unittest + from google.protobuf import descriptor_pb2 from google.protobuf.internal import factory_test1_pb2 from google.protobuf.internal import factory_test2_pb2 @@ -43,7 +44,7 @@ from google.protobuf import descriptor_pool from google.protobuf import message_factory -class MessageFactoryTest(basetest.TestCase): +class MessageFactoryTest(unittest.TestCase): def setUp(self): self.factory_test1_fd = descriptor_pb2.FileDescriptorProto.FromString( @@ -104,17 +105,18 @@ class MessageFactoryTest(basetest.TestCase): for _ in range(2): messages = message_factory.GetMessages([self.factory_test2_fd, self.factory_test1_fd]) - self.assertContainsSubset( - ['google.protobuf.python.internal.Factory2Message', - 'google.protobuf.python.internal.Factory1Message'], - messages.keys()) + self.assertTrue( + set(['google.protobuf.python.internal.Factory2Message', + 'google.protobuf.python.internal.Factory1Message'], + ).issubset(set(messages.keys()))) self._ExerciseDynamicClass( messages['google.protobuf.python.internal.Factory2Message']) - self.assertContainsSubset( - ['google.protobuf.python.internal.Factory2Message.one_more_field', - 'google.protobuf.python.internal.another_field'], - (messages['google.protobuf.python.internal.Factory1Message'] - ._extensions_by_name.keys())) + self.assertTrue( + set(['google.protobuf.python.internal.Factory2Message.one_more_field', + 'google.protobuf.python.internal.another_field'], + ).issubset( + set(messages['google.protobuf.python.internal.Factory1Message'] + ._extensions_by_name.keys()))) factory_msg1 = messages['google.protobuf.python.internal.Factory1Message'] msg1 = messages['google.protobuf.python.internal.Factory1Message']() ext1 = factory_msg1._extensions_by_name[ @@ -128,4 +130,4 @@ class MessageFactoryTest(basetest.TestCase): if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/message_python_test.py b/python/google/protobuf/internal/message_python_test.py index c40623a8..ef57967b 100644 --- a/python/google/protobuf/internal/message_python_test.py +++ b/python/google/protobuf/internal/message_python_test.py @@ -33,22 +33,22 @@ """Tests for ..public.message for the pure Python implementation.""" import os +import unittest os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python' # We must set the implementation version above before the google3 imports. # pylint: disable=g-import-not-at-top -from google.apputils import basetest from google.protobuf.internal import api_implementation # Run all tests from the original module by putting them in our namespace. # pylint: disable=wildcard-import from google.protobuf.internal.message_test import * -class ConfirmPurePythonTest(basetest.TestCase): +class ConfirmPurePythonTest(unittest.TestCase): def testImplementationSetting(self): self.assertEqual('python', api_implementation.Type()) if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 42e2ad7e..4227c480 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -48,8 +48,8 @@ import math import operator import pickle import sys +import unittest -from google.apputils import basetest from google.protobuf import unittest_pb2 from google.protobuf.internal import api_implementation from google.protobuf.internal import test_util @@ -69,7 +69,7 @@ def IsNegInf(val): return isinf(val) and (val < 0) -class MessageTest(basetest.TestCase): +class MessageTest(unittest.TestCase): def testBadUtf8String(self): if api_implementation.Type() != 'python': @@ -695,7 +695,7 @@ class MessageTest(basetest.TestCase): m.HasField('repeated_int32') -class ValidTypeNamesTest(basetest.TestCase): +class ValidTypeNamesTest(unittest.TestCase): def assertImportFromName(self, msg, base_name): # Parse to extra 'some.name' as a string. @@ -718,4 +718,4 @@ class ValidTypeNamesTest(basetest.TestCase): if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/proto_builder_test.py b/python/google/protobuf/internal/proto_builder_test.py index c74db7e7..9229205a 100644 --- a/python/google/protobuf/internal/proto_builder_test.py +++ b/python/google/protobuf/internal/proto_builder_test.py @@ -32,7 +32,7 @@ """Tests for google.protobuf.proto_builder.""" -from google.apputils import basetest +import unittest from google.protobuf import descriptor_pb2 from google.protobuf import descriptor_pool @@ -40,7 +40,7 @@ from google.protobuf import proto_builder from google.protobuf import text_format -class ProtoBuilderTest(basetest.TestCase): +class ProtoBuilderTest(unittest.TestCase): def setUp(self): self._fields = { @@ -74,4 +74,4 @@ class ProtoBuilderTest(basetest.TestCase): if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 6b24b092..30a6e571 100755 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -39,8 +39,8 @@ import copy import gc import operator import struct +import unittest -from google.apputils import basetest from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 @@ -102,7 +102,7 @@ class _MiniDecoder(object): return self._pos == len(self._bytes) -class ReflectionTest(basetest.TestCase): +class ReflectionTest(unittest.TestCase): def assertListsEqual(self, values, others): self.assertEqual(len(values), len(others)) @@ -1619,7 +1619,7 @@ class ReflectionTest(basetest.TestCase): self.assertFalse(proto.IsInitialized(errors)) self.assertEqual(errors, ['a', 'b', 'c']) - @basetest.unittest.skipIf( + @unittest.skipIf( api_implementation.Type() != 'cpp' or api_implementation.Version() != 2, 'Errors are only available from the most recent C++ implementation.') def testFileDescriptorErrors(self): @@ -1797,7 +1797,7 @@ class ReflectionTest(basetest.TestCase): # into separate TestCase classes. -class TestAllTypesEqualityTest(basetest.TestCase): +class TestAllTypesEqualityTest(unittest.TestCase): def setUp(self): self.first_proto = unittest_pb2.TestAllTypes() @@ -1813,7 +1813,7 @@ class TestAllTypesEqualityTest(basetest.TestCase): self.assertEqual(self.first_proto, self.second_proto) -class FullProtosEqualityTest(basetest.TestCase): +class FullProtosEqualityTest(unittest.TestCase): """Equality tests using completely-full protos as a starting point.""" @@ -1899,7 +1899,7 @@ class FullProtosEqualityTest(basetest.TestCase): self.assertEqual(self.first_proto, self.second_proto) -class ExtensionEqualityTest(basetest.TestCase): +class ExtensionEqualityTest(unittest.TestCase): def testExtensionEquality(self): first_proto = unittest_pb2.TestAllExtensions() @@ -1932,7 +1932,7 @@ class ExtensionEqualityTest(basetest.TestCase): self.assertEqual(first_proto, second_proto) -class MutualRecursionEqualityTest(basetest.TestCase): +class MutualRecursionEqualityTest(unittest.TestCase): def testEqualityWithMutualRecursion(self): first_proto = unittest_pb2.TestMutualRecursionA() @@ -1944,7 +1944,7 @@ class MutualRecursionEqualityTest(basetest.TestCase): self.assertEqual(first_proto, second_proto) -class ByteSizeTest(basetest.TestCase): +class ByteSizeTest(unittest.TestCase): def setUp(self): self.proto = unittest_pb2.TestAllTypes() @@ -2240,7 +2240,7 @@ class ByteSizeTest(basetest.TestCase): # * Handling of empty submessages (with and without "has" # bits set). -class SerializationTest(basetest.TestCase): +class SerializationTest(unittest.TestCase): def testSerializeEmtpyMessage(self): first_proto = unittest_pb2.TestAllTypes() @@ -2791,7 +2791,7 @@ class SerializationTest(basetest.TestCase): self.assertEqual(3, proto.repeated_int32[2]) -class OptionsTest(basetest.TestCase): +class OptionsTest(unittest.TestCase): def testMessageOptions(self): proto = unittest_mset_pb2.TestMessageSet() @@ -2818,9 +2818,9 @@ class OptionsTest(basetest.TestCase): -class ClassAPITest(basetest.TestCase): +class ClassAPITest(unittest.TestCase): - @basetest.unittest.skipIf( + @unittest.skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, 'C++ implementation requires a call to MakeDescriptor()') def testMakeClassWithNestedDescriptor(self): @@ -2952,4 +2952,4 @@ class ClassAPITest(basetest.TestCase): self.assertEqual(msg.bar.baz.deep, 4) if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/service_reflection_test.py b/python/google/protobuf/internal/service_reflection_test.py index d066ae70..e3f71545 100755 --- a/python/google/protobuf/internal/service_reflection_test.py +++ b/python/google/protobuf/internal/service_reflection_test.py @@ -34,13 +34,14 @@ __author__ = 'petar@google.com (Petar Petrov)' -from google.apputils import basetest +import unittest + from google.protobuf import unittest_pb2 from google.protobuf import service_reflection from google.protobuf import service -class FooUnitTest(basetest.TestCase): +class FooUnitTest(unittest.TestCase): def testService(self): class MockRpcChannel(service.RpcChannel): @@ -133,4 +134,4 @@ class FooUnitTest(basetest.TestCase): if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/symbol_database_test.py b/python/google/protobuf/internal/symbol_database_test.py index 47572d58..a58cb1a4 100644 --- a/python/google/protobuf/internal/symbol_database_test.py +++ b/python/google/protobuf/internal/symbol_database_test.py @@ -32,12 +32,13 @@ """Tests for google.protobuf.symbol_database.""" -from google.apputils import basetest +import unittest + from google.protobuf import unittest_pb2 from google.protobuf import symbol_database -class SymbolDatabaseTest(basetest.TestCase): +class SymbolDatabaseTest(unittest.TestCase): def _Database(self): db = symbol_database.SymbolDatabase() @@ -117,4 +118,4 @@ class SymbolDatabaseTest(basetest.TestCase): if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/text_encoding_test.py b/python/google/protobuf/internal/text_encoding_test.py index db0222bd..48c30f01 100755 --- a/python/google/protobuf/internal/text_encoding_test.py +++ b/python/google/protobuf/internal/text_encoding_test.py @@ -32,7 +32,8 @@ """Tests for google.protobuf.text_encoding.""" -from google.apputils import basetest +import unittest + from google.protobuf import text_encoding TEST_VALUES = [ @@ -50,7 +51,7 @@ TEST_VALUES = [ b"\010\011\012\013\014\015")] -class TextEncodingTestCase(basetest.TestCase): +class TextEncodingTestCase(unittest.TestCase): def testCEscape(self): for escaped, escaped_utf8, unescaped in TEST_VALUES: self.assertEquals(escaped, @@ -65,4 +66,4 @@ class TextEncodingTestCase(basetest.TestCase): if __name__ == "__main__": - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py index 55e3c2c8..0af48645 100755 --- a/python/google/protobuf/internal/text_format_test.py +++ b/python/google/protobuf/internal/text_format_test.py @@ -35,15 +35,15 @@ __author__ = 'kenton@google.com (Kenton Varda)' import re +import unittest -from google.apputils import basetest from google.protobuf import text_format from google.protobuf.internal import api_implementation from google.protobuf.internal import test_util from google.protobuf import unittest_pb2 from google.protobuf import unittest_mset_pb2 -class TextFormatTest(basetest.TestCase): +class TextFormatTest(unittest.TestCase): def ReadGolden(self, golden_filename): with test_util.GoldenFile(golden_filename) as f: @@ -600,7 +600,7 @@ class TextFormatTest(basetest.TestCase): self.assertEqual('oneof_uint32', m2.WhichOneof('oneof_field')) -class TokenizerTest(basetest.TestCase): +class TokenizerTest(unittest.TestCase): def testSimpleTokenCases(self): text = ('identifier1:"string1"\n \n\n' @@ -745,4 +745,4 @@ class TokenizerTest(basetest.TestCase): if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/unknown_fields_test.py b/python/google/protobuf/internal/unknown_fields_test.py index a4dc1f7c..0650d92b 100755 --- a/python/google/protobuf/internal/unknown_fields_test.py +++ b/python/google/protobuf/internal/unknown_fields_test.py @@ -35,7 +35,8 @@ __author__ = 'bohdank@google.com (Bohdan Koval)' -from google.apputils import basetest +import unittest + from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 from google.protobuf.internal import api_implementation @@ -45,10 +46,10 @@ from google.protobuf.internal import test_util from google.protobuf.internal import type_checkers -@basetest.unittest.skipIf( +@unittest.skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, 'C++ implementation does not expose unknown fields to Python') -class UnknownFieldsTest(basetest.TestCase): +class UnknownFieldsTest(unittest.TestCase): def setUp(self): self.descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR @@ -179,10 +180,10 @@ class UnknownFieldsTest(basetest.TestCase): self.assertNotEqual(self.empty_message, message) -@basetest.unittest.skipIf( +@unittest.skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, 'C++ implementation does not expose unknown fields to Python') -class UnknownEnumValuesTest(basetest.TestCase): +class UnknownEnumValuesTest(unittest.TestCase): def setUp(self): self.descriptor = missing_enum_values_pb2.TestEnumValues.DESCRIPTOR @@ -235,4 +236,4 @@ class UnknownEnumValuesTest(basetest.TestCase): if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/internal/wire_format_test.py b/python/google/protobuf/internal/wire_format_test.py index f39035ca..e40a40cc 100755 --- a/python/google/protobuf/internal/wire_format_test.py +++ b/python/google/protobuf/internal/wire_format_test.py @@ -34,12 +34,13 @@ __author__ = 'robinson@google.com (Will Robinson)' -from google.apputils import basetest +import unittest + from google.protobuf import message from google.protobuf.internal import wire_format -class WireFormatTest(basetest.TestCase): +class WireFormatTest(unittest.TestCase): def testPackTag(self): field_number = 0xabc @@ -250,4 +251,4 @@ class WireFormatTest(basetest.TestCase): if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/pyext/descriptor_cpp2_test.py b/python/google/protobuf/pyext/descriptor_cpp2_test.py index 3cf45a22..1eb3663b 100644 --- a/python/google/protobuf/pyext/descriptor_cpp2_test.py +++ b/python/google/protobuf/pyext/descriptor_cpp2_test.py @@ -35,19 +35,19 @@ __author__ = 'anuraag@google.com (Anuraag Agrawal)' import os +import unittest os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp' os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION'] = '2' # We must set the implementation version above before the google3 imports. # pylint: disable=g-import-not-at-top -from google.apputils import basetest from google.protobuf.internal import api_implementation # Run all tests from the original module by putting them in our namespace. # pylint: disable=wildcard-import from google.protobuf.internal.descriptor_test import * -class ConfirmCppApi2Test(basetest.TestCase): +class ConfirmCppApi2Test(unittest.TestCase): def testImplementationSetting(self): self.assertEqual('cpp', api_implementation.Type()) @@ -55,4 +55,4 @@ class ConfirmCppApi2Test(basetest.TestCase): if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/pyext/message_factory_cpp2_test.py b/python/google/protobuf/pyext/message_factory_cpp2_test.py index 32ab4f85..ce4ae861 100644 --- a/python/google/protobuf/pyext/message_factory_cpp2_test.py +++ b/python/google/protobuf/pyext/message_factory_cpp2_test.py @@ -33,19 +33,19 @@ """Tests for google.protobuf.message_factory.""" import os +import unittest os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp' os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION'] = '2' # We must set the implementation version above before the google3 imports. # pylint: disable=g-import-not-at-top -from google.apputils import basetest from google.protobuf.internal import api_implementation # Run all tests from the original module by putting them in our namespace. # pylint: disable=wildcard-import from google.protobuf.internal.message_factory_test import * -class ConfirmCppApi2Test(basetest.TestCase): +class ConfirmCppApi2Test(unittest.TestCase): def testImplementationSetting(self): self.assertEqual('cpp', api_implementation.Type()) @@ -53,4 +53,4 @@ class ConfirmCppApi2Test(basetest.TestCase): if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/google/protobuf/pyext/reflection_cpp2_generated_test.py b/python/google/protobuf/pyext/reflection_cpp2_generated_test.py index 552efd48..b1a23051 100755 --- a/python/google/protobuf/pyext/reflection_cpp2_generated_test.py +++ b/python/google/protobuf/pyext/reflection_cpp2_generated_test.py @@ -36,17 +36,17 @@ __author__ = 'jasonh@google.com (Jason Hsueh)' import os +import unittest os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp' os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION'] = '2' -from google.apputils import basetest from google.protobuf.internal import api_implementation from google.protobuf.internal import more_extensions_dynamic_pb2 from google.protobuf.internal import more_extensions_pb2 from google.protobuf.internal.reflection_test import * -class ReflectionCppTest(basetest.TestCase): +class ReflectionCppTest(unittest.TestCase): def testImplementationSetting(self): self.assertEqual('cpp', api_implementation.Type()) self.assertEqual(2, api_implementation.Version()) @@ -91,4 +91,4 @@ class ReflectionCppTest(basetest.TestCase): if __name__ == '__main__': - basetest.main() + unittest.main() diff --git a/python/setup.py b/python/setup.py index cfe25cc0..cb75b06e 100755 --- a/python/setup.py +++ b/python/setup.py @@ -197,11 +197,6 @@ if __name__ == '__main__': 'google.protobuf.text_format'], cmdclass = { 'clean': clean, 'build_py': build_py }, install_requires = ['setuptools'], - # TODO: Restore dependency once a Python 3 compatible google-apputils - # is released. - setup_requires = (['google-apputils'] - if sys.version_info[0] < 3 else - []), ext_modules = ext_module_list, url = 'https://developers.google.com/protocol-buffers/', maintainer = maintainer_email, -- cgit v1.2.3 From fec1b8e4442a51a0367927bc3c01052df1496215 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Tue, 13 Jan 2015 14:57:18 -0500 Subject: Overlooked dependency. --- python/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python/setup.py') diff --git a/python/setup.py b/python/setup.py index cfe25cc0..da552ef5 100755 --- a/python/setup.py +++ b/python/setup.py @@ -196,7 +196,7 @@ if __name__ == '__main__': 'google.protobuf.text_encoding', 'google.protobuf.text_format'], cmdclass = { 'clean': clean, 'build_py': build_py }, - install_requires = ['setuptools'], + install_requires = ['setuptools', 'six'], # TODO: Restore dependency once a Python 3 compatible google-apputils # is released. setup_requires = (['google-apputils'] -- cgit v1.2.3 From 71edc31f23918ca3c0093ce9cdb38bfa0206ed94 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Tue, 13 Jan 2015 15:38:10 -0500 Subject: Compatibility with Python2.6 unittest. --- .../protobuf/internal/message_factory_test.py | 4 +-- python/google/protobuf/internal/reflection_test.py | 30 ++++++++++++++-------- .../protobuf/internal/unknown_fields_test.py | 15 +++++++++-- python/setup.py | 7 ----- 4 files changed, 35 insertions(+), 21 deletions(-) (limited to 'python/setup.py') diff --git a/python/google/protobuf/internal/message_factory_test.py b/python/google/protobuf/internal/message_factory_test.py index 45ddcd26..5a344a79 100644 --- a/python/google/protobuf/internal/message_factory_test.py +++ b/python/google/protobuf/internal/message_factory_test.py @@ -94,11 +94,11 @@ class MessageFactoryTest(unittest.TestCase): factory = message_factory.MessageFactory() cls = factory.GetPrototype(pool.FindMessageTypeByName( 'google.protobuf.python.internal.Factory2Message')) - self.assertIsNot(cls, factory_test2_pb2.Factory2Message) + self.assertFalse(cls is factory_test2_pb2.Factory2Message) self._ExerciseDynamicClass(cls) cls2 = factory.GetPrototype(pool.FindMessageTypeByName( 'google.protobuf.python.internal.Factory2Message')) - self.assertIs(cls, cls2) + self.assertTrue(cls is cls2) def testGetMessages(self): # performed twice because multiple calls with the same input must be allowed diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 8a72e134..03f558fd 100755 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -40,6 +40,17 @@ import gc import operator import struct import unittest +try: + from unittest import skipIf +except ImportError: + def skipIf(predicate, message): + def decorator(wrapped): + if predicate: + def _noop(*args, **kw): + pass + return _noop + return wrapped + return decorator import six @@ -1623,7 +1634,7 @@ class ReflectionTest(unittest.TestCase): self.assertFalse(proto.IsInitialized(errors)) self.assertEqual(errors, ['a', 'b', 'c']) - @unittest.skipIf( + @skipIf( api_implementation.Type() != 'cpp' or api_implementation.Version() != 2, 'Errors are only available from the most recent C++ implementation.') def testFileDescriptorErrors(self): @@ -1644,18 +1655,17 @@ class ReflectionTest(unittest.TestCase): file_descriptor_proto.name = another_file_name m2 = file_descriptor_proto.message_type.add() m2.name = 'msg2' - with self.assertRaises(TypeError) as cm: + try: descriptor.FileDescriptor( another_file_name, package_name, serialized_pb=file_descriptor_proto.SerializeToString()) - self.assertTrue(hasattr(cm, 'exception'), '%s not raised' % - getattr(cm.expected, '__name__', cm.expected)) - self.assertIn('test_file_descriptor_errors.proto', str(cm.exception)) - # Error message will say something about this definition being a - # duplicate, though we don't check the message exactly to avoid a - # dependency on the C++ logging code. - self.assertIn('test_file_descriptor_errors.msg1', str(cm.exception)) + except TypeError as e: + message = str(e) + else: + self.fail("Did not raise TypeError") + + self.assertTrue('test_file_descriptor_errors.proto' in message) def testStringUTF8Encoding(self): proto = unittest_pb2.TestAllTypes() @@ -2824,7 +2834,7 @@ class OptionsTest(unittest.TestCase): class ClassAPITest(unittest.TestCase): - @unittest.skipIf( + @skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, 'C++ implementation requires a call to MakeDescriptor()') def testMakeClassWithNestedDescriptor(self): diff --git a/python/google/protobuf/internal/unknown_fields_test.py b/python/google/protobuf/internal/unknown_fields_test.py index 0650d92b..e405f113 100755 --- a/python/google/protobuf/internal/unknown_fields_test.py +++ b/python/google/protobuf/internal/unknown_fields_test.py @@ -36,6 +36,17 @@ __author__ = 'bohdank@google.com (Bohdan Koval)' import unittest +try: + from unittest import skipIf +except ImportError: + def skipIf(predicate, message): + def decorator(wrapped): + if predicate: + def _noop(*args, **kw): + pass + return _noop + return wrapped + return decorator from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 @@ -46,7 +57,7 @@ from google.protobuf.internal import test_util from google.protobuf.internal import type_checkers -@unittest.skipIf( +@skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, 'C++ implementation does not expose unknown fields to Python') class UnknownFieldsTest(unittest.TestCase): @@ -180,7 +191,7 @@ class UnknownFieldsTest(unittest.TestCase): self.assertNotEqual(self.empty_message, message) -@unittest.skipIf( +@skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, 'C++ implementation does not expose unknown fields to Python') class UnknownEnumValuesTest(unittest.TestCase): diff --git a/python/setup.py b/python/setup.py index d916b9c5..a4015d8a 100755 --- a/python/setup.py +++ b/python/setup.py @@ -135,13 +135,6 @@ class build_py(_build_py): pass # _build_py is an old-style class, so super() doesn't work. _build_py.run(self) - # TODO(mrovner): Subclass to run 2to3 on some files only. - # Tracing what https://wiki.python.org/moin/PortingPythonToPy3k's "Approach 2" - # section on how to get 2to3 to run on source files during install under - # Python 3. This class seems like a good place to put logic that calls - # python3's distutils.util.run_2to3 on the subset of the files we have in our - # release that are subject to conversion. - # See code reference in previous code review. if __name__ == '__main__': ext_module_list = [] -- cgit v1.2.3 From daeaa6a28b81195f24d89222e649d79c9555af8b Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Tue, 13 Jan 2015 16:00:33 -0500 Subject: Declare explicit support for Python 3.3 and 3.4. --- python/setup.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'python/setup.py') diff --git a/python/setup.py b/python/setup.py index 3739dc45..32176ae6 100755 --- a/python/setup.py +++ b/python/setup.py @@ -165,9 +165,13 @@ if __name__ == '__main__': 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( -- cgit v1.2.3 From 833c046fb703f9c5ef6bd8b05c4aa1d7e2ecec0e Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Thu, 13 Aug 2015 01:17:26 -0400 Subject: Fixing some tests Signed-off-by: Dan O'Reilly --- python/google/protobuf/internal/_parameterized.py | 10 ++-- python/google/protobuf/internal/python_message.py | 3 +- python/google/protobuf/internal/reflection_test.py | 2 +- python/setup.py | 57 +++++++++------------- 4 files changed, 30 insertions(+), 42 deletions(-) (limited to 'python/setup.py') diff --git a/python/google/protobuf/internal/_parameterized.py b/python/google/protobuf/internal/_parameterized.py index 400b2216..3002b230 100755 --- a/python/google/protobuf/internal/_parameterized.py +++ b/python/google/protobuf/internal/_parameterized.py @@ -152,6 +152,8 @@ import types import unittest import uuid +import six + ADDR_RE = re.compile(r'\<([a-zA-Z0-9_\-\.]+) object at 0x[a-fA-F0-9]+\>') _SEPARATOR = uuid.uuid1().hex _FIRST_ARG = object() @@ -170,13 +172,13 @@ def _StrClass(cls): def _NonStringIterable(obj): return (isinstance(obj, collections.Iterable) and not - isinstance(obj, basestring)) + isinstance(obj, six.string_types)) def _FormatParameterList(testcase_params): if isinstance(testcase_params, collections.Mapping): return ', '.join('%s=%s' % (argname, _CleanRepr(value)) - for argname, value in testcase_params.iteritems()) + for argname, value in testcase_params.items()) elif _NonStringIterable(testcase_params): return ', '.join(map(_CleanRepr, testcase_params)) else: @@ -258,7 +260,7 @@ def _ModifyClass(class_object, testcases, naming_type): 'Cannot add parameters to %s,' ' which already has parameterized methods.' % (class_object,)) class_object._id_suffix = id_suffix = {} - for name, obj in class_object.__dict__.items(): + for name, obj in class_object.__dict__.copy().items(): if (name.startswith(unittest.TestLoader.testMethodPrefix) and isinstance(obj, types.FunctionType)): delattr(class_object, name) @@ -266,7 +268,7 @@ def _ModifyClass(class_object, testcases, naming_type): _UpdateClassDictForParamTestCase( methods, id_suffix, name, _ParameterizedTestIter(obj, testcases, naming_type)) - for name, meth in methods.iteritems(): + for name, meth in methods.items(): setattr(class_object, name, meth) diff --git a/python/google/protobuf/internal/python_message.py b/python/google/protobuf/internal/python_message.py index bb06beb3..9a72315e 100755 --- a/python/google/protobuf/internal/python_message.py +++ b/python/google/protobuf/internal/python_message.py @@ -59,7 +59,6 @@ import weakref import six import six.moves.copyreg as copyreg -import six.string_types # We use "as" to avoid name collisions with variables. from google.protobuf.internal import containers @@ -1120,7 +1119,7 @@ def _AddIsInitializedMethod(message_descriptor, cls): # ScalarMaps can't have any initialization errors. pass elif field.label == _FieldDescriptor.LABEL_REPEATED: - for i in xrange(len(value)): + for i in range(len(value)): element = value[i] prefix = "%s[%d]." % (name, i) sub_errors = element.FindInitializationErrors() diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 794395c5..d1c18c1f 100755 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -1634,7 +1634,7 @@ class ReflectionTest(unittest.TestCase): self.assertFalse(proto.IsInitialized(errors)) self.assertEqual(errors, ['a', 'b', 'c']) - @basetest.unittest.skipIf( + @skipIf( api_implementation.Type() != 'cpp' or api_implementation.Version() != 2, 'Errors are only available from the most recent C++ implementation.') def testFileDescriptorErrors(self): diff --git a/python/setup.py b/python/setup.py index ba0dac2c..bb8a7d05 100755 --- a/python/setup.py +++ b/python/setup.py @@ -88,41 +88,27 @@ def generate_proto(source, require = True): 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/descriptor_pool_test1.proto") - generate_proto("google/protobuf/internal/descriptor_pool_test2.proto") - generate_proto("google/protobuf/internal/test_bad_identifiers.proto") - generate_proto("google/protobuf/internal/missing_enum_values.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") - generate_proto("google/protobuf/internal/import_test_package/inner.proto") - generate_proto("google/protobuf/internal/import_test_package/outer.proto") - generate_proto("google/protobuf/pyext/python.proto") - -def MakeTestSuite(): - # Test C++ implementation - import unittest - import google.protobuf.pyext.descriptor_cpp2_test as descriptor_cpp2_test - import google.protobuf.pyext.message_factory_cpp2_test \ - as message_factory_cpp2_test - import google.protobuf.pyext.reflection_cpp2_generated_test \ - as reflection_cpp2_generated_test - - loader = unittest.defaultTestLoader - suite = unittest.TestSuite() - for test in [ descriptor_cpp2_test, - message_factory_cpp2_test, - reflection_cpp2_generated_test]: - suite.addTest(loader.loadTestsFromModule(test)) - return suite + generate_proto("../src/google/protobuf/map_unittest.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_no_generic_services.proto", False) + generate_proto("../src/google/protobuf/unittest_proto3_arena.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/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/test_bad_identifiers.proto", False) + generate_proto("google/protobuf/pyext/python.proto", False) + class clean(_clean): def run(self): @@ -153,6 +139,7 @@ class build_py(_build_py): # _build_py is an old-style class, so super() doesn't work. _build_py.run(self) + if __name__ == '__main__': ext_module_list = [] cpp_impl = '--cpp_implementation' -- cgit v1.2.3 From 2621c8aefbfefd517a3facc6dc0e0dc45ae5eb87 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Fri, 14 Aug 2015 22:54:53 -0400 Subject: Get Python 2.6 working. Signed-off-by: Dan O'Reilly --- python/google/protobuf/internal/_parameterized.py | 5 +++- .../protobuf/internal/descriptor_database_test.py | 5 +++- .../protobuf/internal/descriptor_pool_test.py | 6 ++-- python/google/protobuf/internal/descriptor_test.py | 10 +++++-- python/google/protobuf/internal/generator_test.py | 7 +++-- .../protobuf/internal/message_factory_test.py | 5 +++- python/google/protobuf/internal/message_test.py | 21 +++++++------ .../google/protobuf/internal/proto_builder_test.py | 13 ++++++-- python/google/protobuf/internal/reflection_test.py | 16 +++------- .../protobuf/internal/service_reflection_test.py | 5 +++- .../protobuf/internal/symbol_database_test.py | 5 +++- .../google/protobuf/internal/text_encoding_test.py | 5 +++- .../google/protobuf/internal/text_format_test.py | 35 ++++++++++++---------- .../protobuf/internal/unknown_fields_test.py | 16 +++------- .../google/protobuf/internal/wire_format_test.py | 5 +++- python/google/protobuf/proto_builder.py | 7 +++-- python/setup.py | 7 ++++- 17 files changed, 104 insertions(+), 69 deletions(-) (limited to 'python/setup.py') diff --git a/python/google/protobuf/internal/_parameterized.py b/python/google/protobuf/internal/_parameterized.py index 3002b230..6c5a2bac 100755 --- a/python/google/protobuf/internal/_parameterized.py +++ b/python/google/protobuf/internal/_parameterized.py @@ -149,7 +149,10 @@ import collections import functools import re import types -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest import uuid import six diff --git a/python/google/protobuf/internal/descriptor_database_test.py b/python/google/protobuf/internal/descriptor_database_test.py index 3241cb72..1baff7d1 100644 --- a/python/google/protobuf/internal/descriptor_database_test.py +++ b/python/google/protobuf/internal/descriptor_database_test.py @@ -34,7 +34,10 @@ __author__ = 'matthewtoia@google.com (Matt Toia)' -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import descriptor_pb2 from google.protobuf.internal import factory_test2_pb2 from google.protobuf import descriptor_database diff --git a/python/google/protobuf/internal/descriptor_pool_test.py b/python/google/protobuf/internal/descriptor_pool_test.py index 64b5d172..2a482fba 100644 --- a/python/google/protobuf/internal/descriptor_pool_test.py +++ b/python/google/protobuf/internal/descriptor_pool_test.py @@ -35,9 +35,11 @@ __author__ = 'matthewtoia@google.com (Matt Toia)' import os -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest -import unittest from google.protobuf import unittest_pb2 from google.protobuf import descriptor_pb2 from google.protobuf.internal import api_implementation diff --git a/python/google/protobuf/internal/descriptor_test.py b/python/google/protobuf/internal/descriptor_test.py index a40ec0e4..34843a61 100755 --- a/python/google/protobuf/internal/descriptor_test.py +++ b/python/google/protobuf/internal/descriptor_test.py @@ -36,7 +36,6 @@ __author__ = 'robinson@google.com (Will Robinson)' import sys -import unittest from google.protobuf import unittest_custom_options_pb2 from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_pb2 @@ -46,6 +45,11 @@ from google.protobuf import descriptor from google.protobuf import symbol_database from google.protobuf import text_format +try: + import unittest2 as unittest +except ImportError: + import unittest + TEST_EMPTY_MESSAGE_DESCRIPTOR_ASCII = """ name: 'TestEmptyMessage' @@ -455,7 +459,7 @@ class GeneratedDescriptorTest(unittest.TestCase): # properties of an immutable abc.Mapping. self.assertGreater(len(mapping), 0) # Sized self.assertEqual(len(mapping), len(list(mapping))) # Iterable - if sys.version_info.major >= 3: + if sys.version_info >= (3,): key, item = next(iter(mapping.items())) else: key, item = mapping.items()[0] @@ -464,7 +468,7 @@ class GeneratedDescriptorTest(unittest.TestCase): # keys(), iterkeys() &co item = (next(iter(mapping.keys())), next(iter(mapping.values()))) self.assertEqual(item, next(iter(mapping.items()))) - if sys.version_info.major < 3: + if sys.version_info < (3,): def CheckItems(seq, iterator): self.assertEqual(next(iterator), seq[0]) self.assertEqual(list(iterator), seq[1:]) diff --git a/python/google/protobuf/internal/generator_test.py b/python/google/protobuf/internal/generator_test.py index f6135fb9..bdd7382a 100755 --- a/python/google/protobuf/internal/generator_test.py +++ b/python/google/protobuf/internal/generator_test.py @@ -41,7 +41,10 @@ further ensures that we can use Python protocol message objects as we expect. __author__ = 'robinson@google.com (Will Robinson)' -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf.internal import test_bad_identifiers_pb2 from google.protobuf import unittest_custom_options_pb2 from google.protobuf import unittest_import_pb2 @@ -153,7 +156,7 @@ class GeneratorTest(unittest.TestCase): # extension and for its value to be set to -789. def testNestedTypes(self): - self.assertEquals( + self.assertEqual( set(unittest_pb2.TestAllTypes.DESCRIPTOR.nested_types), set([ unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR, diff --git a/python/google/protobuf/internal/message_factory_test.py b/python/google/protobuf/internal/message_factory_test.py index 27a3f08b..0d880a75 100644 --- a/python/google/protobuf/internal/message_factory_test.py +++ b/python/google/protobuf/internal/message_factory_test.py @@ -34,7 +34,10 @@ __author__ = 'matthewtoia@google.com (Matt Toia)' -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import descriptor_pb2 from google.protobuf.internal import factory_test1_pb2 from google.protobuf.internal import factory_test2_pb2 diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 66356c92..cf3fcfe9 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -54,7 +54,10 @@ import six if six.PY3: long = int -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf.internal import _parameterized from google.protobuf import map_unittest_pb2 from google.protobuf import unittest_pb2 @@ -324,7 +327,7 @@ class MessageTest(unittest.TestCase): def testHighPrecisionFloatPrinting(self, message_module): message = message_module.TestAllTypes() message.optional_double = 0.12345678912345678 - if sys.version_info.major >= 3: + if sys.version_info >= (3,): self.assertEqual(str(message), 'optional_double: 0.12345678912345678\n') else: self.assertEqual(str(message), 'optional_double: 0.123456789123\n') @@ -443,7 +446,7 @@ class MessageTest(unittest.TestCase): message.repeated_nested_message.sort(key=get_bb, reverse=True) self.assertEqual([k.bb for k in message.repeated_nested_message], [6, 5, 4, 3, 2, 1]) - if sys.version_info.major >= 3: return # No cmp sorting in PY3. + if sys.version_info >= (3,): return # No cmp sorting in PY3. message.repeated_nested_message.sort(sort_function=cmp_bb) self.assertEqual([k.bb for k in message.repeated_nested_message], [1, 2, 3, 4, 5, 6]) @@ -462,7 +465,7 @@ class MessageTest(unittest.TestCase): self.assertEqual(list(message.repeated_int32), [-1, -2, -3]) message.repeated_int32.sort(key=abs, reverse=True) self.assertEqual(list(message.repeated_int32), [-3, -2, -1]) - if sys.version_info.major < 3: # No cmp sorting in PY3. + if sys.version_info < (3,): # No cmp sorting in PY3. abs_cmp = lambda a, b: cmp(abs(a), abs(b)) message.repeated_int32.sort(sort_function=abs_cmp) self.assertEqual(list(message.repeated_int32), [-1, -2, -3]) @@ -476,7 +479,7 @@ class MessageTest(unittest.TestCase): self.assertEqual(list(message.repeated_string), ['c', 'bb', 'aaa']) message.repeated_string.sort(key=len, reverse=True) self.assertEqual(list(message.repeated_string), ['aaa', 'bb', 'c']) - if sys.version_info.major < 3: # No cmp sorting in PY3. + if sys.version_info < (3,): # No cmp sorting in PY3. len_cmp = lambda a, b: cmp(len(a), len(b)) message.repeated_string.sort(sort_function=len_cmp) self.assertEqual(list(message.repeated_string), ['c', 'bb', 'aaa']) @@ -499,7 +502,7 @@ class MessageTest(unittest.TestCase): m2.repeated_nested_message.add().bb = 2 m2.repeated_nested_message.add().bb = 3 - if sys.version_info.major >= 3: return # No cmp() in PY3. + if sys.version_info >= (3,): return # No cmp() in PY3. # These comparisons should not raise errors. _ = m1 < m2 @@ -1248,14 +1251,14 @@ class Proto3Test(unittest.TestCase): msg = map_unittest_pb2.TestMap() self.assertIsNone(msg.map_int32_int32.get(5)) - self.assertEquals(10, msg.map_int32_int32.get(5, 10)) + self.assertEqual(10, msg.map_int32_int32.get(5, 10)) self.assertIsNone(msg.map_int32_int32.get(5)) msg.map_int32_int32[5] = 15 - self.assertEquals(15, msg.map_int32_int32.get(5)) + self.assertEqual(15, msg.map_int32_int32.get(5)) self.assertIsNone(msg.map_int32_foreign_message.get(5)) - self.assertEquals(10, msg.map_int32_foreign_message.get(5, 10)) + self.assertEqual(10, msg.map_int32_foreign_message.get(5, 10)) submsg = msg.map_int32_foreign_message[5] self.assertIs(submsg, msg.map_int32_foreign_message.get(5)) diff --git a/python/google/protobuf/internal/proto_builder_test.py b/python/google/protobuf/internal/proto_builder_test.py index edaf3fa3..1eda10fb 100644 --- a/python/google/protobuf/internal/proto_builder_test.py +++ b/python/google/protobuf/internal/proto_builder_test.py @@ -32,8 +32,15 @@ """Tests for google.protobuf.proto_builder.""" -import collections -import unittest +try: + from collections import OrderedDict +except ImportError: + from ordereddict import OrderedDict #PY26 + +try: + import unittest2 as unittest #PY26 +except ImportError: + import unittest from google.protobuf import descriptor_pb2 from google.protobuf import descriptor_pool @@ -44,7 +51,7 @@ from google.protobuf import text_format class ProtoBuilderTest(unittest.TestCase): def setUp(self): - self.ordered_fields = collections.OrderedDict([ + self.ordered_fields = OrderedDict([ ('foo', descriptor_pb2.FieldDescriptorProto.TYPE_INT64), ('bar', descriptor_pb2.FieldDescriptorProto.TYPE_STRING), ]) diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 9fe3abee..8967dc2e 100755 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -39,18 +39,10 @@ import copy import gc import operator import struct -import unittest try: - from unittest import skipIf + import unittest2 as unittest except ImportError: - def skipIf(predicate, message): - def decorator(wrapped): - if predicate: - def _noop(*args, **kw): - pass - return _noop - return wrapped - return decorator + import unittest import six @@ -1634,7 +1626,7 @@ class ReflectionTest(unittest.TestCase): self.assertFalse(proto.IsInitialized(errors)) self.assertEqual(errors, ['a', 'b', 'c']) - @skipIf( + @unittest.skipIf( api_implementation.Type() != 'cpp' or api_implementation.Version() != 2, 'Errors are only available from the most recent C++ implementation.') def testFileDescriptorErrors(self): @@ -2835,7 +2827,7 @@ class OptionsTest(unittest.TestCase): class ClassAPITest(unittest.TestCase): - @skipIf( + @unittest.skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, 'C++ implementation requires a call to MakeDescriptor()') def testMakeClassWithNestedDescriptor(self): diff --git a/python/google/protobuf/internal/service_reflection_test.py b/python/google/protobuf/internal/service_reflection_test.py index 9967255a..d7cd591b 100755 --- a/python/google/protobuf/internal/service_reflection_test.py +++ b/python/google/protobuf/internal/service_reflection_test.py @@ -34,7 +34,10 @@ __author__ = 'petar@google.com (Petar Petrov)' -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import unittest_pb2 from google.protobuf import service_reflection from google.protobuf import service diff --git a/python/google/protobuf/internal/symbol_database_test.py b/python/google/protobuf/internal/symbol_database_test.py index b2489cdb..97442262 100644 --- a/python/google/protobuf/internal/symbol_database_test.py +++ b/python/google/protobuf/internal/symbol_database_test.py @@ -32,7 +32,10 @@ """Tests for google.protobuf.symbol_database.""" -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import unittest_pb2 from google.protobuf import symbol_database diff --git a/python/google/protobuf/internal/text_encoding_test.py b/python/google/protobuf/internal/text_encoding_test.py index 9e7b9ce4..338a287b 100755 --- a/python/google/protobuf/internal/text_encoding_test.py +++ b/python/google/protobuf/internal/text_encoding_test.py @@ -32,7 +32,10 @@ """Tests for google.protobuf.text_encoding.""" -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import text_encoding TEST_VALUES = [ diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py index 49e6332c..67d08dfe 100755 --- a/python/google/protobuf/internal/text_format_test.py +++ b/python/google/protobuf/internal/text_format_test.py @@ -38,7 +38,10 @@ import re import six -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf.internal import _parameterized from google.protobuf import map_unittest_pb2 @@ -62,7 +65,7 @@ class TextFormatBase(unittest.TestCase): self.assertMultiLineEqual(text, ''.join(golden_lines)) def CompareToGoldenText(self, text, golden_text): - self.assertMultiLineEqual(text, golden_text) + self.assertEqual(text, golden_text) def RemoveRedundantZeros(self, text): # Some platforms print 1e+5 as 1e+005. This is fine, but we need to remove @@ -218,13 +221,13 @@ class TextFormatTest(TextFormatBase): text_message = text_format.MessageToString(message, float_format='.15g') self.CompareToGoldenText( self.RemoveRedundantZeros(text_message), - 'payload {{\n {}\n {}\n {}\n {}\n}}\n'.format(*formatted_fields)) + 'payload {{\n {0}\n {1}\n {2}\n {3}\n}}\n'.format(*formatted_fields)) # as_one_line=True is a separate code branch where float_format is passed. text_message = text_format.MessageToString(message, as_one_line=True, float_format='.15g') self.CompareToGoldenText( self.RemoveRedundantZeros(text_message), - 'payload {{ {} {} {} {} }}'.format(*formatted_fields)) + 'payload {{ {0} {1} {2} {3} }}'.format(*formatted_fields)) def testMessageToString(self, message_module): message = message_module.ForeignMessage() @@ -297,7 +300,7 @@ class TextFormatTest(TextFormatBase): def testParseSingleWord(self, message_module): message = message_module.TestAllTypes() text = 'foo' - self.assertRaisesRegexp( + six.assertRaisesRegex(self, text_format.ParseError, (r'1:1 : Message type "\w+.TestAllTypes" has no field named ' r'"foo".'), @@ -306,7 +309,7 @@ class TextFormatTest(TextFormatBase): def testParseUnknownField(self, message_module): message = message_module.TestAllTypes() text = 'unknown_field: 8\n' - self.assertRaisesRegexp( + six.assertRaisesRegex(self, text_format.ParseError, (r'1:1 : Message type "\w+.TestAllTypes" has no field named ' r'"unknown_field".'), @@ -315,7 +318,7 @@ class TextFormatTest(TextFormatBase): def testParseBadEnumValue(self, message_module): message = message_module.TestAllTypes() text = 'optional_nested_enum: BARR' - self.assertRaisesRegexp( + six.assertRaisesRegex(self, text_format.ParseError, (r'1:23 : Enum type "\w+.TestAllTypes.NestedEnum" ' r'has no value named BARR.'), @@ -323,7 +326,7 @@ class TextFormatTest(TextFormatBase): message = message_module.TestAllTypes() text = 'optional_nested_enum: 100' - self.assertRaisesRegexp( + six.assertRaisesRegex(self, text_format.ParseError, (r'1:23 : Enum type "\w+.TestAllTypes.NestedEnum" ' r'has no value with number 100.'), @@ -332,7 +335,7 @@ class TextFormatTest(TextFormatBase): def testParseBadIntValue(self, message_module): message = message_module.TestAllTypes() text = 'optional_int32: bork' - self.assertRaisesRegexp( + six.assertRaisesRegex(self, text_format.ParseError, ('1:17 : Couldn\'t parse integer: bork'), text_format.Parse, text, message) @@ -596,12 +599,12 @@ class Proto2Tests(TextFormatBase): def testParseBadExtension(self): message = unittest_pb2.TestAllExtensions() text = '[unknown_extension]: 8\n' - self.assertRaisesRegexp( + six.assertRaisesRegex(self, text_format.ParseError, '1:2 : Extension "unknown_extension" not registered.', text_format.Parse, text, message) message = unittest_pb2.TestAllTypes() - self.assertRaisesRegexp( + six.assertRaisesRegex(self, text_format.ParseError, ('1:2 : Message type "protobuf_unittest.TestAllTypes" does not have ' 'extensions.'), @@ -620,7 +623,7 @@ class Proto2Tests(TextFormatBase): message = unittest_pb2.TestAllExtensions() text = ('[protobuf_unittest.optional_int32_extension]: 42 ' '[protobuf_unittest.optional_int32_extension]: 67') - self.assertRaisesRegexp( + six.assertRaisesRegex(self, text_format.ParseError, ('1:96 : Message type "protobuf_unittest.TestAllExtensions" ' 'should not have multiple ' @@ -631,7 +634,7 @@ class Proto2Tests(TextFormatBase): message = unittest_pb2.TestAllTypes() text = ('optional_nested_message { bb: 1 } ' 'optional_nested_message { bb: 2 }') - self.assertRaisesRegexp( + six.assertRaisesRegex(self, text_format.ParseError, ('1:65 : Message type "protobuf_unittest.TestAllTypes.NestedMessage" ' 'should not have multiple "bb" fields.'), @@ -641,7 +644,7 @@ class Proto2Tests(TextFormatBase): message = unittest_pb2.TestAllTypes() text = ('optional_int32: 42 ' 'optional_int32: 67') - self.assertRaisesRegexp( + six.assertRaisesRegex(self, text_format.ParseError, ('1:36 : Message type "protobuf_unittest.TestAllTypes" should not ' 'have multiple "optional_int32" fields.'), @@ -650,11 +653,11 @@ class Proto2Tests(TextFormatBase): def testParseGroupNotClosed(self): message = unittest_pb2.TestAllTypes() text = 'RepeatedGroup: <' - self.assertRaisesRegexp( + six.assertRaisesRegex(self, text_format.ParseError, '1:16 : Expected ">".', text_format.Parse, text, message) text = 'RepeatedGroup: {' - self.assertRaisesRegexp( + six.assertRaisesRegex(self, text_format.ParseError, '1:16 : Expected "}".', text_format.Parse, text, message) diff --git a/python/google/protobuf/internal/unknown_fields_test.py b/python/google/protobuf/internal/unknown_fields_test.py index 5cd23d78..1b5d7bc0 100755 --- a/python/google/protobuf/internal/unknown_fields_test.py +++ b/python/google/protobuf/internal/unknown_fields_test.py @@ -35,18 +35,10 @@ __author__ = 'bohdank@google.com (Bohdan Koval)' -import unittest try: - from unittest import skipIf + import unittest2 as unittest except ImportError: - def skipIf(predicate, message): - def decorator(wrapped): - if predicate: - def _noop(*args, **kw): - pass - return _noop - return wrapped - return decorator + import unittest from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 @@ -129,7 +121,7 @@ class UnknownFieldsTest(unittest.TestCase): self.assertNotEqual(self.empty_message, message) -@skipIf( +@unittest.skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, 'C++ implementation does not expose unknown fields to Python') class UnknownFieldsAccessorsTest(unittest.TestCase): @@ -217,7 +209,7 @@ class UnknownFieldsAccessorsTest(unittest.TestCase): -@skipIf( +@unittest.skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, 'C++ implementation does not expose unknown fields to Python') class UnknownEnumValuesTest(unittest.TestCase): diff --git a/python/google/protobuf/internal/wire_format_test.py b/python/google/protobuf/internal/wire_format_test.py index 78dc1167..f659d18e 100755 --- a/python/google/protobuf/internal/wire_format_test.py +++ b/python/google/protobuf/internal/wire_format_test.py @@ -34,7 +34,10 @@ __author__ = 'robinson@google.com (Will Robinson)' -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest from google.protobuf import message from google.protobuf.internal import wire_format diff --git a/python/google/protobuf/proto_builder.py b/python/google/protobuf/proto_builder.py index 7489cf63..700e3c25 100644 --- a/python/google/protobuf/proto_builder.py +++ b/python/google/protobuf/proto_builder.py @@ -30,7 +30,10 @@ """Dynamic Protobuf class creator.""" -import collections +try: + from collections import OrderedDict +except ImportError: + from ordereddict import OrderedDict #PY26 import hashlib import os @@ -80,7 +83,7 @@ def MakeSimpleProtoClass(fields, full_name, pool=None): # an OrderedDict we keep the order, but otherwise we sort the field to ensure # consistent ordering. field_items = fields.items() - if not isinstance(fields, collections.OrderedDict): + if not isinstance(fields, OrderedDict): field_items = sorted(field_items) # Use a consistent file name that is unlikely to conflict with any imported diff --git a/python/setup.py b/python/setup.py index bb8a7d05..79e23698 100755 --- a/python/setup.py +++ b/python/setup.py @@ -158,6 +158,11 @@ if __name__ == '__main__': ) os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp' + install_requires = ['six', 'setuptools'] + if sys.version_info <= (2,7): + install_requires.append('ordereddict') + install_requires.append('unittest2') + setup( name='protobuf', version=GetVersion(), @@ -187,6 +192,6 @@ if __name__ == '__main__': 'clean': clean, 'build_py': build_py, }, - install_requires=['setuptools', 'six'], + install_requires=install_requires, ext_modules=ext_module_list, ) -- cgit v1.2.3 From 3bdfb4b6951ad3db1a9493e86cd76f4f1c4d8986 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Thu, 20 Aug 2015 13:51:26 -0400 Subject: Add some clarifying comments. Remove ez_setup.py. Signed-off-by: Dan O'Reilly --- python/ez_setup.py | 332 ---------------------- python/google/protobuf/internal/_parameterized.py | 2 + python/setup.py | 14 +- python/tox.ini | 2 + 4 files changed, 5 insertions(+), 345 deletions(-) delete mode 100644 python/ez_setup.py (limited to 'python/setup.py') diff --git a/python/ez_setup.py b/python/ez_setup.py deleted file mode 100644 index 955a8008..00000000 --- a/python/ez_setup.py +++ /dev/null @@ -1,332 +0,0 @@ -#!/usr/bin/env python -"""Bootstrap setuptools installation - -To use setuptools in your package's setup.py, include this -file in the same directory and add this to the top of your setup.py:: - - from ez_setup import use_setuptools - use_setuptools() - -To require a specific version of setuptools, set a download -mirror, or use an alternate download directory, simply supply -the appropriate options to ``use_setuptools()``. - -This file can also be run as a script to install or upgrade setuptools. -""" -import os -import shutil -import sys -import tempfile -import zipfile -import optparse -import subprocess -import platform -import textwrap -import contextlib - -from distutils import log - -try: - from urllib.request import urlopen -except ImportError: - from urllib2 import urlopen - -try: - from site import USER_SITE -except ImportError: - USER_SITE = None - -DEFAULT_VERSION = "11.3.1" -DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/" - -def _python_cmd(*args): - """ - Return True if the command succeeded. - """ - args = (sys.executable,) + args - return subprocess.call(args) == 0 - - -def _install(archive_filename, install_args=()): - with archive_context(archive_filename): - # installing - log.warn('Installing Setuptools') - if not _python_cmd('setup.py', 'install', *install_args): - log.warn('Something went wrong during the installation.') - log.warn('See the error message above.') - # exitcode will be 2 - return 2 - - -def _build_egg(egg, archive_filename, to_dir): - with archive_context(archive_filename): - # building an egg - log.warn('Building a Setuptools egg in %s', to_dir) - _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir) - # returning the result - log.warn(egg) - if not os.path.exists(egg): - raise IOError('Could not build the egg.') - - -class ContextualZipFile(zipfile.ZipFile): - """ - Supplement ZipFile class to support context manager for Python 2.6 - """ - - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - self.close() - - def __new__(cls, *args, **kwargs): - """ - Construct a ZipFile or ContextualZipFile as appropriate - """ - if hasattr(zipfile.ZipFile, '__exit__'): - return zipfile.ZipFile(*args, **kwargs) - return super(ContextualZipFile, cls).__new__(cls) - - -@contextlib.contextmanager -def archive_context(filename): - # extracting the archive - tmpdir = tempfile.mkdtemp() - log.warn('Extracting in %s', tmpdir) - old_wd = os.getcwd() - try: - os.chdir(tmpdir) - with ContextualZipFile(filename) as archive: - archive.extractall() - - # going in the directory - subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0]) - os.chdir(subdir) - log.warn('Now working in %s', subdir) - yield - - finally: - os.chdir(old_wd) - shutil.rmtree(tmpdir) - - -def _do_download(version, download_base, to_dir, download_delay): - egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg' - % (version, sys.version_info[0], sys.version_info[1])) - if not os.path.exists(egg): - archive = download_setuptools(version, download_base, - to_dir, download_delay) - _build_egg(egg, archive, to_dir) - sys.path.insert(0, egg) - - # Remove previously-imported pkg_resources if present (see - # https://bitbucket.org/pypa/setuptools/pull-request/7/ for details). - if 'pkg_resources' in sys.modules: - del sys.modules['pkg_resources'] - - import setuptools - setuptools.bootstrap_install_from = egg - - -def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, - to_dir=os.curdir, download_delay=15): - to_dir = os.path.abspath(to_dir) - rep_modules = 'pkg_resources', 'setuptools' - imported = set(sys.modules).intersection(rep_modules) - try: - import pkg_resources - except ImportError: - return _do_download(version, download_base, to_dir, download_delay) - try: - pkg_resources.require("setuptools>=" + version) - return - except pkg_resources.DistributionNotFound: - return _do_download(version, download_base, to_dir, download_delay) - except pkg_resources.VersionConflict as VC_err: - if imported: - msg = textwrap.dedent(""" - The required version of setuptools (>={version}) is not available, - and can't be installed while this script is running. Please - install a more recent version first, using - 'easy_install -U setuptools'. - - (Currently using {VC_err.args[0]!r}) - """).format(VC_err=VC_err, version=version) - sys.stderr.write(msg) - sys.exit(2) - - # otherwise, reload ok - del pkg_resources, sys.modules['pkg_resources'] - return _do_download(version, download_base, to_dir, download_delay) - -def _clean_check(cmd, target): - """ - Run the command to download target. If the command fails, clean up before - re-raising the error. - """ - try: - subprocess.check_call(cmd) - except subprocess.CalledProcessError: - if os.access(target, os.F_OK): - os.unlink(target) - raise - -def download_file_powershell(url, target): - """ - Download the file at url to target using Powershell (which will validate - trust). Raise an exception if the command cannot complete. - """ - target = os.path.abspath(target) - ps_cmd = ( - "[System.Net.WebRequest]::DefaultWebProxy.Credentials = " - "[System.Net.CredentialCache]::DefaultCredentials; " - "(new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)" - % vars() - ) - cmd = [ - 'powershell', - '-Command', - ps_cmd, - ] - _clean_check(cmd, target) - -def has_powershell(): - if platform.system() != 'Windows': - return False - cmd = ['powershell', '-Command', 'echo test'] - with open(os.path.devnull, 'wb') as devnull: - try: - subprocess.check_call(cmd, stdout=devnull, stderr=devnull) - except Exception: - return False - return True - -download_file_powershell.viable = has_powershell - -def download_file_curl(url, target): - cmd = ['curl', url, '--silent', '--output', target] - _clean_check(cmd, target) - -def has_curl(): - cmd = ['curl', '--version'] - with open(os.path.devnull, 'wb') as devnull: - try: - subprocess.check_call(cmd, stdout=devnull, stderr=devnull) - except Exception: - return False - return True - -download_file_curl.viable = has_curl - -def download_file_wget(url, target): - cmd = ['wget', url, '--quiet', '--output-document', target] - _clean_check(cmd, target) - -def has_wget(): - cmd = ['wget', '--version'] - with open(os.path.devnull, 'wb') as devnull: - try: - subprocess.check_call(cmd, stdout=devnull, stderr=devnull) - except Exception: - return False - return True - -download_file_wget.viable = has_wget - -def download_file_insecure(url, target): - """ - Use Python to download the file, even though it cannot authenticate the - connection. - """ - src = urlopen(url) - try: - # Read all the data in one block. - data = src.read() - finally: - src.close() - - # Write all the data in one block to avoid creating a partial file. - with open(target, "wb") as dst: - dst.write(data) - -download_file_insecure.viable = lambda: True - -def get_best_downloader(): - downloaders = ( - download_file_powershell, - download_file_curl, - download_file_wget, - download_file_insecure, - ) - viable_downloaders = (dl for dl in downloaders if dl.viable()) - return next(viable_downloaders, None) - -def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, - to_dir=os.curdir, delay=15, downloader_factory=get_best_downloader): - """ - Download setuptools from a specified location and return its filename - - `version` should be a valid setuptools version number that is available - as an sdist for download under the `download_base` URL (which should end - with a '/'). `to_dir` is the directory where the egg will be downloaded. - `delay` is the number of seconds to pause before an actual download - attempt. - - ``downloader_factory`` should be a function taking no arguments and - returning a function for downloading a URL to a target. - """ - # making sure we use the absolute path - to_dir = os.path.abspath(to_dir) - zip_name = "setuptools-%s.zip" % version - url = download_base + zip_name - saveto = os.path.join(to_dir, zip_name) - if not os.path.exists(saveto): # Avoid repeated downloads - log.warn("Downloading %s", url) - downloader = downloader_factory() - downloader(url, saveto) - return os.path.realpath(saveto) - -def _build_install_args(options): - """ - Build the arguments to 'python setup.py install' on the setuptools package - """ - return ['--user'] if options.user_install else [] - -def _parse_args(): - """ - Parse the command line for options - """ - parser = optparse.OptionParser() - parser.add_option( - '--user', dest='user_install', action='store_true', default=False, - help='install in user site package (requires Python 2.6 or later)') - parser.add_option( - '--download-base', dest='download_base', metavar="URL", - default=DEFAULT_URL, - help='alternative URL from where to download the setuptools package') - parser.add_option( - '--insecure', dest='downloader_factory', action='store_const', - const=lambda: download_file_insecure, default=get_best_downloader, - help='Use internal, non-validating downloader' - ) - parser.add_option( - '--version', help="Specify which version to download", - default=DEFAULT_VERSION, - ) - options, args = parser.parse_args() - # positional arguments are ignored - return options - -def main(): - """Install or upgrade setuptools and EasyInstall""" - options = _parse_args() - archive = download_setuptools( - version=options.version, - download_base=options.download_base, - downloader_factory=options.downloader_factory, - ) - return _install(archive, _build_install_args(options)) - -if __name__ == '__main__': - sys.exit(main()) diff --git a/python/google/protobuf/internal/_parameterized.py b/python/google/protobuf/internal/_parameterized.py index 6c5a2bac..3821b916 100755 --- a/python/google/protobuf/internal/_parameterized.py +++ b/python/google/protobuf/internal/_parameterized.py @@ -263,6 +263,8 @@ def _ModifyClass(class_object, testcases, naming_type): 'Cannot add parameters to %s,' ' which already has parameterized methods.' % (class_object,)) class_object._id_suffix = id_suffix = {} + # We change the size of __dict__ while we iterate over it, + # which Python 3.x will complain about, so use copy(). for name, obj in class_object.__dict__.copy().items(): if (name.startswith(unittest.TestLoader.testMethodPrefix) and isinstance(obj, types.FunctionType)): diff --git a/python/setup.py b/python/setup.py index 79e23698..23193cba 100755 --- a/python/setup.py +++ b/python/setup.py @@ -8,19 +8,7 @@ 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, find_packages -except ImportError: - try: - from ez_setup import use_setuptools - use_setuptools() - from setuptools import setup, Extension, find_packages - 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 diff --git a/python/tox.ini b/python/tox.ini index d73d27af..24b709ef 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -1,5 +1,7 @@ [tox] envlist = + # Py3 tests currently fail because of text handling issues, + # So only test py26/py27 for now. #py26,py27,py33,py34 py26,py27 -- cgit v1.2.3 From 416f001adca9d3b2247a21630e4a71ec6e8d14e9 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Thu, 20 Aug 2015 15:29:10 -0400 Subject: Use tox in travis build. Tweak tox.ini Signed-off-by: Dan O'Reilly --- python/setup.py | 1 + python/tox.ini | 5 +++-- travis.sh | 10 ++-------- 3 files changed, 6 insertions(+), 10 deletions(-) (limited to 'python/setup.py') diff --git a/python/setup.py b/python/setup.py index 23193cba..24f0c5b6 100755 --- a/python/setup.py +++ b/python/setup.py @@ -132,6 +132,7 @@ if __name__ == '__main__': ext_module_list = [] cpp_impl = '--cpp_implementation' if cpp_impl in sys.argv: + print("YYYYYYYYYYYYYYYYYYYYYYYY") sys.argv.remove(cpp_impl) # C++ implementation extension ext_module_list.append( diff --git a/python/tox.ini b/python/tox.ini index 24b709ef..4a994b61 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -10,8 +10,9 @@ usedevelop = true setenv = LD_LIBRARY_PATH={toxinidir}/../src/.libs commands = - python setup.py -q --cpp_implementation develop - python setup.py build_py + python setup.py -q build_py + python setup.py -q build {posargs} python setup.py -q test -q {posargs} + pip install --install-option {posargs: -q} . deps = six diff --git a/travis.sh b/travis.sh index 07004571..c061cad5 100755 --- a/travis.sh +++ b/travis.sh @@ -114,10 +114,7 @@ build_javanano_oracle7() { build_python() { internal_build_cpp cd python - python setup.py build - python setup.py test - python setup.py sdist - sudo pip install virtualenv && virtualenv /tmp/protoenv && /tmp/protoenv/bin/pip install dist/* + tox cd .. } @@ -126,10 +123,7 @@ build_python_cpp() { export LD_LIBRARY_PATH=../src/.libs # for Linux export DYLD_LIBRARY_PATH=../src/.libs # for OS X cd python - python setup.py build --cpp_implementation - python setup.py test --cpp_implementation - python setup.py sdist --cpp_implementation - sudo pip install virtualenv && virtualenv /tmp/protoenv && /tmp/protoenv/bin/pip install dist/* + tox -- --cpp_implementation cd .. } -- cgit v1.2.3 From afa488c4d10a06730d7a16a8eda4935a06ea965d Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Thu, 20 Aug 2015 15:51:06 -0400 Subject: Remove debug code Signed-off-by: Dan O'Reilly --- python/setup.py | 1 - 1 file changed, 1 deletion(-) (limited to 'python/setup.py') diff --git a/python/setup.py b/python/setup.py index 24f0c5b6..23193cba 100755 --- a/python/setup.py +++ b/python/setup.py @@ -132,7 +132,6 @@ if __name__ == '__main__': ext_module_list = [] cpp_impl = '--cpp_implementation' if cpp_impl in sys.argv: - print("YYYYYYYYYYYYYYYYYYYYYYYY") sys.argv.remove(cpp_impl) # C++ implementation extension ext_module_list.append( -- cgit v1.2.3 From 3791c8051a587de347c3aa1c03de79dce38c1a2e Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Thu, 20 Aug 2015 20:49:45 -0400 Subject: Fix travis build Signed-off-by: Dan O'Reilly --- python/setup.py | 1 + python/tox.ini | 2 ++ 2 files changed, 3 insertions(+) (limited to 'python/setup.py') diff --git a/python/setup.py b/python/setup.py index 23193cba..f7ee6357 100755 --- a/python/setup.py +++ b/python/setup.py @@ -146,6 +146,7 @@ if __name__ == '__main__': ) os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp' + # Keep this list of dependencies in sync with tox.ini. install_requires = ['six', 'setuptools'] if sys.version_info <= (2,7): install_requires.append('ordereddict') diff --git a/python/tox.ini b/python/tox.ini index ebe75459..d758512d 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -6,6 +6,7 @@ envlist = py{26,27}-{cpp,python} [testenv] +usedevelop=true setenv = cpp: LD_LIBRARY_PATH={toxinidir}/../src/.libs cpp: PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp @@ -16,6 +17,7 @@ commands = python: python setup.py -q test -q cpp: python setup.py -q test -q --cpp_implementation deps = + # Keep this list of dependencies in sync with setup.py. six py26: ordereddict py26: unittest2 -- cgit v1.2.3