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

http://github.com/tomahawk-player/tomahawk · Python · 152 lines · 116 code · 19 blank · 17 comment · 22 complexity · e9e81c2687bee3f0b7def8bf20b999b0 MD5 · raw file

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