I emit the proto compilation into a generated_code/ directory(say communicator_pb2.py and communicator_pb2_grpc.py). Now, the grpc output imports the python code like so import communicator_pb2 as communicator__pb2; without having to modify the import path to import generated_code.communicator_pb2 as communicator__pb2 or append generated_code to sys.path, what is the most legal way to import if I were to import like:
import generate_code.commuinicator_pb2 as communicator_pb2
import generate_code.commuinicator_pb2_grpc as communicator_pb2_grpc
generated_codedirectory is on yoursys.patheither by runninggenerated_code/.., by settingPYTHONPATH, or via direct manipulation, can't you just usefrom generated_code import communicator_pb2from your application code?communicator_pb2_grpc.pyimportscommunicator_pb2.pylikeimport communicator_pb2 as communicator__pb2. I know that as long as myPYTHONPATHconsists ofgenerated_code/we are safe here. I was wondering if there was a way to hide this in__init__.pyor something slightly more elegant. Sorry, I lack some fundamentals here.__init__.py, you might try addingsys.path.insert(0, PATH_TO_PROTOBUF_DIR). This will ensure that the import command you mentioned above will be able to properly resolve thecommunicator_pb2module.