Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop python package based on third-party proto #16360

Open
broken-dream opened this issue Apr 1, 2024 · 0 comments
Open

Develop python package based on third-party proto #16360

broken-dream opened this issue Apr 1, 2024 · 0 comments

Comments

@broken-dream
Copy link

broken-dream commented Apr 1, 2024

Hi all, I'm working on developing a python package for internal usage. It depends on several other proto repositories which are used as submodules. Suppose the python project looks like:

mypackage
├── src
│   ├── a.py
│   └── b.py
├── submodule1
│   ├── foo.proto
│   ├── bar.proto
│   └── maybe some other scripts
└── generated
    ├── foo_pb2.py
    ├── bar_pb2.py
    └── __init__.py
# submodule1/foo.proto
package submodule1.foo

message FooMessage {
  ...
} 
# submodule1/bar.proto
package submodule1.bar

import "submodule1/foo.proto"

then the generated bar_pb2.py file looks like:

...
from submodule1 import foo_pb2 as .....
...

and the submodule1 developer will use it like:

from submodule.foo_pb2 import FooMessage

I hope the package will be installed by pip and used like:

from mypackage.submodule.foo_pb2 import FooMessage

However, because of the python import mechanism, the two FooMessage is different between from mypackage.submodule.foo_pb2 import FooMessage and from submodule.foo_pb2 import FooMessage

I know there are some solutions like change the import path in generated python file or add mypackage to the sys.path then I can from submodule.foo_pb2 import FooMessage directly. But I think there should be a more elegant solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant