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

Create alias importing of proto packages in their corresponding python module __init__ #2

Open
CCP-Zeulix opened this issue Jun 14, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@CCP-Zeulix
Copy link
Contributor

There's a certain schism in how Python's proto compiles, in that the python classes module path/namespace adheres to the proto file path instead of the package defined in the files.

image

Thus, as per this example, those three files will all be rendered as three individual python files and those messages will be under three different modules:
efrit/common/game.proto -> efrit.common.game_dc.py
efrit/common/text.proto -> efrit.common.text_dc.py
efrit/common/catalog.proto -> efrit.common.catalog_dc.py

However in proto, all the messages in there are in the same package/namespace in efrit.common while in python, going from efrit.common import * imports nothing.

Since proto doesn't allow any name collisions within package definitions, we can assume that everything defined in the same package can also live in the same namespace/module in Python and from that, in the __init__.py of each package module, "alias-import"every message that belongs to that package.

E.g. for the example above:
File: efrit/common/__init__.py

# Proto package alias importing
from efrit.common.game_dc import *
from efrit.common.text_dc import *
from efrit.common.catalog_dc import *
```

Thus, when using the neobuf package you can import stuff based on the proto packages definitions:
```python
from efrit.common import *
```
@CCP-Zeulix CCP-Zeulix added the enhancement New feature or request label Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant