pyrobuf icon indicating copy to clipboard operation
pyrobuf copied to clipboard

Using built messages inside package scope

Open rkrn opened this issue 7 years ago • 2 comments

I'm using your setuptools extension to distribute a package. However, I'd like to import the built message classes inside the project itself. This would be a fairly common use case (let's say the package has a web server that needs to serialize these protobuf messages) as compared to a user wanting to use it outside the scope of the project module.

So instead of this directory structure:

sample/
    proto/
        my_message.proto
    sample/
        __init__.py
    setup.py

We have this:

sample/
    sample/
        __init__.py
        proto/
            __init__.py
            my_message.proto
        server.py
    setup.py

where:

# file server.py
from .proto.my_message import MyMessage

For that matter, if someone wants to use my message classes, it seems cleaner to distribute it as a submodule since it belongs under the scope of the project anyway:

from sample.proto.my_message import MyMessage

Is there a reason not to install the package like this by default?

rkrn avatar Jun 12 '18 16:06 rkrn

Being able to specify the package namespace would be pretty slick. When I get a chance I will look into how we could do this, unless you want to take a stab at it and put up a PR 😬

tburmeister avatar Jun 14 '18 14:06 tburmeister

@rkrn sorry it took me so long to get around to this. I have a PR up for a solution: https://github.com/appnexus/pyrobuf/pull/114

It's not quite what you asked for, which I agree would be the cleanest, but I think it's at least an improvement. Basically, in the above example, all your message classes will be under the package sample_proto. See the diff in the README for what changed.

tburmeister avatar Sep 10 '18 22:09 tburmeister