PageRenderTime 30ms CodeModel.GetById 17ms app.highlight 11ms RepoModel.GetById 0ms app.codeStats 1ms

/thirdparty/breakpad/third_party/protobuf/protobuf/python/setup.py

http://github.com/tomahawk-player/tomahawk
Python | 152 lines | 131 code | 9 blank | 12 comment | 2 complexity | e9e81c2687bee3f0b7def8bf20b999b0 MD5 | raw file
  1#! /usr/bin/python
  2#
  3# See README for usage instructions.
  4
  5# We must use setuptools, not distutils, because we need to use the
  6# namespace_packages option for the "google" package.
  7from ez_setup import use_setuptools
  8use_setuptools()
  9
 10from setuptools import setup, Extension
 11from distutils.spawn import find_executable
 12import sys
 13import os
 14import subprocess
 15
 16maintainer_email = "protobuf@googlegroups.com"
 17
 18# Find the Protocol Compiler.
 19if os.path.exists("../src/protoc"):
 20  protoc = "../src/protoc"
 21elif os.path.exists("../src/protoc.exe"):
 22  protoc = "../src/protoc.exe"
 23elif os.path.exists("../vsprojects/Debug/protoc.exe"):
 24  protoc = "../vsprojects/Debug/protoc.exe"
 25elif os.path.exists("../vsprojects/Release/protoc.exe"):
 26  protoc = "../vsprojects/Release/protoc.exe"
 27else:
 28  protoc = find_executable("protoc")
 29
 30def generate_proto(source):
 31  """Invokes the Protocol Compiler to generate a _pb2.py from the given
 32  .proto file.  Does nothing if the output already exists and is newer than
 33  the input."""
 34
 35  output = source.replace(".proto", "_pb2.py").replace("../src/", "")
 36
 37  if not os.path.exists(source):
 38    print "Can't find required file: " + source
 39    sys.exit(-1)
 40
 41  if (not os.path.exists(output) or
 42      (os.path.exists(source) and
 43       os.path.getmtime(source) > os.path.getmtime(output))):
 44    print "Generating %s..." % output
 45
 46    if protoc == None:
 47      sys.stderr.write(
 48          "protoc is not installed nor found in ../src.  Please compile it "
 49          "or install the binary package.\n")
 50      sys.exit(-1)
 51
 52    protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ]
 53    if subprocess.call(protoc_command) != 0:
 54      sys.exit(-1)
 55
 56def MakeTestSuite():
 57  # This is apparently needed on some systems to make sure that the tests
 58  # work even if a previous version is already installed.
 59  if 'google' in sys.modules:
 60    del sys.modules['google']
 61
 62  generate_proto("../src/google/protobuf/unittest.proto")
 63  generate_proto("../src/google/protobuf/unittest_custom_options.proto")
 64  generate_proto("../src/google/protobuf/unittest_import.proto")
 65  generate_proto("../src/google/protobuf/unittest_mset.proto")
 66  generate_proto("../src/google/protobuf/unittest_no_generic_services.proto")
 67  generate_proto("google/protobuf/internal/more_extensions.proto")
 68  generate_proto("google/protobuf/internal/more_messages.proto")
 69
 70  import unittest
 71  import google.protobuf.internal.generator_test     as generator_test
 72  import google.protobuf.internal.descriptor_test    as descriptor_test
 73  import google.protobuf.internal.reflection_test    as reflection_test
 74  import google.protobuf.internal.service_reflection_test \
 75    as service_reflection_test
 76  import google.protobuf.internal.text_format_test   as text_format_test
 77  import google.protobuf.internal.wire_format_test   as wire_format_test
 78
 79  loader = unittest.defaultTestLoader
 80  suite = unittest.TestSuite()
 81  for test in [ generator_test,
 82                descriptor_test,
 83                reflection_test,
 84                service_reflection_test,
 85                text_format_test,
 86                wire_format_test ]:
 87    suite.addTest(loader.loadTestsFromModule(test))
 88
 89  return suite
 90
 91if __name__ == '__main__':
 92  # TODO(kenton):  Integrate this into setuptools somehow?
 93  if len(sys.argv) >= 2 and sys.argv[1] == "clean":
 94    # Delete generated _pb2.py files and .pyc files in the code tree.
 95    for (dirpath, dirnames, filenames) in os.walk("."):
 96      for filename in filenames:
 97        filepath = os.path.join(dirpath, filename)
 98        if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \
 99          filepath.endswith(".so") or filepath.endswith(".o"):
100          os.remove(filepath)
101  else:
102    # Generate necessary .proto file if it doesn't exist.
103    # TODO(kenton):  Maybe we should hook this into a distutils command?
104    generate_proto("../src/google/protobuf/descriptor.proto")
105    generate_proto("../src/google/protobuf/compiler/plugin.proto")
106
107  ext_module_list = []
108
109  # C++ implementation extension
110  if os.getenv("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python") == "cpp":
111    print "Using EXPERIMENTAL C++ Implmenetation."
112    ext_module_list.append(Extension(
113        "google.protobuf.internal._net_proto2___python",
114        [ "google/protobuf/pyext/python_descriptor.cc",
115          "google/protobuf/pyext/python_protobuf.cc",
116          "google/protobuf/pyext/python-proto2.cc" ],
117        include_dirs = [ "." ],
118        libraries = [ "protobuf" ]))
119
120  setup(name = 'protobuf',
121        version = '2.4.2-pre',
122        packages = [ 'google' ],
123        namespace_packages = [ 'google' ],
124        test_suite = 'setup.MakeTestSuite',
125        # Must list modules explicitly so that we don't install tests.
126        py_modules = [
127          'google.protobuf.internal.api_implementation',
128          'google.protobuf.internal.containers',
129          'google.protobuf.internal.cpp_message',
130          'google.protobuf.internal.decoder',
131          'google.protobuf.internal.encoder',
132          'google.protobuf.internal.message_listener',
133          'google.protobuf.internal.python_message',
134          'google.protobuf.internal.type_checkers',
135          'google.protobuf.internal.wire_format',
136          'google.protobuf.descriptor',
137          'google.protobuf.descriptor_pb2',
138          'google.protobuf.compiler.plugin_pb2',
139          'google.protobuf.message',
140          'google.protobuf.reflection',
141          'google.protobuf.service',
142          'google.protobuf.service_reflection',
143          'google.protobuf.text_format' ],
144        ext_modules = ext_module_list,
145        url = 'http://code.google.com/p/protobuf/',
146        maintainer = maintainer_email,
147        maintainer_email = 'protobuf@googlegroups.com',
148        license = 'New BSD License',
149        description = 'Protocol Buffers',
150        long_description =
151          "Protocol Buffers are Google's data interchange format.",
152        )