1#!/usr/bin/env python3 2# 3# Copyright 2022 Google Inc. All rights reserved. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import subprocess 18import sys 19import generate_grpc_examples 20from pathlib import Path 21 22# Get the path where this script is located so we can invoke the script from 23# any directory and have the paths work correctly. 24script_path = Path(__file__).parent.resolve() 25 26# Get the root path as an absolute path, so all derived paths are absolute. 27root_path = script_path.parent.absolute() 28 29print("Generating GRPC code...") 30generate_grpc_examples.GenerateGRPCExamples() 31 32result = subprocess.run(["git", "diff", "--quiet"], cwd=root_path) 33 34if result.returncode != 0: 35 print( 36 "\n" 37 "ERROR: ********************************************************\n" 38 "ERROR: * The following differences were found after running *\n" 39 "ERROR: * the script/generate_grpc_examples.py script. Maybe *\n" 40 "ERROR: * you forgot to run it after making changes in a *\n" 41 "ERROR: * generator or schema? *\n" 42 "ERROR: ********************************************************\n" 43 ) 44 subprocess.run(["git", "diff", "--binary", "--exit-code"], cwd=root_path) 45 sys.exit(result.returncode) 46