MCPcopy Create free account
hub / github.com/apple/coremltools / generate_proto

Function generate_proto

deps/protobuf/python/setup.py:51–78  ·  view source on GitHub ↗

Invokes the Protocol Compiler to generate a _pb2.py from the given .proto file. Does nothing if the output already exists and is newer than the input.

(source, require = True)

Source from the content-addressed store, hash-verified

49
50
51def generate_proto(source, require = True):
52 """Invokes the Protocol Compiler to generate a _pb2.py from the given
53 .proto file. Does nothing if the output already exists and is newer than
54 the input."""
55
56 if not require and not os.path.exists(source):
57 return
58
59 output = source.replace(".proto", "_pb2.py").replace("../src/", "")
60
61 if (not os.path.exists(output) or
62 (os.path.exists(source) and
63 os.path.getmtime(source) > os.path.getmtime(output))):
64 print("Generating %s..." % output)
65
66 if not os.path.exists(source):
67 sys.stderr.write("Can't find required file: %s\n" % source)
68 sys.exit(-1)
69
70 if protoc is None:
71 sys.stderr.write(
72 "protoc is not installed nor found in ../src. Please compile it "
73 "or install the binary package.\n")
74 sys.exit(-1)
75
76 protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ]
77 if subprocess.call(protoc_command) != 0:
78 sys.exit(-1)
79
80def GenerateUnittestProtos():
81 generate_proto("../src/google/protobuf/any_test.proto", False)

Callers 2

GenerateUnittestProtosFunction · 0.85
runMethod · 0.85

Calls 5

printFunction · 0.85
replaceMethod · 0.80
exitMethod · 0.80
writeMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected