Skip to content

relative imports are not supported #304

@ierezell

Description

@ierezell

When using -I to import other proto files (common declaration in my use-case) the python generated file does not import correctly the generated file.

E.g :

makefile
A 
--- A.proto
Common
--- common.proto

In the makefile :

./protoc/bin/protoc  -I Common -I A
	--python_out=$(COMPILED_PROTO_DIRECTORY) \
	--mypy_out=$(COMPILED_PROTO_DIRECTORY) \
	--grpc_out=$(COMPILED_PROTO_DIRECTORY) \
	--mypy_grpc_out=$(COMPILED_PROTO_DIRECTORY) \
	A/A.proto

Which generate a file (a_pb2.py) with :

"""
@generated by mypy-protobuf.  Do not edit manually!
isort:skip_file
"""
import builtins
import common_pb2

However common_pb2 is not a module in my path ! At least it should be from common import common_pb2 (which would in my case work)

I know it's a known problem but using https://github.com/danielgtaylor/python-betterproto seems to fix it (however it comes with other things I don't want and seems less maintained than this repo)

Do you have any fix / advice

Thanks in advance
Have a great day

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions