danielgtaylor / python-betterproto

Clean, modern, Python 3.6+ code generator & library for Protobuf 3 and async gRPC
MIT License
1.47k stars 205 forks source link

Issue importing structures between files in subpackages #154

Open danni opened 3 years ago

danni commented 3 years ago

Given a file like...

import "badger/mushroom";

package badger.snake;

message Snake {
  badger.mushroom.Mushroom mushroom = ...;
}

This results in compiling a badger/snake.py which includes the line from .badger import mushroom instead of from . import mushroom.

shaunco commented 3 years ago

I am seeing this as well in v1.2.5. Given:

The generated proj/pkg1/pkg1.py has:

# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: proj/pkg1/mapping.proto
# plugin: python-betterproto
from dataclasses import dataclass
from typing import Dict, List

import betterproto

from .proj import pkg2

When it should either be from .. import pkg2 or from proj import pkg2

Gobot1234 commented 3 years ago

Is this still an issue on V2.0.0b2?

shaunco commented 3 years ago

Is this still an issue on V2.0.0b2?

v2.0.0b2 packs everything for each package in to the __init__.py file and seems to have solved the parent/cousin import issues.