github.com/google/fleetspeak@v0.1.15-0.20240426164851-4f31f62c1aea/frr_python/setup.py (about) 1 import os 2 import subprocess 3 import sys 4 5 from setuptools import setup 6 from setuptools.command.develop import develop 7 8 GRPCIO_TOOLS = "grpcio-tools==1.46.3" 9 THIS_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) 10 os.chdir(THIS_DIRECTORY) 11 12 13 def compile_protos(): 14 """Compiles all proto files.""" 15 p = subprocess.Popen( 16 [sys.executable, "-m", "grpc_tools.protoc", "--help"], 17 stdout=subprocess.PIPE, 18 stderr=subprocess.PIPE, 19 ) 20 p.communicate() 21 if p.returncode != 0: 22 subprocess.check_call( 23 [sys.executable, "-m", "pip", "install", GRPCIO_TOOLS] 24 ) 25 26 proto_files = [] 27 for dir_path, _, filenames in os.walk(os.path.join(THIS_DIRECTORY, "..")): 28 for filename in filenames: 29 if filename.endswith(".proto"): 30 proto_files.append(os.path.join(dir_path, filename)) 31 if not proto_files: 32 return 33 34 root_dir = os.path.join(THIS_DIRECTORY, "..") 35 protoc_command = [ 36 "python", 37 "-m", 38 "grpc_tools.protoc", 39 "--python_out", 40 THIS_DIRECTORY, 41 "--grpc_python_out", 42 THIS_DIRECTORY, 43 "--proto_path", 44 root_dir, 45 ] 46 protoc_command.extend(proto_files) 47 subprocess.check_call(protoc_command, cwd=root_dir) 48 49 50 class Develop(develop): 51 52 def run(self): 53 compile_protos() 54 develop.run(self) 55 56 57 setup( 58 name="frr_python", 59 description="Frr server and client services", 60 url="https://github.com/google/fleetspeak/tree/master/frr_python", 61 maintainer="GRR Development Team", 62 maintainer_email="grr-dev@googlegroups.com", 63 license="Apache License, Version 2.0", 64 py_modules=["frr_client", "frr_server"], 65 install_requires=["absl-py>=0.8.0", "fleetspeak>=0.1.7"], 66 cmdclass={ 67 "develop": Develop, 68 }, 69 )