| OLD | NEW | 
|    1 #! /usr/bin/python |    1 #! /usr/bin/env python | 
|    2 # |    2 # | 
|    3 # See README for usage instructions. |    3 # See README for usage instructions. | 
|    4 import sys |    4 import glob | 
|    5 import os |    5 import os | 
|    6 import subprocess |    6 import subprocess | 
 |    7 import sys | 
|    7  |    8  | 
|    8 # We must use setuptools, not distutils, because we need to use the |    9 # We must use setuptools, not distutils, because we need to use the | 
|    9 # namespace_packages option for the "google" package. |   10 # namespace_packages option for the "google" package. | 
|   10 try: |   11 from setuptools import setup, Extension, find_packages | 
|   11   from setuptools import setup, Extension |   12  | 
|   12 except ImportError: |  | 
|   13   try: |  | 
|   14     from ez_setup import use_setuptools |  | 
|   15     use_setuptools() |  | 
|   16     from setuptools import setup, Extension |  | 
|   17   except ImportError: |  | 
|   18     sys.stderr.write( |  | 
|   19         "Could not import setuptools; make sure you have setuptools or " |  | 
|   20         "ez_setup installed.\n") |  | 
|   21     raise |  | 
|   22 from distutils.command.clean import clean as _clean |   13 from distutils.command.clean import clean as _clean | 
|   23 from distutils.command.build_py import build_py as _build_py |   14  | 
 |   15 if sys.version_info[0] == 3: | 
 |   16   # Python 3 | 
 |   17   from distutils.command.build_py import build_py_2to3 as _build_py | 
 |   18 else: | 
 |   19   # Python 2 | 
 |   20   from distutils.command.build_py import build_py as _build_py | 
|   24 from distutils.spawn import find_executable |   21 from distutils.spawn import find_executable | 
|   25  |   22  | 
|   26 maintainer_email = "protobuf@googlegroups.com" |  | 
|   27  |  | 
|   28 # Find the Protocol Compiler. |   23 # Find the Protocol Compiler. | 
|   29 if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']): |   24 if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']): | 
|   30   protoc = os.environ['PROTOC'] |   25   protoc = os.environ['PROTOC'] | 
|   31 elif os.path.exists("../src/protoc"): |   26 elif os.path.exists("../src/protoc"): | 
|   32   protoc = "../src/protoc" |   27   protoc = "../src/protoc" | 
|   33 elif os.path.exists("../src/protoc.exe"): |   28 elif os.path.exists("../src/protoc.exe"): | 
|   34   protoc = "../src/protoc.exe" |   29   protoc = "../src/protoc.exe" | 
|   35 elif os.path.exists("../vsprojects/Debug/protoc.exe"): |   30 elif os.path.exists("../vsprojects/Debug/protoc.exe"): | 
|   36   protoc = "../vsprojects/Debug/protoc.exe" |   31   protoc = "../vsprojects/Debug/protoc.exe" | 
|   37 elif os.path.exists("../vsprojects/Release/protoc.exe"): |   32 elif os.path.exists("../vsprojects/Release/protoc.exe"): | 
|   38   protoc = "../vsprojects/Release/protoc.exe" |   33   protoc = "../vsprojects/Release/protoc.exe" | 
|   39 else: |   34 else: | 
|   40   protoc = find_executable("protoc") |   35   protoc = find_executable("protoc") | 
|   41  |   36  | 
|   42 def generate_proto(source): |   37  | 
 |   38 def GetVersion(): | 
 |   39   """Gets the version from google/protobuf/__init__.py | 
 |   40  | 
 |   41   Do not import google.protobuf.__init__ directly, because an installed | 
 |   42   protobuf library may be loaded instead.""" | 
 |   43  | 
 |   44   with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file: | 
 |   45     exec(version_file.read(), globals()) | 
 |   46     return __version__ | 
 |   47  | 
 |   48  | 
 |   49 def generate_proto(source, require = True): | 
|   43   """Invokes the Protocol Compiler to generate a _pb2.py from the given |   50   """Invokes the Protocol Compiler to generate a _pb2.py from the given | 
|   44   .proto file.  Does nothing if the output already exists and is newer than |   51   .proto file.  Does nothing if the output already exists and is newer than | 
|   45   the input.""" |   52   the input.""" | 
|   46  |   53  | 
 |   54   if not require and not os.path.exists(source): | 
 |   55     return | 
 |   56  | 
|   47   output = source.replace(".proto", "_pb2.py").replace("../src/", "") |   57   output = source.replace(".proto", "_pb2.py").replace("../src/", "") | 
|   48  |   58  | 
|   49   if (not os.path.exists(output) or |   59   if (not os.path.exists(output) or | 
|   50       (os.path.exists(source) and |   60       (os.path.exists(source) and | 
|   51        os.path.getmtime(source) > os.path.getmtime(output))): |   61        os.path.getmtime(source) > os.path.getmtime(output))): | 
|   52     print "Generating %s..." % output |   62     print("Generating %s..." % output) | 
|   53  |   63  | 
|   54     if not os.path.exists(source): |   64     if not os.path.exists(source): | 
|   55       sys.stderr.write("Can't find required file: %s\n" % source) |   65       sys.stderr.write("Can't find required file: %s\n" % source) | 
|   56       sys.exit(-1) |   66       sys.exit(-1) | 
|   57  |   67  | 
|   58     if protoc == None: |   68     if protoc is None: | 
|   59       sys.stderr.write( |   69       sys.stderr.write( | 
|   60           "protoc is not installed nor found in ../src.  Please compile it " |   70           "protoc is not installed nor found in ../src.  Please compile it " | 
|   61           "or install the binary package.\n") |   71           "or install the binary package.\n") | 
|   62       sys.exit(-1) |   72       sys.exit(-1) | 
|   63  |   73  | 
|   64     protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ] |   74     protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ] | 
|   65     if subprocess.call(protoc_command) != 0: |   75     if subprocess.call(protoc_command) != 0: | 
|   66       sys.exit(-1) |   76       sys.exit(-1) | 
|   67  |   77  | 
|   68 def GenerateUnittestProtos(): |   78 def GenerateUnittestProtos(): | 
|   69   generate_proto("../src/google/protobuf/unittest.proto") |   79   generate_proto("../src/google/protobuf/map_unittest.proto", False) | 
|   70   generate_proto("../src/google/protobuf/unittest_custom_options.proto") |   80   generate_proto("../src/google/protobuf/unittest_arena.proto", False) | 
|   71   generate_proto("../src/google/protobuf/unittest_import.proto") |   81   generate_proto("../src/google/protobuf/unittest_no_arena.proto", False) | 
|   72   generate_proto("../src/google/protobuf/unittest_import_public.proto") |   82   generate_proto("../src/google/protobuf/unittest_no_arena_import.proto", False) | 
|   73   generate_proto("../src/google/protobuf/unittest_mset.proto") |   83   generate_proto("../src/google/protobuf/unittest.proto", False) | 
|   74   generate_proto("../src/google/protobuf/unittest_no_generic_services.proto") |   84   generate_proto("../src/google/protobuf/unittest_custom_options.proto", False) | 
|   75   generate_proto("google/protobuf/internal/test_bad_identifiers.proto") |   85   generate_proto("../src/google/protobuf/unittest_import.proto", False) | 
|   76   generate_proto("google/protobuf/internal/more_extensions.proto") |   86   generate_proto("../src/google/protobuf/unittest_import_public.proto", False) | 
|   77   generate_proto("google/protobuf/internal/more_extensions_dynamic.proto") |   87   generate_proto("../src/google/protobuf/unittest_mset.proto", False) | 
|   78   generate_proto("google/protobuf/internal/more_messages.proto") |   88   generate_proto("../src/google/protobuf/unittest_mset_wire_format.proto", False
     ) | 
|   79   generate_proto("google/protobuf/internal/factory_test1.proto") |   89   generate_proto("../src/google/protobuf/unittest_no_generic_services.proto", Fa
     lse) | 
|   80   generate_proto("google/protobuf/internal/factory_test2.proto") |   90   generate_proto("../src/google/protobuf/unittest_proto3_arena.proto", False) | 
|   81  |   91   generate_proto("../src/google/protobuf/util/json_format_proto3.proto", False) | 
|   82 def MakeTestSuite(): |   92   generate_proto("google/protobuf/internal/any_test.proto", False) | 
|   83   # This is apparently needed on some systems to make sure that the tests |   93   generate_proto("google/protobuf/internal/descriptor_pool_test1.proto", False) | 
|   84   # work even if a previous version is already installed. |   94   generate_proto("google/protobuf/internal/descriptor_pool_test2.proto", False) | 
|   85   if 'google' in sys.modules: |   95   generate_proto("google/protobuf/internal/factory_test1.proto", False) | 
|   86     del sys.modules['google'] |   96   generate_proto("google/protobuf/internal/factory_test2.proto", False) | 
|   87   GenerateUnittestProtos() |   97   generate_proto("google/protobuf/internal/import_test_package/inner.proto", Fal
     se) | 
|   88  |   98   generate_proto("google/protobuf/internal/import_test_package/outer.proto", Fal
     se) | 
|   89   import unittest |   99   generate_proto("google/protobuf/internal/missing_enum_values.proto", False) | 
|   90   import google.protobuf.internal.generator_test     as generator_test |  100   generate_proto("google/protobuf/internal/message_set_extensions.proto", False) | 
|   91   import google.protobuf.internal.descriptor_test    as descriptor_test |  101   generate_proto("google/protobuf/internal/more_extensions.proto", False) | 
|   92   import google.protobuf.internal.reflection_test    as reflection_test |  102   generate_proto("google/protobuf/internal/more_extensions_dynamic.proto", False
     ) | 
|   93   import google.protobuf.internal.service_reflection_test \ |  103   generate_proto("google/protobuf/internal/more_messages.proto", False) | 
|   94     as service_reflection_test |  104   generate_proto("google/protobuf/internal/packed_field_test.proto", False) | 
|   95   import google.protobuf.internal.text_format_test   as text_format_test |  105   generate_proto("google/protobuf/internal/test_bad_identifiers.proto", False) | 
|   96   import google.protobuf.internal.wire_format_test   as wire_format_test |  106   generate_proto("google/protobuf/pyext/python.proto", False) | 
|   97   import google.protobuf.internal.unknown_fields_test as unknown_fields_test |  | 
|   98   import google.protobuf.internal.descriptor_database_test \ |  | 
|   99       as descriptor_database_test |  | 
|  100   import google.protobuf.internal.descriptor_pool_test as descriptor_pool_test |  | 
|  101   import google.protobuf.internal.message_factory_test as message_factory_test |  | 
|  102   import google.protobuf.internal.message_cpp_test as message_cpp_test |  | 
|  103   import google.protobuf.internal.reflection_cpp_generated_test \ |  | 
|  104       as reflection_cpp_generated_test |  | 
|  105  |  | 
|  106   loader = unittest.defaultTestLoader |  | 
|  107   suite = unittest.TestSuite() |  | 
|  108   for test in [ generator_test, |  | 
|  109                 descriptor_test, |  | 
|  110                 reflection_test, |  | 
|  111                 service_reflection_test, |  | 
|  112                 text_format_test, |  | 
|  113                 wire_format_test ]: |  | 
|  114     suite.addTest(loader.loadTestsFromModule(test)) |  | 
|  115  |  | 
|  116   return suite |  | 
|  117  |  107  | 
|  118  |  108  | 
|  119 class clean(_clean): |  109 class clean(_clean): | 
|  120   def run(self): |  110   def run(self): | 
|  121     # Delete generated files in the code tree. |  111     # Delete generated files in the code tree. | 
|  122     for (dirpath, dirnames, filenames) in os.walk("."): |  112     for (dirpath, dirnames, filenames) in os.walk("."): | 
|  123       for filename in filenames: |  113       for filename in filenames: | 
|  124         filepath = os.path.join(dirpath, filename) |  114         filepath = os.path.join(dirpath, filename) | 
|  125         if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \ |  115         if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \ | 
|  126           filepath.endswith(".so") or filepath.endswith(".o") or \ |  116           filepath.endswith(".so") or filepath.endswith(".o") or \ | 
|  127           filepath.endswith('google/protobuf/compiler/__init__.py'): |  117           filepath.endswith('google/protobuf/compiler/__init__.py') or \ | 
 |  118           filepath.endswith('google/protobuf/util/__init__.py'): | 
|  128           os.remove(filepath) |  119           os.remove(filepath) | 
|  129     # _clean is an old-style class, so super() doesn't work. |  120     # _clean is an old-style class, so super() doesn't work. | 
|  130     _clean.run(self) |  121     _clean.run(self) | 
|  131  |  122  | 
|  132 class build_py(_build_py): |  123 class build_py(_build_py): | 
|  133   def run(self): |  124   def run(self): | 
|  134     # Generate necessary .proto file if it doesn't exist. |  125     # Generate necessary .proto file if it doesn't exist. | 
|  135     generate_proto("../src/google/protobuf/descriptor.proto") |  126     generate_proto("../src/google/protobuf/descriptor.proto") | 
|  136     generate_proto("../src/google/protobuf/compiler/plugin.proto") |  127     generate_proto("../src/google/protobuf/compiler/plugin.proto") | 
 |  128     generate_proto("../src/google/protobuf/any.proto") | 
 |  129     generate_proto("../src/google/protobuf/api.proto") | 
 |  130     generate_proto("../src/google/protobuf/duration.proto") | 
 |  131     generate_proto("../src/google/protobuf/empty.proto") | 
 |  132     generate_proto("../src/google/protobuf/field_mask.proto") | 
 |  133     generate_proto("../src/google/protobuf/source_context.proto") | 
 |  134     generate_proto("../src/google/protobuf/struct.proto") | 
 |  135     generate_proto("../src/google/protobuf/timestamp.proto") | 
 |  136     generate_proto("../src/google/protobuf/type.proto") | 
 |  137     generate_proto("../src/google/protobuf/wrappers.proto") | 
 |  138     GenerateUnittestProtos() | 
|  137  |  139  | 
|  138     GenerateUnittestProtos() |  140     # Make sure google.protobuf/** are valid packages. | 
|  139     # Make sure google.protobuf.compiler is a valid package. |  141     for path in ['', 'internal/', 'compiler/', 'pyext/', 'util/']: | 
|  140     open('google/protobuf/compiler/__init__.py', 'a').close() |  142       try: | 
 |  143         open('google/protobuf/%s__init__.py' % path, 'a').close() | 
 |  144       except EnvironmentError: | 
 |  145         pass | 
|  141     # _build_py is an old-style class, so super() doesn't work. |  146     # _build_py is an old-style class, so super() doesn't work. | 
|  142     _build_py.run(self) |  147     _build_py.run(self) | 
|  143  |  148  | 
 |  149 class test_conformance(_build_py): | 
 |  150   target = 'test_python' | 
 |  151   def run(self): | 
 |  152     cmd = 'cd ../conformance && make %s' % (test_conformance.target) | 
 |  153     status = subprocess.check_call(cmd, shell=True) | 
 |  154  | 
 |  155  | 
|  144 if __name__ == '__main__': |  156 if __name__ == '__main__': | 
|  145   ext_module_list = [] |  157   ext_module_list = [] | 
 |  158   cpp_impl = '--cpp_implementation' | 
 |  159   warnings_as_errors = '--warnings_as_errors' | 
 |  160   if cpp_impl in sys.argv: | 
 |  161     sys.argv.remove(cpp_impl) | 
 |  162     extra_compile_args = ['-Wno-write-strings', '-Wno-invalid-offsetof'] | 
 |  163     test_conformance.target = 'test_python_cpp' | 
|  146  |  164  | 
|  147   # C++ implementation extension |  165     if "clang" in os.popen('$CC --version').read(): | 
|  148   if os.getenv("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python") == "cpp": |  166       extra_compile_args.append('-Wno-shorten-64-to-32') | 
|  149     print "Using EXPERIMENTAL C++ Implmenetation." |  | 
|  150     ext_module_list.append(Extension( |  | 
|  151         "google.protobuf.internal._net_proto2___python", |  | 
|  152         [ "google/protobuf/pyext/python_descriptor.cc", |  | 
|  153           "google/protobuf/pyext/python_protobuf.cc", |  | 
|  154           "google/protobuf/pyext/python-proto2.cc" ], |  | 
|  155         include_dirs = [ "." ], |  | 
|  156         libraries = [ "protobuf" ])) |  | 
|  157  |  167  | 
|  158   setup(name = 'protobuf', |  168     if warnings_as_errors in sys.argv: | 
|  159         version = '2.5.0-pre', |  169       extra_compile_args.append('-Werror') | 
|  160         packages = [ 'google' ], |  170       sys.argv.remove(warnings_as_errors) | 
|  161         namespace_packages = [ 'google' ], |  171  | 
|  162         test_suite = 'setup.MakeTestSuite', |  172     # C++ implementation extension | 
|  163         # Must list modules explicitly so that we don't install tests. |  173     ext_module_list.append( | 
|  164         py_modules = [ |  174         Extension( | 
|  165           'google.protobuf.internal.api_implementation', |  175             "google.protobuf.pyext._message", | 
|  166           'google.protobuf.internal.containers', |  176             glob.glob('google/protobuf/pyext/*.cc'), | 
|  167           'google.protobuf.internal.cpp_message', |  177             include_dirs=[".", "../src"], | 
|  168           'google.protobuf.internal.decoder', |  178             libraries=['protobuf'], | 
|  169           'google.protobuf.internal.encoder', |  179             library_dirs=['../src/.libs'], | 
|  170           'google.protobuf.internal.enum_type_wrapper', |  180             extra_compile_args=extra_compile_args, | 
|  171           'google.protobuf.internal.message_listener', |  | 
|  172           'google.protobuf.internal.python_message', |  | 
|  173           'google.protobuf.internal.type_checkers', |  | 
|  174           'google.protobuf.internal.wire_format', |  | 
|  175           'google.protobuf.descriptor', |  | 
|  176           'google.protobuf.descriptor_pb2', |  | 
|  177           'google.protobuf.compiler.plugin_pb2', |  | 
|  178           'google.protobuf.message', |  | 
|  179           'google.protobuf.descriptor_database', |  | 
|  180           'google.protobuf.descriptor_pool', |  | 
|  181           'google.protobuf.message_factory', |  | 
|  182           'google.protobuf.reflection', |  | 
|  183           'google.protobuf.service', |  | 
|  184           'google.protobuf.service_reflection', |  | 
|  185           'google.protobuf.text_format' ], |  | 
|  186         cmdclass = { 'clean': clean, 'build_py': build_py }, |  | 
|  187         install_requires = ['setuptools'], |  | 
|  188         ext_modules = ext_module_list, |  | 
|  189         url = 'http://code.google.com/p/protobuf/', |  | 
|  190         maintainer = maintainer_email, |  | 
|  191         maintainer_email = 'protobuf@googlegroups.com', |  | 
|  192         license = 'New BSD License', |  | 
|  193         description = 'Protocol Buffers', |  | 
|  194         long_description = |  | 
|  195           "Protocol Buffers are Google's data interchange format.", |  | 
|  196         ) |  181         ) | 
 |  182     ) | 
 |  183     os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp' | 
 |  184  | 
 |  185   # Keep this list of dependencies in sync with tox.ini. | 
 |  186   install_requires = ['six>=1.9', 'setuptools'] | 
 |  187   if sys.version_info <= (2,7): | 
 |  188     install_requires.append('ordereddict') | 
 |  189     install_requires.append('unittest2') | 
 |  190  | 
 |  191   setup( | 
 |  192       name='protobuf', | 
 |  193       version=GetVersion(), | 
 |  194       description='Protocol Buffers', | 
 |  195       long_description="Protocol Buffers are Google's data interchange format", | 
 |  196       url='https://developers.google.com/protocol-buffers/', | 
 |  197       maintainer='protobuf@googlegroups.com', | 
 |  198       maintainer_email='protobuf@googlegroups.com', | 
 |  199       license='New BSD License', | 
 |  200       classifiers=[ | 
 |  201         "Programming Language :: Python", | 
 |  202         "Programming Language :: Python :: 2", | 
 |  203         "Programming Language :: Python :: 2.6", | 
 |  204         "Programming Language :: Python :: 2.7", | 
 |  205         "Programming Language :: Python :: 3", | 
 |  206         "Programming Language :: Python :: 3.3", | 
 |  207         "Programming Language :: Python :: 3.4", | 
 |  208         ], | 
 |  209       namespace_packages=['google'], | 
 |  210       packages=find_packages( | 
 |  211           exclude=[ | 
 |  212               'import_test_package', | 
 |  213           ], | 
 |  214       ), | 
 |  215       test_suite='google.protobuf.internal', | 
 |  216       cmdclass={ | 
 |  217           'clean': clean, | 
 |  218           'build_py': build_py, | 
 |  219           'test_conformance': test_conformance, | 
 |  220       }, | 
 |  221       install_requires=install_requires, | 
 |  222       ext_modules=ext_module_list, | 
 |  223   ) | 
| OLD | NEW |