1- import os
21from pathlib import Path
32from setuptools import setup
43from setuptools .command .develop import develop as _develop
54from setuptools .command .install import install as _install
65from setuptools .command .build_py import build_py as _build_py
76from grpc_tools import protoc
8- from pkg_resources import resource_filename
7+ import importlib .resources
8+
99
1010def install_and_compile_proto ():
1111 """
@@ -14,8 +14,7 @@ def install_and_compile_proto():
1414 proto_dir = Path (__file__ ).absolute ().parent .joinpath (
1515 "snet" , "cli" , "resources" , "proto" )
1616
17- # Locate the standard grpc_tools internal protos (google/protobuf/...)
18- grpc_protos_include = resource_filename ('grpc_tools' , '_proto' )
17+ grpc_protos_include = str (importlib .resources .files ('grpc_tools' ).joinpath ('_proto' ))
1918
2019 print (f"Proto directory: { proto_dir } " )
2120 print (f"Grpc include directory: { grpc_protos_include } " )
@@ -31,7 +30,7 @@ def install_and_compile_proto():
3130 command = [
3231 'grpc_tools.protoc' ,
3332 f'-I{ proto_dir } ' ,
34- f'-I{ grpc_protos_include } ' , # <--- CRITICAL FIX: Add standard protos to include path
33+ f'-I{ grpc_protos_include } ' ,
3534 f'--python_out={ proto_dir } ' ,
3635 f'--grpc_python_out={ proto_dir } ' ,
3736 str (fn )
@@ -41,27 +40,30 @@ def install_and_compile_proto():
4140 print (f"Error: Failed to compile { fn } " )
4241 raise RuntimeError (f"Protocol buffer compilation failed for { fn } " )
4342
43+
4444class build_py (_build_py ):
4545 """
46- Override build_py to compile protos before building the wheel.
4746 This is the hook used by 'python -m build'.
4847 """
4948 def run (self ):
5049 self .execute (install_and_compile_proto , (), msg = "Compile protocol buffers" )
5150 _build_py .run (self )
5251
52+
5353class develop (_develop ):
5454 """Post-installation for development mode (pip install -e .)."""
5555 def run (self ):
5656 self .execute (install_and_compile_proto , (), msg = "Compile protocol buffers" )
5757 _develop .run (self )
5858
59+
5960class install (_install ):
6061 """Post-installation for legacy installation mode."""
6162 def run (self ):
6263 self .execute (install_and_compile_proto , (), msg = "Compile protocol buffers" )
6364 _install .run (self )
6465
66+
6567setup (
6668 cmdclass = {
6769 'develop' : develop ,
0 commit comments