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

Relativ to absolut import in python3 in new ptotobuf version 3.0.0 #957

Closed
aurelw opened this issue Nov 9, 2015 · 2 comments
Closed

Relativ to absolut import in python3 in new ptotobuf version 3.0.0 #957

aurelw opened this issue Nov 9, 2015 · 2 comments

Comments

@aurelw
Copy link

aurelw commented Nov 9, 2015

This issue only concerns python3 generated code.

I have several message .pb files which i compile into python3 code. They all follow a package structure, "package myprotos.suba". There are several .pb files and corresponding modules, subBase, suba, subb. suba and subb import subBase. I now want to put all those generated python modules into one python package "myprotos". so i create "myprotos" directory, and add an empty init.py file.

Then in python code i should be able to do the following:

import myprotos
from myprotos import suba   # fails because suba is not in the path

However, this fails in the auto-generated module suba at the following statement:

import subBase

This is because python3 drops the support for these relative imports. A correctly generated code would look something like this:

import myprotos
from myprotos import subBase

Because the proto files already specifies package and subpackages it would be possible to generate an entire output directory with as a python package with working, cross-referencing imports.

@xdmiodz
Copy link

xdmiodz commented Nov 19, 2015

Hi,

Looks similar to #881

In your subb.proto you can import subBase.proto like:

#subb.proto
import 'myprotos/subBase.proto'

In this case the generated file will import subBase properly.

@anandolee
Copy link
Contributor

See #1491 for discussion of relative imports

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

No branches or pull requests

4 participants