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

Side by Side Diff: third_party/protobuf/python/setup.py

Issue 21208003: Update protobuf to r428, part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #! /usr/bin/python 1 #! /usr/bin/python
2 # 2 #
3 # See README for usage instructions. 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.
7 from ez_setup import use_setuptools
8 use_setuptools()
9
10 from setuptools import setup, Extension
11 from distutils.spawn import find_executable
12 import sys 4 import sys
13 import os 5 import os
14 import subprocess 6 import subprocess
15 7
8 # We must use setuptools, not distutils, because we need to use the
9 # namespace_packages option for the "google" package.
10 try:
11 from setuptools import setup, Extension
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
23 from distutils.command.build_py import build_py as _build_py
24 from distutils.spawn import find_executable
25
16 maintainer_email = "protobuf@googlegroups.com" 26 maintainer_email = "protobuf@googlegroups.com"
17 27
18 # Find the Protocol Compiler. 28 # Find the Protocol Compiler.
19 if os.path.exists("../src/protoc"): 29 if os.path.exists("../src/protoc"):
20 protoc = "../src/protoc" 30 protoc = "../src/protoc"
21 elif os.path.exists("../src/protoc.exe"): 31 elif os.path.exists("../src/protoc.exe"):
22 protoc = "../src/protoc.exe" 32 protoc = "../src/protoc.exe"
23 elif os.path.exists("../vsprojects/Debug/protoc.exe"): 33 elif os.path.exists("../vsprojects/Debug/protoc.exe"):
24 protoc = "../vsprojects/Debug/protoc.exe" 34 protoc = "../vsprojects/Debug/protoc.exe"
25 elif os.path.exists("../vsprojects/Release/protoc.exe"): 35 elif os.path.exists("../vsprojects/Release/protoc.exe"):
26 protoc = "../vsprojects/Release/protoc.exe" 36 protoc = "../vsprojects/Release/protoc.exe"
27 else: 37 else:
28 protoc = find_executable("protoc") 38 protoc = find_executable("protoc")
29 39
30 def generate_proto(source): 40 def generate_proto(source):
31 """Invokes the Protocol Compiler to generate a _pb2.py from the given 41 """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 42 .proto file. Does nothing if the output already exists and is newer than
33 the input.""" 43 the input."""
34 44
35 output = source.replace(".proto", "_pb2.py").replace("../src/", "") 45 output = source.replace(".proto", "_pb2.py").replace("../src/", "")
36 46
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 47 if (not os.path.exists(output) or
42 (os.path.exists(source) and 48 (os.path.exists(source) and
43 os.path.getmtime(source) > os.path.getmtime(output))): 49 os.path.getmtime(source) > os.path.getmtime(output))):
44 print "Generating %s..." % output 50 print "Generating %s..." % output
45 51
52 if not os.path.exists(source):
53 sys.stderr.write("Can't find required file: %s\n" % source)
54 sys.exit(-1)
55
46 if protoc == None: 56 if protoc == None:
47 sys.stderr.write( 57 sys.stderr.write(
48 "protoc is not installed nor found in ../src. Please compile it " 58 "protoc is not installed nor found in ../src. Please compile it "
49 "or install the binary package.\n") 59 "or install the binary package.\n")
50 sys.exit(-1) 60 sys.exit(-1)
51 61
52 protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ] 62 protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ]
53 if subprocess.call(protoc_command) != 0: 63 if subprocess.call(protoc_command) != 0:
54 sys.exit(-1) 64 sys.exit(-1)
55 65
66 def GenerateUnittestProtos():
67 generate_proto("../src/google/protobuf/unittest.proto")
68 generate_proto("../src/google/protobuf/unittest_custom_options.proto")
69 generate_proto("../src/google/protobuf/unittest_import.proto")
70 generate_proto("../src/google/protobuf/unittest_import_public.proto")
71 generate_proto("../src/google/protobuf/unittest_mset.proto")
72 generate_proto("../src/google/protobuf/unittest_no_generic_services.proto")
73 generate_proto("google/protobuf/internal/test_bad_identifiers.proto")
74 generate_proto("google/protobuf/internal/more_extensions.proto")
75 generate_proto("google/protobuf/internal/more_extensions_dynamic.proto")
76 generate_proto("google/protobuf/internal/more_messages.proto")
77 generate_proto("google/protobuf/internal/factory_test1.proto")
78 generate_proto("google/protobuf/internal/factory_test2.proto")
79
56 def MakeTestSuite(): 80 def MakeTestSuite():
57 # This is apparently needed on some systems to make sure that the tests 81 # This is apparently needed on some systems to make sure that the tests
58 # work even if a previous version is already installed. 82 # work even if a previous version is already installed.
59 if 'google' in sys.modules: 83 if 'google' in sys.modules:
60 del sys.modules['google'] 84 del sys.modules['google']
61 85 GenerateUnittestProtos()
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 86
70 import unittest 87 import unittest
71 import google.protobuf.internal.generator_test as generator_test 88 import google.protobuf.internal.generator_test as generator_test
72 import google.protobuf.internal.descriptor_test as descriptor_test 89 import google.protobuf.internal.descriptor_test as descriptor_test
73 import google.protobuf.internal.reflection_test as reflection_test 90 import google.protobuf.internal.reflection_test as reflection_test
74 import google.protobuf.internal.service_reflection_test \ 91 import google.protobuf.internal.service_reflection_test \
75 as service_reflection_test 92 as service_reflection_test
76 import google.protobuf.internal.text_format_test as text_format_test 93 import google.protobuf.internal.text_format_test as text_format_test
77 import google.protobuf.internal.wire_format_test as wire_format_test 94 import google.protobuf.internal.wire_format_test as wire_format_test
95 import google.protobuf.internal.unknown_fields_test as unknown_fields_test
96 import google.protobuf.internal.descriptor_database_test \
97 as descriptor_database_test
98 import google.protobuf.internal.descriptor_pool_test as descriptor_pool_test
99 import google.protobuf.internal.message_factory_test as message_factory_test
100 import google.protobuf.internal.message_cpp_test as message_cpp_test
101 import google.protobuf.internal.reflection_cpp_generated_test \
102 as reflection_cpp_generated_test
78 103
79 loader = unittest.defaultTestLoader 104 loader = unittest.defaultTestLoader
80 suite = unittest.TestSuite() 105 suite = unittest.TestSuite()
81 for test in [ generator_test, 106 for test in [ generator_test,
82 descriptor_test, 107 descriptor_test,
83 reflection_test, 108 reflection_test,
84 service_reflection_test, 109 service_reflection_test,
85 text_format_test, 110 text_format_test,
86 wire_format_test ]: 111 wire_format_test ]:
87 suite.addTest(loader.loadTestsFromModule(test)) 112 suite.addTest(loader.loadTestsFromModule(test))
88 113
89 return suite 114 return suite
90 115
91 if __name__ == '__main__': 116
92 # TODO(kenton): Integrate this into setuptools somehow? 117 class clean(_clean):
93 if len(sys.argv) >= 2 and sys.argv[1] == "clean": 118 def run(self):
94 # Delete generated _pb2.py files and .pyc files in the code tree. 119 # Delete generated files in the code tree.
95 for (dirpath, dirnames, filenames) in os.walk("."): 120 for (dirpath, dirnames, filenames) in os.walk("."):
96 for filename in filenames: 121 for filename in filenames:
97 filepath = os.path.join(dirpath, filename) 122 filepath = os.path.join(dirpath, filename)
98 if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \ 123 if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \
99 filepath.endswith(".so") or filepath.endswith(".o"): 124 filepath.endswith(".so") or filepath.endswith(".o") or \
125 filepath.endswith('google/protobuf/compiler/__init__.py'):
100 os.remove(filepath) 126 os.remove(filepath)
101 else: 127 # _clean is an old-style class, so super() doesn't work.
128 _clean.run(self)
129
130 class build_py(_build_py):
131 def run(self):
102 # Generate necessary .proto file if it doesn't exist. 132 # 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") 133 generate_proto("../src/google/protobuf/descriptor.proto")
105 generate_proto("../src/google/protobuf/compiler/plugin.proto") 134 generate_proto("../src/google/protobuf/compiler/plugin.proto")
106 135
136 GenerateUnittestProtos()
137 # Make sure google.protobuf.compiler is a valid package.
138 open('google/protobuf/compiler/__init__.py', 'a').close()
139 # _build_py is an old-style class, so super() doesn't work.
140 _build_py.run(self)
141
142 if __name__ == '__main__':
107 ext_module_list = [] 143 ext_module_list = []
108 144
109 # C++ implementation extension 145 # C++ implementation extension
110 if os.getenv("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python") == "cpp": 146 if os.getenv("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python") == "cpp":
111 print "Using EXPERIMENTAL C++ Implmenetation." 147 print "Using EXPERIMENTAL C++ Implmenetation."
112 ext_module_list.append(Extension( 148 ext_module_list.append(Extension(
113 "google.protobuf.internal._net_proto2___python", 149 "google.protobuf.internal._net_proto2___python",
114 [ "google/protobuf/pyext/python_descriptor.cc", 150 [ "google/protobuf/pyext/python_descriptor.cc",
115 "google/protobuf/pyext/python_protobuf.cc", 151 "google/protobuf/pyext/python_protobuf.cc",
116 "google/protobuf/pyext/python-proto2.cc" ], 152 "google/protobuf/pyext/python-proto2.cc" ],
(...skipping 13 matching lines...) Expand all
130 'google.protobuf.internal.decoder', 166 'google.protobuf.internal.decoder',
131 'google.protobuf.internal.encoder', 167 'google.protobuf.internal.encoder',
132 'google.protobuf.internal.message_listener', 168 'google.protobuf.internal.message_listener',
133 'google.protobuf.internal.python_message', 169 'google.protobuf.internal.python_message',
134 'google.protobuf.internal.type_checkers', 170 'google.protobuf.internal.type_checkers',
135 'google.protobuf.internal.wire_format', 171 'google.protobuf.internal.wire_format',
136 'google.protobuf.descriptor', 172 'google.protobuf.descriptor',
137 'google.protobuf.descriptor_pb2', 173 'google.protobuf.descriptor_pb2',
138 'google.protobuf.compiler.plugin_pb2', 174 'google.protobuf.compiler.plugin_pb2',
139 'google.protobuf.message', 175 'google.protobuf.message',
176 'google.protobuf.descriptor_database',
177 'google.protobuf.descriptor_pool',
178 'google.protobuf.message_factory',
140 'google.protobuf.reflection', 179 'google.protobuf.reflection',
141 'google.protobuf.service', 180 'google.protobuf.service',
142 'google.protobuf.service_reflection', 181 'google.protobuf.service_reflection',
143 'google.protobuf.text_format' ], 182 'google.protobuf.text_format' ],
183 cmdclass = { 'clean': clean, 'build_py': build_py },
184 install_requires = ['setuptools'],
144 ext_modules = ext_module_list, 185 ext_modules = ext_module_list,
145 url = 'http://code.google.com/p/protobuf/', 186 url = 'http://code.google.com/p/protobuf/',
146 maintainer = maintainer_email, 187 maintainer = maintainer_email,
147 maintainer_email = 'protobuf@googlegroups.com', 188 maintainer_email = 'protobuf@googlegroups.com',
148 license = 'New BSD License', 189 license = 'New BSD License',
149 description = 'Protocol Buffers', 190 description = 'Protocol Buffers',
150 long_description = 191 long_description =
151 "Protocol Buffers are Google's data interchange format.", 192 "Protocol Buffers are Google's data interchange format.",
152 ) 193 )
OLDNEW
« no previous file with comments | « third_party/protobuf/python/google/protobuf/text_format.py ('k') | third_party/protobuf/src/Makefile.am » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698